-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
When lint attributes in the same scope overlap, all but the last declared one are dropped #53079
Comments
At least one thing that's going on here is that It looks like it might also be the case that directives at the same scope can clobber each other? So #![forbid(dead_code)]
#![allow(dead_code)]
struct Foo;
fn main() {} surprisingly works, but #![forbid(dead_code)]
#[allow(dead_code)]
struct Foo;
fn main() {} fails as expected. This is also pretty confusing. |
#[forbid(dead_code)]
#[allow(dead_code)]
struct Foo;
fn main() {} Wait, scratch that. This doesn't compile, but doesn't mention the #[allow(dead_code)]
#[forbid(dead_code)]
struct Foo;
fn main() {} And this compiles with a warning: #[allow(dead_code)]
#[forbid(dead_code)]
#[warn(dead_code)]
struct Foo;
fn main() {} So it looks like when we have overlapping lint settings in the same scope, we're now dropping all but that last one. |
forbid
lint level is broken on all channels
This issue can be closed because this was fixed by #81556 which added plenty of tests. $ rustc +1.71 main.rs
warning: allow(dead_code) incompatible with previous forbid
--> /home/martin/src/bin/src/main.rs:2:10
|
1 | #![forbid(warnings)]
| -------- `forbid` level set here
2 | #![allow(dead_code)]
| ^^^^^^^^^ overruled by previous forbid
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
= note: `#[warn(forbidden_lint_groups)]` on by default
warning: 1 warning emitted |
Playground link
The above code should fail to compile with an error about trying to
allow
aforbid
den lint, but successfully builds without any warnings. Tested on latest stable/beta/nightly.The text was updated successfully, but these errors were encountered: