forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#73379 - pnkfelix:issue-70819-disallow-overr…
…ide-forbid-in-same-scope, r=petrochenkov Disallow later override of forbid lint in same scope Fix rust-lang#70819 When building lint specs map for a given scope, check if forbid present on each insert. Drive-by changes: 1. make `LintLevelsBuilder::push` private to the crate. 2. Add methods to `LintSource` for extracting its name symbol or its span. 3. Rewrote old test so that its use of lint attributes are consistent with what we want in the language. (Note that the fact this test existed is a slight sign that we may need a crater run on this bugfix...)
- Loading branch information
Showing
5 changed files
with
146 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/ui/lint/issue-70819-dont-override-forbid-in-same-scope.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// This test is checking that you cannot override a `forbid` by adding in other | ||
// attributes later in the same scope. (We already ensure that you cannot | ||
// override it in nested scopes). | ||
|
||
// If you turn off deduplicate diagnostics (which rustc turns on by default but | ||
// compiletest turns off when it runs ui tests), then the errors are | ||
// (unfortunately) repeated here because the checking is done as we read in the | ||
// errors, and curretly that happens two or three different times, depending on | ||
// compiler flags. | ||
// | ||
// I decided avoiding the redundant output was not worth the time in engineering | ||
// effort for bug like this, which 1. end users are unlikely to run into in the | ||
// first place, and 2. they won't see the redundant output anyway. | ||
|
||
// compile-flags: -Z deduplicate-diagnostics=yes | ||
|
||
fn forbid_first(num: i32) -> i32 { | ||
#![forbid(unused)] | ||
#![deny(unused)] | ||
//~^ ERROR: deny(unused) incompatible with previous forbid in same scope [E0453] | ||
#![warn(unused)] | ||
//~^ ERROR: warn(unused) incompatible with previous forbid in same scope [E0453] | ||
#![allow(unused)] | ||
//~^ ERROR: allow(unused) incompatible with previous forbid in same scope [E0453] | ||
|
||
num * num | ||
} | ||
|
||
fn forbid_last(num: i32) -> i32 { | ||
#![deny(unused)] | ||
#![warn(unused)] | ||
#![allow(unused)] | ||
#![forbid(unused)] | ||
|
||
num * num | ||
} | ||
|
||
fn forbid_multiple(num: i32) -> i32 { | ||
#![forbid(unused)] | ||
#![forbid(unused)] | ||
|
||
num * num | ||
} | ||
|
||
fn main() { | ||
forbid_first(10); | ||
forbid_last(10); | ||
forbid_multiple(10); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/test/ui/lint/issue-70819-dont-override-forbid-in-same-scope.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
error[E0453]: deny(unused) incompatible with previous forbid in same scope | ||
--> $DIR/issue-70819-dont-override-forbid-in-same-scope.rs:19:13 | ||
| | ||
LL | #![forbid(unused)] | ||
| ------ `forbid` level set here | ||
LL | #![deny(unused)] | ||
| ^^^^^^ | ||
|
||
error[E0453]: warn(unused) incompatible with previous forbid in same scope | ||
--> $DIR/issue-70819-dont-override-forbid-in-same-scope.rs:21:13 | ||
| | ||
LL | #![forbid(unused)] | ||
| ------ `forbid` level set here | ||
... | ||
LL | #![warn(unused)] | ||
| ^^^^^^ | ||
|
||
error[E0453]: allow(unused) incompatible with previous forbid in same scope | ||
--> $DIR/issue-70819-dont-override-forbid-in-same-scope.rs:23:14 | ||
| | ||
LL | #![forbid(unused)] | ||
| ------ `forbid` level set here | ||
... | ||
LL | #![allow(unused)] | ||
| ^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0453`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters