-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
#[must_use] does not work for nested structures #39524
Copy link
Copy link
Closed
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
When
#[must_use]is applied to a structure that is nested, the linter no longer picks up when that value is unused.This is related to: #26291 and #26281
Looking at those issues, there seem to be a lot of cases where
#[must_use]does not work. This is unfortunate because it is actually an incredibly useful annotation that definitely has applications past just the Result enum.Accidentally relying on it too much can have you make mistakes you otherwise would have corrected had the warning been a bit smarter. I consider this a bug because
#[must_use]implies that you must use that value no matter what; regardless of what form it is returned in.I tried this code: (Rust Playground: https://is.gd/vCLZKq)
I expected to see this happen: A warning about the MustUse structure not being used
Instead, this happened: The code compiled and ran with no errors
Meta
rustc --version --verbose: stable, nightly, etc.Backtrace: not applicable