serenity icon indicating copy to clipboard operation
serenity copied to clipboard

Unable to build e01_basic_ping_bot

Open AirborneDetergent opened this issue 1 year ago • 6 comments

If I download the basic ping bot example, modify Cargo.toml to make it build as its own independent project, and then try to build it, I get a compiler error. I am using Windows 10, I have not tested it on Linux. The error only popped up if I made an optimized build in the project I'm working on where I encountered it, but it seems to happen all the time in the minimal reproduction.

The error:

   Compiling serenity v0.12.0
error[E0596]: cannot borrow `*handler` as mutable, as it is behind a `&` reference
   --> C:\Users\<REDACTED>\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serenity-0.12.0\src\client\event_handler.rs:67:25
    |
67  |                           handler.$method_name($($context,)? $( $arg_name ),* ).await;
    |                           ^^^^^^^ `handler` is a `&` reference, so the data it refers to cannot be borrowed as mutable
...
75  | / event_handler! {
76  | |     /// Dispatched when the permissions of an application command was updated.
77  | |     ///
78  | |     /// Provides said permission's data.
...   |
449 | |     async fn ratelimit(&self, | Ratelimit { data: RatelimitInfo });
450 | | }
    | |_- in this macro invocation
    |
    = note: this error originates in the macro `event_handler` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider specifying this binding's type
    |
62  |             pub async fn dispatch(self, ctx: Context, handler: &mut dyn event_handler::EventHandler: &dyn EventHandler) {
    |                                                              ++++++++++++++++++++++++++++++++++++++

error[E0596]: cannot borrow data in an `Arc` as mutable
   --> C:\Users\<REDACTED>\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serenity-0.12.0\src\gateway\bridge\shard_runner.rs:129:25
    |
129 |                         event_handler.shard_stage_update(context, event).await;
    |                         ^^^^^^^^^^^^^ cannot borrow as mutable
    |
    = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Arc<dyn event_handler::EventHandler>`

For more information about this error, try `rustc --explain E0596`.
error: could not compile `serenity` (lib) due to 2 previous errors

Steps to reproduce:

  1. Download the folder here https://github.com/serenity-rs/serenity/tree/current/examples/e01_basic_ping_bot and unzip it into a folder. I used https://download-directory.github.io/ to do this.
  2. Replace line 8 of Cargo.toml with serenity = { version = "0.12.0", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
  3. Open the directory in a terminal and run cargo build

AirborneDetergent avatar Feb 07 '24 22:02 AirborneDetergent

What version of Rust are you getting the error on? You can fetch this with rustc --version.

GnomedDev avatar Feb 08 '24 00:02 GnomedDev

@GnomedDev I get rustc 1.75.0 (82e1608df 2023-12-21) when I run that command. There don't appear to be any updates available when running rustup check.

AirborneDetergent avatar Feb 08 '24 00:02 AirborneDetergent

I would recommend running cargo clean and also cargo update. Your Cargo.lock may need to get refreshed.

mkrasnitski avatar Feb 08 '24 01:02 mkrasnitski

That didn't seem to do anything.

AirborneDetergent avatar Feb 08 '24 01:02 AirborneDetergent

That error message also seems a bit malformed. This isn't a valid function signature:

pub async fn dispatch(self, ctx: Context, handler: &mut dyn event_handler::EventHandler: &dyn EventHandler)

Also, the signature of FullEvent::dispatch in serenity v0.12.0 is this:

pub async fn dispatch(self, ctx: Context, handler: &dyn EventHandler)

mkrasnitski avatar Feb 08 '24 03:02 mkrasnitski

@mkrasnitski I have no idea what's causing the malformed error message, but I reinstalled my toolchain as well as rust itself, tried switching from GNU to MSVC, and tested out the nightly toolchain with no result. What finally ended up working was just changing Serenity's version to v0.11.7. It doesn't really make any sense because I've been using v0.12.0 the whole time and the problem started spontaneously. I'll leave the issue open since my fix was to downgrade, so there must be something up with the current version of Serenity.

AirborneDetergent avatar Feb 08 '24 22:02 AirborneDetergent