mockall icon indicating copy to clipboard operation
mockall copied to clipboard

Clippy pedantic falls over `Option<&T>` parameter of `automock`'ed function

Open jaques-sam opened this issue 9 months ago • 1 comments

Have for example this code:

#[automock]
pub trait Compare<T> {
    fn is_different_except_foo<'a>(&self, other: Option<&'a T>) -> bool;
}

When running clippy:

cargo clippy --release --all-targets -- -Dclippy::all -Dclippy::pedantic

This is the error popping up:

error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>`
  --> configurator/src/entities/resources.rs:34:1
   |
34 | #[automock]
   | ^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ref_option_ref
   = note: this error originates in the attribute macro `automock` (in Nightly builds, run with -Z macro-backtrace for more info)

jaques-sam avatar Mar 11 '25 12:03 jaques-sam

Good catch. I don't usually use pedantic, but this warning should be easy to suppress.

asomers avatar Mar 11 '25 13:03 asomers