dtolnay / async-trait

Type erasure for async trait methods
Apache License 2.0
1.84k stars 85 forks source link

Macro-generated false positive for `clippy::needless_arbitrary_self_type` #277

Closed adamspofford-dfinity closed 1 month ago

adamspofford-dfinity commented 1 month ago

I am implementing an async trait for all T where &T: tower::Service<...>. Since Service::execute takes &mut self, this trait impl says mut self: &Self (since you cannot say mut &self). This is fine with a plain async trait, but #[async_trait] triggers the clippy lint:

warning: the type of the `self` parameter does not need to be arbitrary
    --> ic-agent/src/agent/mod.rs:1865:13
     |
1865 |         mut self: &'a Self,
     |             ^^^^^^^^^^^^^^ help: consider to change this parameter to: `&'a self`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_arbitrary_self_type
     = note: `#[warn(clippy::needless_arbitrary_self_type)]` on by default

because the generated code starts with &self and let-binds it later. It would be good if async_trait silenced the warning instead of the caller.