async-trait
async-trait copied to clipboard
[Bug] Incorrect rust compiler help hint
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) {
| ~~~~~~~~~