Skip to content
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

Closed

Conversation

zackmdavis
Copy link
Member

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 in LateLintPass/HIR?? Maybe reviewers have opinions on whether this is worth merging or needs more work?

useless_must_use

@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 7, 2018
@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Oct 7, 2018
@Centril
Copy link
Contributor

Centril commented Oct 7, 2018

Apparently this does not emit a warning either:

struct Fear{}

impl Fear {
    #[must_use]
    fn bravery() -> u8 { 1 }
}

fn main() {
    Fear::bravery(); // no warning
}

@Havvy Havvy added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. labels Oct 7, 2018
@Havvy
Copy link
Contributor

Havvy commented Oct 7, 2018

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.

@Centril Centril added the S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). label Oct 7, 2018
@Centril
Copy link
Contributor

Centril commented Oct 7, 2018

I'd like to echo @varkor's sentiments here, #54828 (comment), wrt. what we should do.

@zackmdavis
Copy link
Member Author

Closing as overcome-by-events (#54920).

@zackmdavis
Copy link
Member Author

Apparently this does not emit a warning either

Well that's just a bug: #55003

zackmdavis added a commit to zackmdavis/rust that referenced this pull request Oct 13, 2018
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.)
bors added a commit that referenced this pull request Oct 13, 2018
`#[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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants