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

[Bug] Incorrect rust compiler help hint #269

Open
h4-h opened this issue May 10, 2024 · 0 comments
Open

[Bug] Incorrect rust compiler help hint #269

h4-h opened this issue May 10, 2024 · 0 comments

Comments

@h4-h
Copy link

h4-h commented May 10, 2024

I don't know if this issue should be here or in rust issues, but it does occur with this library.

Versions

name version
rust 1.78.0
async-trait 0.1.80
tokio 1.37.0

Description

If we create a trait that has an asynchronous function with immutable reference to itself and try to mutate it we may get an incorrect (as i know) rust code help hint:

help: consider specifying this binding's type
   |
15 |     async fn non_mutable_fn(&self: &mut TestStruct, new: i32) {
   |                                  +++++++++++++++++

Full code on rust-playground.com

Or here
use async_trait::async_trait; // 0.1.80
use tokio; // 1.37.0

#[async_trait]
trait First {
    async fn non_mutable_fn(&self, new: i32);
}

struct TestStruct {
    nums: Vec<i32>
}

#[async_trait]
impl First for TestStruct {
    async fn non_mutable_fn(&self, new: i32) {
        self.nums.push(new);
    }
}

#[tokio::main]
async fn main() {
    let test_struct = TestStruct { nums: Vec::new() };
    test_struct.non_mutable_fn(3).await;
}

Expected behavior

Standard help about mutable reference, without the async-trait crate you can achieve that:

help: consider changing this to be a mutable reference
   |
13 |     async fn non_mutable_fn(&mut self, new: i32) {
   |                             ~~~~~~~~~
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

1 participant