-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
in which we lint #[must_use]
functions with discardable return type
#54884
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Apparently this does not emit a warning either: struct Fear{}
impl Fear {
#[must_use]
fn bravery() -> u8 { 1 }
}
fn main() {
Fear::bravery(); // no warning
} |
I personally think it's okay for it to say unused on the impl fn for the wrong reason right now, as long as an issue is filed about it. If we're going to do that though, we should have the problematic test case link to the opened issue. |
I'd like to echo @varkor's sentiments here, #54828 (comment), wrt. what we should do. |
Closing as overcome-by-events (#54920). |
Well that's just a bug: #55003 |
In the comments of (closed, defunct) pull request rust-lang#54884, Mazdak "Centril" Farrokhzad noted that must-use annotations didn't work on an associated function (what other communities might call a "static method"). Subsequent logging revealed that in this case we have a `Def::Method`, whereas the lint pass was only matching on `Def::Fn`. (One could argue that those def-names are thereby misleading—must-use for self-ful methods have always worked—but documenting or reworking that can be left to another day.)
`#[must_use]` for associated functions is supposed to actually work In the comments of (closed, defunct) pull request #54884, @Centril [noted that](#54884 (comment)) must-use annotations didn't work on an associated function (what other communities might call a "static method"). Subsequent logging revealed that in this case we have a `Def::Method`, whereas the lint pass was only matching on `Def::Fn`. (One could argue that those def-names are thereby misleading—must-use for `self`-ful methods have always worked—but documenting or reworking that can be left to another day.) r? @varkor
A rejoinder to discussion on #54828. cc @abonander @Centril @Havvy
It's arguably pretty misleading that this also lints on trait impls (see the FIXME in the UI test), which should also be unused-attributes, but for a different reason, namely, that the
#[must_use]
should go on the signature in the trait definition, not the implementation for a particular type (#48486). Unfortunately, I can't seem to figure out how to distinguish trait method impls from functions or inherent methods inLateLintPass
/HIR?? Maybe reviewers have opinions on whether this is worth merging or needs more work?