Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build e01_basic_ping_bot #2756

Open
AirborneDetergent opened this issue Feb 7, 2024 · 6 comments
Open

Unable to build e01_basic_ping_bot #2756

AirborneDetergent opened this issue Feb 7, 2024 · 6 comments

Comments

@AirborneDetergent
Copy link

AirborneDetergent commented Feb 7, 2024

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
@GnomedDev
Copy link
Member

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

@AirborneDetergent
Copy link
Author

@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.

@mkrasnitski
Copy link
Collaborator

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

@AirborneDetergent
Copy link
Author

That didn't seem to do anything.

@mkrasnitski
Copy link
Collaborator

mkrasnitski commented Feb 8, 2024

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)

@AirborneDetergent
Copy link
Author

AirborneDetergent commented Feb 8, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants