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

When lint attributes in the same scope overlap, all but the last declared one are dropped #53079

Closed
FaultyRAM opened this issue Aug 5, 2018 · 3 comments
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@FaultyRAM
Copy link

#![forbid(warnings)]
#![allow(dead_code)]

struct Foo;

fn main() {}

Playground link

The above code should fail to compile with an error about trying to allow a forbidden lint, but successfully builds without any warnings. Tested on latest stable/beta/nightly.

@zackmdavis
Copy link
Member

zackmdavis commented Aug 5, 2018

At least one thing that's going on here is that warnings isn't (as one might intuitively think) an ordinary lint group that happens to contain all lints. Rather, it's a special magic setting that makes lints deny when they otherwise would have warned. This is pretty confusing and should at least be better documented.

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.

@FaultyRAM
Copy link
Author

FaultyRAM commented Aug 5, 2018

That does seem to be the case, since this compiles as well:

#[forbid(dead_code)]
#[allow(dead_code)]
struct Foo;

fn main() {}

Wait, scratch that. This doesn't compile, but doesn't mention the allow:

#[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.

@FaultyRAM FaultyRAM changed the title forbid lint level is broken on all channels When lint attributes in the same scope overlap, all but the last declared one are dropped Aug 5, 2018
@Mark-Simulacrum Mark-Simulacrum added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Aug 5, 2018
@Enselic
Copy link
Member

Enselic commented Jul 24, 2023

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

@Enselic Enselic closed this as not planned Won't fix, can't repro, duplicate, stale Aug 17, 2023
@Enselic Enselic closed this as completed Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants