Skip to content

Commit a243ef5

Browse files
authored
Unrolled build for rust-lang#119388
Rollup merge of rust-lang#119388 - Enselic:prevent-lint-triplication, r=cjgillot rustc_lint: Prevent triplication of various lints Prevent triplication of various lints. The triplication happens because we run the same lint three times (or less in some cases): * In `BuiltinCombinedPreExpansionLintPass` * In `BuiltinCombinedEarlyLintPass` * In `shallow_lint_levels_on()` Only run the lints one time by checking the `lint_added_lints` bool. Set your GitHub diff setting to ignore whitespaces changes when reviewing this PR, since I had to enclose a block inside an if. Closes rust-lang#73301 (I found this while exploring the code related to [this](rust-lang#119251 (comment)) comment.)
2 parents 3cdd004 + 7ca4e9f commit a243ef5

37 files changed

+64
-664
lines changed

compiler/rustc_error_codes/src/error_codes/E0453.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Example of erroneous code:
88
99
#[allow(non_snake_case)]
1010
fn main() {
11-
let MyNumber = 2; // error: allow(non_snake_case) overruled by outer
12-
// forbid(non_snake_case)
11+
// error: allow(non_snake_case) incompatible with previous forbid
12+
let MyNumber = 2;
1313
}
1414
```
1515

compiler/rustc_lint/src/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ impl<'a> EarlyContext<'a> {
10691069
pub(crate) fn new(
10701070
sess: &'a Session,
10711071
features: &'a Features,
1072-
warn_about_weird_lints: bool,
1072+
lint_added_lints: bool,
10731073
lint_store: &'a LintStore,
10741074
registered_tools: &'a RegisteredTools,
10751075
buffered: LintBuffer,
@@ -1078,7 +1078,7 @@ impl<'a> EarlyContext<'a> {
10781078
builder: LintLevelsBuilder::new(
10791079
sess,
10801080
features,
1081-
warn_about_weird_lints,
1081+
lint_added_lints,
10821082
lint_store,
10831083
registered_tools,
10841084
),

compiler/rustc_lint/src/levels.rs

+31-31
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
135135
unstable_to_stable_ids: FxHashMap::default(),
136136
empty: FxHashMap::default(),
137137
},
138-
warn_about_weird_lints: false,
138+
lint_added_lints: false,
139139
store,
140140
registered_tools: tcx.registered_tools(()),
141141
};
@@ -164,7 +164,7 @@ fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLe
164164
empty: FxHashMap::default(),
165165
attrs,
166166
},
167-
warn_about_weird_lints: false,
167+
lint_added_lints: false,
168168
store,
169169
registered_tools: tcx.registered_tools(()),
170170
};
@@ -451,7 +451,7 @@ pub struct LintLevelsBuilder<'s, P> {
451451
sess: &'s Session,
452452
features: &'s Features,
453453
provider: P,
454-
warn_about_weird_lints: bool,
454+
lint_added_lints: bool,
455455
store: &'s LintStore,
456456
registered_tools: &'s RegisteredTools,
457457
}
@@ -464,15 +464,15 @@ impl<'s> LintLevelsBuilder<'s, TopDown> {
464464
pub(crate) fn new(
465465
sess: &'s Session,
466466
features: &'s Features,
467-
warn_about_weird_lints: bool,
467+
lint_added_lints: bool,
468468
store: &'s LintStore,
469469
registered_tools: &'s RegisteredTools,
470470
) -> Self {
471471
let mut builder = LintLevelsBuilder {
472472
sess,
473473
features,
474474
provider: TopDown { sets: LintLevelSets::new(), cur: COMMAND_LINE },
475-
warn_about_weird_lints,
475+
lint_added_lints,
476476
store,
477477
registered_tools,
478478
};
@@ -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
//
@@ -968,7 +968,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
968968
continue;
969969
}
970970

971-
_ if !self.warn_about_weird_lints => {}
971+
_ if !self.lint_added_lints => {}
972972

973973
CheckLintNameResult::Renamed(ref replace) => {
974974
let suggestion =
@@ -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;
@@ -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/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/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 => {}

0 commit comments

Comments
 (0)