You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[must_use] on associated function definition when trait declaration does not have it should still trigger warning when calling function concretely #48486
This is expected (or at least, known) behavior; the #[must_use] attribute needs to go on the function signature in the trait definition, not the implementation. I argue that the current behavior makes sense: the semantics of a trait method should be the same across implementations. We should document this better, though—thanks for starting on that!
Then there should be a warning when #[must_use] is on a trait method.
But while it is known behavior, I didn't expect it. I expect that concretely calling a trait method should work the same as concretely calling an inherent method. Of course, when called generically, it should only look at the trait declaration.
#[must_use] on associated function definition when trait declaration does not have it should still trigger warning when calling function concretely · Issue #48486 · rust-lang/rust
Activity
zackmdavis commentedon Feb 23, 2018
This is expected (or at least, known) behavior; the
#[must_use]
attribute needs to go on the function signature in the trait definition, not the implementation. I argue that the current behavior makes sense: the semantics of a trait method should be the same across implementations. We should document this better, though—thanks for starting on that!Havvy commentedon Feb 23, 2018
Then there should be a warning when
#[must_use]
is on a trait method.But while it is known behavior, I didn't expect it. I expect that concretely calling a trait method should work the same as concretely calling an inherent method. Of course, when called generically, it should only look at the trait declaration.
#[must_use]
on functions #43302#[must_use]
functions with discardable return type #54884