asomers / mockall

A powerful mock object library for Rust
Apache License 2.0
1.5k stars 62 forks source link

Handle the #[inline], #[cold], and #[must_use] attributes #555

Closed asomers closed 7 months ago

asomers commented 7 months ago

Fixes #552

asomers commented 7 months ago

@tgnottingham does this branch work for you?

tgnottingham commented 7 months ago

@asomers -- yes, it works for my use case! Thanks for the quick fix!

This hasn't affected me yet in practice, but I noticed that there are still some warnings emitted for #[must_use] (regardless of whether or not there's a default method implementation):

#[mockall::automock]
trait Foo {
    #[must_use]
    fn foo(&self) -> i32;
}

fn main() {}

On Rust 1.76.0:

warning: `#[must_use]` has no effect when applied to a struct field
 --> src/main.rs:3:5
  |
3 |     #[must_use]
  |     ^^^^^^^^^^^
  |
  = note: `#[warn(unused_attributes)]` on by default

warning: `#[must_use]` has no effect when applied to a struct field
 --> src/main.rs:3:5
  |
3 |     #[must_use]
  |     ^^^^^^^^^^^

warning: `#[must_use]` has no effect when applied to an expression
 --> src/main.rs:3:5
  |
3 |     #[must_use]
  |     ^^^^^^^^^^^

warning: unused attribute
 --> src/main.rs:3:5
  |
3 |     #[must_use]
  |     ^^^^^^^^^^^ help: remove this attribute
  |
note: attribute also specified here
 --> src/main.rs:1:1
  |
1 | #[mockall::automock]
  | ^^^^^^^^^^^^^^^^^^^^
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: this warning originates in the attribute macro `mockall::automock` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: `#[must_use]` has no effect when applied to a module
 --> src/main.rs:3:5
  |
3 |     #[must_use]
  |     ^^^^^^^^^^^

Without the &self parameter on foo, only the no effect when applied to a module warning is generated.

asomers commented 7 months ago

@tgnottingham I cannot reproduce those warnings. Are you sure that you're using the "inline" branch?

tgnottingham commented 7 months ago

My mistake, I was on the first commit to that branch. Everything works great on the second commit. Thanks again!