-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Extend #[must_use]
to nested structures
#62262
Conversation
r? @estebank (rust_highfive has picked a reviewer for you, use r? to override) |
|
// We ignore ADTs with more than one variant for simplicity and to avoid | ||
// false positives. | ||
// Unions are also ignored (though in theory, we could lint if every field of | ||
// a union was `#[must_use]`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably go into a separate method and the comments above can become doc comments...
I'm not available for the next couple of days due to personal reasons. I would appreciate it if someone else could take over review. |
I don't think the review is in any rush - this definitely need lang-team sign off (and maybe libs?); I feel like we've discussed this previously and concluded that we shouldn't do it, IIRC because it expands it far enough that it feels like it "always" works which isn't actually the case. I could be projecting my own thoughts on the matter though. |
I nominated this for the lang team. The libs team doesn't deal with compiler lints. I personally feel that the false-positive cases are edge cases that are rare enough that they don't outweigh the big benefit this PR brings. We could however tweak this a bit to look for a |
I disagree a little bit about the libs team bit here -- it seems like this lint is predominantly used for libraries, not language features/things, and so their opinion matters more. At the very least, they should be notified (cc @rust-lang/libs). |
Would it make sense to do a crater run of this to see how useful the warnings it produces in real code are? |
Discussed briefly in @rust-lang/lang -- we agree a crater run would be the logical next step before making any further decisions. Can we set this to deny by default and do a run? |
r? @eddyb |
4ea0b40
to
84ae8df
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
8dbc243
to
8bcf64a
Compare
@bors try |
Extend `#[must_use]` to nested structures Extends the `#[must_use]` lint to apply when `#[must_use]` types are nested within `struct`s (or one-variant `enum`s), making the lint much more generally useful. This is in line with #61100 extending the lint to tuples. Fixes #39524. cc @rust-lang/lang and @rust-lang/compiler for discussion in case this is a controversial change. In particular, we might want to consider allowing annotations on fields containing `#[must_use]` types in user-defined types (e.g. `#[allow(unused_must_use)]`) to opt out of this behaviour, if there are cases where we this this is likely to have frequent false positives. (This is based on top of #62235.)
☀️ Try build successful - checks-azure |
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
23 crates produced the new lint (most of the regressions caught by crater were downstream). They all seem genuine to me, though in most cases they were deliberately (though not explicitly) ignored (in things like I think this crater run demonstrates the change is not very invasive, but can catch genuine errors, and is worth merging. |
The one case I noticed that might be reasonable to allow is calling |
I don't think that pattern is common: the only reason that instance was linted is because they were implementing |
Nominating for lang team re-review, now that the original concerns have been addressed. |
We discussed this in the lang meeting today and there was general agreement that the lint as-implemented in this PR isn't something we're interested in landing. This change would make There was some interest in a "conditional-must-use" based on type parameters, e.g. |
@cramertj "conditional I think we can still do that with an unstable trait, and hook it up either through the trait system, or macro expansion, so both |
Extends the
#[must_use]
lint to apply when#[must_use]
types are nested withinstruct
s (or one-variantenum
s), making the lint much more generally useful. This is in line with #61100 extending the lint to tuples.Fixes #39524.
cc @rust-lang/lang and @rust-lang/compiler for discussion in case this is a controversial change. In particular, we might want to consider allowing annotations on fields containing
#[must_use]
types in user-defined types (e.g.#[allow(unused_must_use)]
) to opt out of this behaviour, if there are cases where we this this is likely to have frequent false positives.(This is based on top of #62235.)