-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
#[expect(unused_must_use)]
does not work when applied directly to statement
#130142
Comments
#[expect(unused_must_use]
does not work when applied directly to statement#[expect(unused_must_use)]
does not work when applied directly to statement
@rustbot claim |
This issue is not limited to just #[must_use]
pub fn important() -> i32 {
42
}
pub fn foo() {
#[allow(unused_must_use)]
important();
} Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=5847d1b5165f0da09b093559c6d20f6e This broken behaviour goes as far back as at least 2021 (couldn't build and test earlier rustc) Underlying reasonWe emit the lint on the
The end result is that the lint's Possible fixAs it happens rust/compiler/rustc_lint/src/levels.rs Lines 258 to 263 in 6c65d4f
If were to add the level for However, if we do that we will still have one problem in the case of I am new to this area so if someone can review this idea or suggest alternatives that will be great. @cjgillot since you seemed to have worked in this area recently, can you please weigh in? |
Your investigation is accurate, and the fix is simple: visit the statement node when building lint levels. Do you mind making such a pr ? I don't think we need any special adjustment for |
Thanks @cjgillot . Yes, I'll put together a PR. My only concern is if all we do is add the level at But anyway let me have a go and see what happens. |
Opened draft PR #130293 that adds the lint on |
Rollup merge of rust-lang#130293 - gurry:130142-lint-level-issue, r=cjgillot Fix lint levels not getting overridden by attrs on `Stmt` nodes Fixes rust-lang#130142. See comments on the issue for context. r? `@cjgillot`
…jgillot Fix lint levels not getting overridden by attrs on `Stmt` nodes Fixes rust-lang#130142. See comments on the issue for context. r? `@cjgillot`
I tried this code:
I expected
#[expect]
to catchunused_must_use
lint and suppress it, as it should. Instead, compiler issues a diagnostic both about unused#[must_use]
value and unfulfilled lint expectation:It does work as expected though if
#[expect]
is applied to function.Meta
I used the latest stable (Rust 1.81), but it is reproducible both on latest beta (2024-09-04 c7c49f4) and latest nightly (2024-09-05 9c01301).
@rustbot labels: +F-lint_reasons, +A-diagnostics
The text was updated successfully, but these errors were encountered: