Skip to content

Commit 7ca4e9f

Browse files
committed
rustc_lint: Prevent triplication of 'unknown lint' lint
1 parent 741884d commit 7ca4e9f

19 files changed

+42
-392
lines changed

compiler/rustc_lint/src/levels.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -1054,33 +1054,33 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
10541054
/// Checks if the lint is gated on a feature that is not enabled.
10551055
///
10561056
/// Returns `true` if the lint's feature is enabled.
1057-
// FIXME only emit this once for each attribute, instead of repeating it 4 times for
1058-
// pre-expansion lints, post-expansion lints, `shallow_lint_levels_on` and `lint_expectations`.
10591057
#[track_caller]
10601058
fn check_gated_lint(&self, lint_id: LintId, span: Span, lint_from_cli: bool) -> bool {
10611059
if let Some(feature) = lint_id.lint.feature_gate {
10621060
if !self.features.active(feature) {
1063-
let lint = builtin::UNKNOWN_LINTS;
1064-
let (level, src) = self.lint_level(builtin::UNKNOWN_LINTS);
1065-
struct_lint_level(
1066-
self.sess,
1067-
lint,
1068-
level,
1069-
src,
1070-
Some(span.into()),
1071-
fluent::lint_unknown_gated_lint,
1072-
|lint| {
1073-
lint.set_arg("name", lint_id.lint.name_lower());
1074-
lint.note(fluent::lint_note);
1075-
rustc_session::parse::add_feature_diagnostics_for_issue(
1076-
lint,
1077-
&self.sess.parse_sess,
1078-
feature,
1079-
GateIssue::Language,
1080-
lint_from_cli,
1081-
);
1082-
},
1083-
);
1061+
if self.lint_added_lints {
1062+
let lint = builtin::UNKNOWN_LINTS;
1063+
let (level, src) = self.lint_level(builtin::UNKNOWN_LINTS);
1064+
struct_lint_level(
1065+
self.sess,
1066+
lint,
1067+
level,
1068+
src,
1069+
Some(span.into()),
1070+
fluent::lint_unknown_gated_lint,
1071+
|lint| {
1072+
lint.set_arg("name", lint_id.lint.name_lower());
1073+
lint.note(fluent::lint_note);
1074+
rustc_session::parse::add_feature_diagnostics_for_issue(
1075+
lint,
1076+
&self.sess.parse_sess,
1077+
feature,
1078+
GateIssue::Language,
1079+
lint_from_cli,
1080+
);
1081+
},
1082+
);
1083+
}
10841084
return false;
10851085
}
10861086
}

tests/ui/feature-gates/feature-gate-multiple_supertrait_upcastable.rs

-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
#![deny(multiple_supertrait_upcastable)]
44
//~^ WARNING unknown lint: `multiple_supertrait_upcastable`
5-
//~| WARNING unknown lint: `multiple_supertrait_upcastable`
6-
//~| WARNING unknown lint: `multiple_supertrait_upcastable`
75
#![warn(multiple_supertrait_upcastable)]
86
//~^ WARNING unknown lint: `multiple_supertrait_upcastable`
9-
//~| WARNING unknown lint: `multiple_supertrait_upcastable`
10-
//~| WARNING unknown lint: `multiple_supertrait_upcastable`
117

128
fn main() {}

tests/ui/feature-gates/feature-gate-multiple_supertrait_upcastable.stderr

+2-42
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,13 @@ LL | #![deny(multiple_supertrait_upcastable)]
99
= note: `#[warn(unknown_lints)]` on by default
1010

1111
warning: unknown lint: `multiple_supertrait_upcastable`
12-
--> $DIR/feature-gate-multiple_supertrait_upcastable.rs:7:1
12+
--> $DIR/feature-gate-multiple_supertrait_upcastable.rs:5:1
1313
|
1414
LL | #![warn(multiple_supertrait_upcastable)]
1515
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616
|
1717
= note: the `multiple_supertrait_upcastable` lint is unstable
1818
= help: add `#![feature(multiple_supertrait_upcastable)]` to the crate attributes to enable
1919

20-
warning: unknown lint: `multiple_supertrait_upcastable`
21-
--> $DIR/feature-gate-multiple_supertrait_upcastable.rs:3:1
22-
|
23-
LL | #![deny(multiple_supertrait_upcastable)]
24-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25-
|
26-
= note: the `multiple_supertrait_upcastable` lint is unstable
27-
= help: add `#![feature(multiple_supertrait_upcastable)]` to the crate attributes to enable
28-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
29-
30-
warning: unknown lint: `multiple_supertrait_upcastable`
31-
--> $DIR/feature-gate-multiple_supertrait_upcastable.rs:7:1
32-
|
33-
LL | #![warn(multiple_supertrait_upcastable)]
34-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35-
|
36-
= note: the `multiple_supertrait_upcastable` lint is unstable
37-
= help: add `#![feature(multiple_supertrait_upcastable)]` to the crate attributes to enable
38-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
39-
40-
warning: unknown lint: `multiple_supertrait_upcastable`
41-
--> $DIR/feature-gate-multiple_supertrait_upcastable.rs:3:1
42-
|
43-
LL | #![deny(multiple_supertrait_upcastable)]
44-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
45-
|
46-
= note: the `multiple_supertrait_upcastable` lint is unstable
47-
= help: add `#![feature(multiple_supertrait_upcastable)]` to the crate attributes to enable
48-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
49-
50-
warning: unknown lint: `multiple_supertrait_upcastable`
51-
--> $DIR/feature-gate-multiple_supertrait_upcastable.rs:7:1
52-
|
53-
LL | #![warn(multiple_supertrait_upcastable)]
54-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55-
|
56-
= note: the `multiple_supertrait_upcastable` lint is unstable
57-
= help: add `#![feature(multiple_supertrait_upcastable)]` to the crate attributes to enable
58-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
59-
60-
warning: 6 warnings emitted
20+
warning: 2 warnings emitted
6121

tests/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.rs

-10
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
#![deny(non_exhaustive_omitted_patterns)]
44
//~^ WARNING unknown lint: `non_exhaustive_omitted_patterns`
5-
//~| WARNING unknown lint: `non_exhaustive_omitted_patterns`
6-
//~| WARNING unknown lint: `non_exhaustive_omitted_patterns`
75
#![allow(non_exhaustive_omitted_patterns)]
86
//~^ WARNING unknown lint: `non_exhaustive_omitted_patterns`
9-
//~| WARNING unknown lint: `non_exhaustive_omitted_patterns`
10-
//~| WARNING unknown lint: `non_exhaustive_omitted_patterns`
117

128
fn main() {
139
enum Foo {
@@ -19,9 +15,6 @@ fn main() {
1915
#[allow(non_exhaustive_omitted_patterns)]
2016
//~^ WARNING unknown lint: `non_exhaustive_omitted_patterns`
2117
//~| WARNING unknown lint: `non_exhaustive_omitted_patterns`
22-
//~| WARNING unknown lint: `non_exhaustive_omitted_patterns`
23-
//~| WARNING unknown lint: `non_exhaustive_omitted_patterns`
24-
//~| WARNING unknown lint: `non_exhaustive_omitted_patterns`
2518
match Foo::A {
2619
//~^ ERROR non-exhaustive patterns: `Foo::C` not covered
2720
Foo::A => {}
@@ -31,9 +24,6 @@ fn main() {
3124
#[warn(non_exhaustive_omitted_patterns)]
3225
//~^ WARNING unknown lint: `non_exhaustive_omitted_patterns`
3326
//~| WARNING unknown lint: `non_exhaustive_omitted_patterns`
34-
//~| WARNING unknown lint: `non_exhaustive_omitted_patterns`
35-
//~| WARNING unknown lint: `non_exhaustive_omitted_patterns`
36-
//~| WARNING unknown lint: `non_exhaustive_omitted_patterns`
3727
match Foo::A {
3828
Foo::A => {}
3929
Foo::B => {}

tests/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr

+8-118
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | #![deny(non_exhaustive_omitted_patterns)]
1010
= note: `#[warn(unknown_lints)]` on by default
1111

1212
warning: unknown lint: `non_exhaustive_omitted_patterns`
13-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:7:1
13+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:5:1
1414
|
1515
LL | #![allow(non_exhaustive_omitted_patterns)]
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -20,7 +20,7 @@ LL | #![allow(non_exhaustive_omitted_patterns)]
2020
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
2121

2222
warning: unknown lint: `non_exhaustive_omitted_patterns`
23-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:19:5
23+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:15:5
2424
|
2525
LL | #[allow(non_exhaustive_omitted_patterns)]
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -30,7 +30,7 @@ LL | #[allow(non_exhaustive_omitted_patterns)]
3030
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
3131

3232
warning: unknown lint: `non_exhaustive_omitted_patterns`
33-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:19:5
33+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:15:5
3434
|
3535
LL | #[allow(non_exhaustive_omitted_patterns)]
3636
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -41,7 +41,7 @@ LL | #[allow(non_exhaustive_omitted_patterns)]
4141
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
4242

4343
warning: unknown lint: `non_exhaustive_omitted_patterns`
44-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:31:5
44+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:24:5
4545
|
4646
LL | #[warn(non_exhaustive_omitted_patterns)]
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -51,73 +51,7 @@ LL | #[warn(non_exhaustive_omitted_patterns)]
5151
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
5252

5353
warning: unknown lint: `non_exhaustive_omitted_patterns`
54-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:31:5
55-
|
56-
LL | #[warn(non_exhaustive_omitted_patterns)]
57-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
58-
|
59-
= note: the `non_exhaustive_omitted_patterns` lint is unstable
60-
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
61-
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
62-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
63-
64-
warning: unknown lint: `non_exhaustive_omitted_patterns`
65-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:3:1
66-
|
67-
LL | #![deny(non_exhaustive_omitted_patterns)]
68-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
69-
|
70-
= note: the `non_exhaustive_omitted_patterns` lint is unstable
71-
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
72-
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
73-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
74-
75-
warning: unknown lint: `non_exhaustive_omitted_patterns`
76-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:7:1
77-
|
78-
LL | #![allow(non_exhaustive_omitted_patterns)]
79-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
80-
|
81-
= note: the `non_exhaustive_omitted_patterns` lint is unstable
82-
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
83-
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
84-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
85-
86-
warning: unknown lint: `non_exhaustive_omitted_patterns`
87-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:19:5
88-
|
89-
LL | #[allow(non_exhaustive_omitted_patterns)]
90-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
91-
|
92-
= note: the `non_exhaustive_omitted_patterns` lint is unstable
93-
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
94-
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
95-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
96-
97-
warning: unknown lint: `non_exhaustive_omitted_patterns`
98-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:19:5
99-
|
100-
LL | #[allow(non_exhaustive_omitted_patterns)]
101-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
102-
|
103-
= note: the `non_exhaustive_omitted_patterns` lint is unstable
104-
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
105-
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
106-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
107-
108-
warning: unknown lint: `non_exhaustive_omitted_patterns`
109-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:31:5
110-
|
111-
LL | #[warn(non_exhaustive_omitted_patterns)]
112-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
113-
|
114-
= note: the `non_exhaustive_omitted_patterns` lint is unstable
115-
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
116-
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
117-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
118-
119-
warning: unknown lint: `non_exhaustive_omitted_patterns`
120-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:31:5
54+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:24:5
12155
|
12256
LL | #[warn(non_exhaustive_omitted_patterns)]
12357
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -128,13 +62,13 @@ LL | #[warn(non_exhaustive_omitted_patterns)]
12862
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
12963

13064
error[E0004]: non-exhaustive patterns: `Foo::C` not covered
131-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:25:11
65+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:18:11
13266
|
13367
LL | match Foo::A {
13468
| ^^^^^^ pattern `Foo::C` not covered
13569
|
13670
note: `Foo` defined here
137-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:10
71+
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:9:10
13872
|
13973
LL | enum Foo {
14074
| ^^^
@@ -148,50 +82,6 @@ LL ~ Foo::B => {},
14882
LL + Foo::C => todo!()
14983
|
15084

151-
warning: unknown lint: `non_exhaustive_omitted_patterns`
152-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:3:1
153-
|
154-
LL | #![deny(non_exhaustive_omitted_patterns)]
155-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
156-
|
157-
= note: the `non_exhaustive_omitted_patterns` lint is unstable
158-
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
159-
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
160-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
161-
162-
warning: unknown lint: `non_exhaustive_omitted_patterns`
163-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:7:1
164-
|
165-
LL | #![allow(non_exhaustive_omitted_patterns)]
166-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
167-
|
168-
= note: the `non_exhaustive_omitted_patterns` lint is unstable
169-
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
170-
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
171-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
172-
173-
warning: unknown lint: `non_exhaustive_omitted_patterns`
174-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:19:5
175-
|
176-
LL | #[allow(non_exhaustive_omitted_patterns)]
177-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
178-
|
179-
= note: the `non_exhaustive_omitted_patterns` lint is unstable
180-
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
181-
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
182-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
183-
184-
warning: unknown lint: `non_exhaustive_omitted_patterns`
185-
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:31:5
186-
|
187-
LL | #[warn(non_exhaustive_omitted_patterns)]
188-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189-
|
190-
= note: the `non_exhaustive_omitted_patterns` lint is unstable
191-
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
192-
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
193-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
194-
195-
error: aborting due to 1 previous error; 16 warnings emitted
85+
error: aborting due to 1 previous error; 6 warnings emitted
19686

19787
For more information about this error, try `rustc --explain E0004`.

tests/ui/feature-gates/feature-gate-strict_provenance.rs

-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
#![deny(fuzzy_provenance_casts)]
44
//~^ WARNING unknown lint: `fuzzy_provenance_casts`
5-
//~| WARNING unknown lint: `fuzzy_provenance_casts`
6-
//~| WARNING unknown lint: `fuzzy_provenance_casts`
75
#![deny(lossy_provenance_casts)]
86
//~^ WARNING unknown lint: `lossy_provenance_casts`
9-
//~| WARNING unknown lint: `lossy_provenance_casts`
10-
//~| WARNING unknown lint: `lossy_provenance_casts`
117

128
fn main() {
139
// no warnings emitted since the lints are not activated

0 commit comments

Comments
 (0)