Skip to content

Commit e0c626f

Browse files
committed
rustc_lint: Prevent multiple 'lint ignored' lints
Prevent multiple 'ignored unless specified at crate level' lints. The multiplication happens because we run the same lint three times: * In BuiltinCombinedEarlyLintPass * In BuiltinCombinedPreExpansionLintPass * In shallow_lint_levels_on Only run the lint one time by checking the `lint_added_lints` bool.
1 parent eef02c4 commit e0c626f

File tree

3 files changed

+4
-58
lines changed

3 files changed

+4
-58
lines changed

compiler/rustc_lint/src/levels.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
10291029
}
10301030
}
10311031

1032-
if !is_crate_node {
1032+
if self.lint_added_lints && !is_crate_node {
10331033
for (id, &(level, ref src)) in self.current_specs().iter() {
10341034
if !id.lint.crate_level_only {
10351035
continue;

tests/ui/lint/crate_level_only_lint.rs

-6
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,14 @@
33
mod foo {
44
#![allow(uncommon_codepoints)]
55
//~^ ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes]
6-
//~| ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes]
7-
//~| ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes]
86

97
#[allow(uncommon_codepoints)]
108
//~^ ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes]
11-
//~| ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes]
12-
//~| ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes]
139
const BAR: f64 = 0.000001;
1410

1511
}
1612

1713
#[allow(uncommon_codepoints)]
1814
//~^ ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes]
19-
//~| ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes]
20-
//~| ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes]
2115
fn main() {
2216
}

tests/ui/lint/crate_level_only_lint.stderr

+3-51
Original file line numberDiff line numberDiff line change
@@ -11,64 +11,16 @@ LL | #![deny(uncommon_codepoints, unused_attributes)]
1111
| ^^^^^^^^^^^^^^^^^
1212

1313
error: allow(uncommon_codepoints) is ignored unless specified at crate level
14-
--> $DIR/crate_level_only_lint.rs:9:9
14+
--> $DIR/crate_level_only_lint.rs:7:9
1515
|
1616
LL | #[allow(uncommon_codepoints)]
1717
| ^^^^^^^^^^^^^^^^^^^
1818

1919
error: allow(uncommon_codepoints) is ignored unless specified at crate level
20-
--> $DIR/crate_level_only_lint.rs:17:9
20+
--> $DIR/crate_level_only_lint.rs:13:9
2121
|
2222
LL | #[allow(uncommon_codepoints)]
2323
| ^^^^^^^^^^^^^^^^^^^
2424

25-
error: allow(uncommon_codepoints) is ignored unless specified at crate level
26-
--> $DIR/crate_level_only_lint.rs:4:10
27-
|
28-
LL | #![allow(uncommon_codepoints)]
29-
| ^^^^^^^^^^^^^^^^^^^
30-
|
31-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
32-
33-
error: allow(uncommon_codepoints) is ignored unless specified at crate level
34-
--> $DIR/crate_level_only_lint.rs:9:9
35-
|
36-
LL | #[allow(uncommon_codepoints)]
37-
| ^^^^^^^^^^^^^^^^^^^
38-
|
39-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
40-
41-
error: allow(uncommon_codepoints) is ignored unless specified at crate level
42-
--> $DIR/crate_level_only_lint.rs:17:9
43-
|
44-
LL | #[allow(uncommon_codepoints)]
45-
| ^^^^^^^^^^^^^^^^^^^
46-
|
47-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
48-
49-
error: allow(uncommon_codepoints) is ignored unless specified at crate level
50-
--> $DIR/crate_level_only_lint.rs:4:10
51-
|
52-
LL | #![allow(uncommon_codepoints)]
53-
| ^^^^^^^^^^^^^^^^^^^
54-
|
55-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
56-
57-
error: allow(uncommon_codepoints) is ignored unless specified at crate level
58-
--> $DIR/crate_level_only_lint.rs:9:9
59-
|
60-
LL | #[allow(uncommon_codepoints)]
61-
| ^^^^^^^^^^^^^^^^^^^
62-
|
63-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
64-
65-
error: allow(uncommon_codepoints) is ignored unless specified at crate level
66-
--> $DIR/crate_level_only_lint.rs:17:9
67-
|
68-
LL | #[allow(uncommon_codepoints)]
69-
| ^^^^^^^^^^^^^^^^^^^
70-
|
71-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
72-
73-
error: aborting due to 9 previous errors
25+
error: aborting due to 3 previous errors
7426

0 commit comments

Comments
 (0)