Skip to content

Commit 741884d

Browse files
committed
rustc_lint: Prevent multiple 'incompatible with previous forbid' lints
1 parent e0c626f commit 741884d

15 files changed

+8
-204
lines changed

compiler/rustc_lint/src/levels.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
642642
//
643643
// This means that this only errors if we're truly lowering the lint
644644
// level from forbid.
645-
if level != Level::Forbid {
645+
if self.lint_added_lints && level != Level::Forbid {
646646
if let Level::Forbid = old_level {
647647
// Backwards compatibility check:
648648
//

tests/ui/error-codes/E0453.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
#[allow(non_snake_case)]
44
//~^ ERROR allow(non_snake_case) incompatible
5-
//~| ERROR allow(non_snake_case) incompatible
65
fn main() {
76
}

tests/ui/error-codes/E0453.stderr

+1-12
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ LL |
77
LL | #[allow(non_snake_case)]
88
| ^^^^^^^^^^^^^^ overruled by previous forbid
99

10-
error[E0453]: allow(non_snake_case) incompatible with previous forbid
11-
--> $DIR/E0453.rs:3:9
12-
|
13-
LL | #![forbid(non_snake_case)]
14-
| -------------- `forbid` level set here
15-
LL |
16-
LL | #[allow(non_snake_case)]
17-
| ^^^^^^^^^^^^^^ overruled by previous forbid
18-
|
19-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
20-
21-
error: aborting due to 2 previous errors
10+
error: aborting due to 1 previous error
2211

2312
For more information about this error, try `rustc --explain E0453`.

tests/ui/lint/forbid-group-group-2.rs

-12
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,4 @@
1111
//~| WARNING previously accepted by the compiler
1212
//~| ERROR incompatible with previous
1313
//~| WARNING previously accepted by the compiler
14-
//~| ERROR incompatible with previous
15-
//~| WARNING previously accepted by the compiler
16-
//~| ERROR incompatible with previous
17-
//~| WARNING previously accepted by the compiler
18-
//~| ERROR incompatible with previous
19-
//~| WARNING previously accepted by the compiler
20-
//~| ERROR incompatible with previous
21-
//~| WARNING previously accepted by the compiler
22-
//~| ERROR incompatible with previous
23-
//~| WARNING previously accepted by the compiler
24-
//~| ERROR incompatible with previous
25-
//~| WARNING previously accepted by the compiler
2614
fn main() {}

tests/ui/lint/forbid-group-group-2.stderr

+1-79
Original file line numberDiff line numberDiff line change
@@ -41,83 +41,5 @@ LL | #[allow(nonstandard_style)]
4141
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
4242
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
4343

44-
error: allow(nonstandard_style) incompatible with previous forbid
45-
--> $DIR/forbid-group-group-2.rs:7:9
46-
|
47-
LL | #![forbid(warnings)]
48-
| -------- `forbid` level set here
49-
...
50-
LL | #[allow(nonstandard_style)]
51-
| ^^^^^^^^^^^^^^^^^ overruled by previous forbid
52-
|
53-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
54-
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
55-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
56-
57-
error: allow(nonstandard_style) incompatible with previous forbid
58-
--> $DIR/forbid-group-group-2.rs:7:9
59-
|
60-
LL | #![forbid(warnings)]
61-
| -------- `forbid` level set here
62-
...
63-
LL | #[allow(nonstandard_style)]
64-
| ^^^^^^^^^^^^^^^^^ overruled by previous forbid
65-
|
66-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
67-
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
68-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
69-
70-
error: allow(nonstandard_style) incompatible with previous forbid
71-
--> $DIR/forbid-group-group-2.rs:7:9
72-
|
73-
LL | #![forbid(warnings)]
74-
| -------- `forbid` level set here
75-
...
76-
LL | #[allow(nonstandard_style)]
77-
| ^^^^^^^^^^^^^^^^^ overruled by previous forbid
78-
|
79-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
80-
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
81-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
82-
83-
error: allow(nonstandard_style) incompatible with previous forbid
84-
--> $DIR/forbid-group-group-2.rs:7:9
85-
|
86-
LL | #![forbid(warnings)]
87-
| -------- `forbid` level set here
88-
...
89-
LL | #[allow(nonstandard_style)]
90-
| ^^^^^^^^^^^^^^^^^ overruled by previous forbid
91-
|
92-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
93-
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
94-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
95-
96-
error: allow(nonstandard_style) incompatible with previous forbid
97-
--> $DIR/forbid-group-group-2.rs:7:9
98-
|
99-
LL | #![forbid(warnings)]
100-
| -------- `forbid` level set here
101-
...
102-
LL | #[allow(nonstandard_style)]
103-
| ^^^^^^^^^^^^^^^^^ overruled by previous forbid
104-
|
105-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
106-
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
107-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
108-
109-
error: allow(nonstandard_style) incompatible with previous forbid
110-
--> $DIR/forbid-group-group-2.rs:7:9
111-
|
112-
LL | #![forbid(warnings)]
113-
| -------- `forbid` level set here
114-
...
115-
LL | #[allow(nonstandard_style)]
116-
| ^^^^^^^^^^^^^^^^^ overruled by previous forbid
117-
|
118-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
119-
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
120-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
121-
122-
error: aborting due to 9 previous errors
44+
error: aborting due to 3 previous errors
12345

tests/ui/lint/forbid-group-member.rs

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
#[allow(unused_variables)]
99
//~^ WARNING incompatible with previous forbid
1010
//~| WARNING previously accepted
11-
//~| WARNING incompatible with previous forbid
12-
//~| WARNING previously accepted
13-
//~| WARNING incompatible with previous forbid
14-
//~| WARNING previously accepted
1511
fn main() {
1612
let a: ();
1713
}

tests/ui/lint/forbid-group-member.stderr

+1-27
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,5 @@ LL | #[allow(unused_variables)]
1111
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
1212
= note: `#[warn(forbidden_lint_groups)]` on by default
1313

14-
warning: allow(unused_variables) incompatible with previous forbid
15-
--> $DIR/forbid-group-member.rs:8:9
16-
|
17-
LL | #![forbid(unused)]
18-
| ------ `forbid` level set here
19-
LL |
20-
LL | #[allow(unused_variables)]
21-
| ^^^^^^^^^^^^^^^^ overruled by previous forbid
22-
|
23-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
24-
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
25-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
26-
27-
warning: allow(unused_variables) incompatible with previous forbid
28-
--> $DIR/forbid-group-member.rs:8:9
29-
|
30-
LL | #![forbid(unused)]
31-
| ------ `forbid` level set here
32-
LL |
33-
LL | #[allow(unused_variables)]
34-
| ^^^^^^^^^^^^^^^^ overruled by previous forbid
35-
|
36-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
37-
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
38-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
39-
40-
warning: 3 warnings emitted
14+
warning: 1 warning emitted
4115

tests/ui/lint/forbid-member-group.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#[allow(unused)]
77
//~^ ERROR incompatible with previous forbid
8-
//~| ERROR incompatible with previous forbid
98
fn main() {
109
let a: ();
1110
}

tests/ui/lint/forbid-member-group.stderr

+1-12
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ LL |
77
LL | #[allow(unused)]
88
| ^^^^^^ overruled by previous forbid
99

10-
error[E0453]: allow(unused) incompatible with previous forbid
11-
--> $DIR/forbid-member-group.rs:6:9
12-
|
13-
LL | #![forbid(unused_variables)]
14-
| ---------------- `forbid` level set here
15-
LL |
16-
LL | #[allow(unused)]
17-
| ^^^^^^ overruled by previous forbid
18-
|
19-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
20-
21-
error: aborting due to 2 previous errors
10+
error: aborting due to 1 previous error
2211

2312
For more information about this error, try `rustc --explain E0453`.

tests/ui/lint/issue-80988.rs

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@
77
#[deny(warnings)]
88
//~^ WARNING incompatible with previous forbid
99
//~| WARNING being phased out
10-
//~| WARNING incompatible with previous forbid
11-
//~| WARNING being phased out
12-
//~| WARNING incompatible with previous forbid
13-
//~| WARNING being phased out
1410
fn main() {}

tests/ui/lint/issue-80988.stderr

+1-27
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,5 @@ LL | #[deny(warnings)]
1111
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
1212
= note: `#[warn(forbidden_lint_groups)]` on by default
1313

14-
warning: deny(warnings) incompatible with previous forbid
15-
--> $DIR/issue-80988.rs:7:8
16-
|
17-
LL | #![forbid(warnings)]
18-
| -------- `forbid` level set here
19-
LL |
20-
LL | #[deny(warnings)]
21-
| ^^^^^^^^ overruled by previous forbid
22-
|
23-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
24-
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
25-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
26-
27-
warning: deny(warnings) incompatible with previous forbid
28-
--> $DIR/issue-80988.rs:7:8
29-
|
30-
LL | #![forbid(warnings)]
31-
| -------- `forbid` level set here
32-
LL |
33-
LL | #[deny(warnings)]
34-
| ^^^^^^^^ overruled by previous forbid
35-
|
36-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
37-
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
38-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
39-
40-
warning: 3 warnings emitted
14+
warning: 1 warning emitted
4115

tests/ui/lint/lint-forbid-attr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
#[allow(deprecated)]
44
//~^ ERROR allow(deprecated) incompatible
5-
//~| ERROR allow(deprecated) incompatible
65
fn main() {
76
}

tests/ui/lint/lint-forbid-attr.stderr

+1-12
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ LL |
77
LL | #[allow(deprecated)]
88
| ^^^^^^^^^^ overruled by previous forbid
99

10-
error[E0453]: allow(deprecated) incompatible with previous forbid
11-
--> $DIR/lint-forbid-attr.rs:3:9
12-
|
13-
LL | #![forbid(deprecated)]
14-
| ---------- `forbid` level set here
15-
LL |
16-
LL | #[allow(deprecated)]
17-
| ^^^^^^^^^^ overruled by previous forbid
18-
|
19-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
20-
21-
error: aborting due to 2 previous errors
10+
error: aborting due to 1 previous error
2211

2312
For more information about this error, try `rustc --explain E0453`.

tests/ui/lint/lint-forbid-cmdline.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// compile-flags: -F deprecated
22

33
#[allow(deprecated)] //~ ERROR allow(deprecated) incompatible
4-
//~| ERROR allow(deprecated) incompatible
54
fn main() {
65
}

tests/ui/lint/lint-forbid-cmdline.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ LL | #[allow(deprecated)]
66
|
77
= note: `forbid` lint level was set on command line
88

9-
error[E0453]: allow(deprecated) incompatible with previous forbid
10-
--> $DIR/lint-forbid-cmdline.rs:3:9
11-
|
12-
LL | #[allow(deprecated)]
13-
| ^^^^^^^^^^ overruled by previous forbid
14-
|
15-
= note: `forbid` lint level was set on command line
16-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
17-
18-
error: aborting due to 2 previous errors
9+
error: aborting due to 1 previous error
1910

2011
For more information about this error, try `rustc --explain E0453`.

0 commit comments

Comments
 (0)