Skip to content

Commit bae47b7

Browse files
committed
deduplicate unused expect lints
1 parent 3ee9c50 commit bae47b7

12 files changed

+29
-727
lines changed

compiler/rustc_lint/src/expect.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,33 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
1818
let mut expectations = Vec::new();
1919

2020
for owner in krate.owners() {
21+
// Deduplicate expectations
22+
let mut inner_expectations = Vec::new();
2123
let lints = tcx.shallow_lint_levels_on(owner);
22-
expectations.extend_from_slice(&lints.expectations);
24+
for expectation in &lints.expectations {
25+
let canonicalized = canonicalize_id(&expectation.0);
26+
if !inner_expectations.iter().any(|(id, _)| canonicalize_id(id) == canonicalized) {
27+
inner_expectations.push(expectation.clone());
28+
}
29+
}
30+
expectations.extend(inner_expectations);
2331
}
2432

2533
expectations
2634
}
2735

36+
fn canonicalize_id(expect_id: &LintExpectationId) -> (rustc_span::AttrId, u16) {
37+
match *expect_id {
38+
LintExpectationId::Unstable { attr_id, lint_index, .. } => (attr_id, lint_index),
39+
LintExpectationId::Stable { attr_id, lint_index, .. } => (attr_id, lint_index),
40+
}
41+
}
42+
2843
fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
2944
let lint_expectations = tcx.lint_expectations(());
3045
let fulfilled_expectations = tcx.dcx().steal_fulfilled_expectation_ids();
3146

3247
// Turn a `LintExpectationId` into a `(AttrId, lint_index)` pair.
33-
let canonicalize_id = |expect_id: &LintExpectationId| match *expect_id {
34-
LintExpectationId::Unstable { attr_id, lint_index, .. } => (attr_id, lint_index),
35-
LintExpectationId::Stable { attr_id, lint_index, .. } => (attr_id, lint_index),
36-
};
37-
3848
let fulfilled_expectations: FxHashSet<_> =
3949
fulfilled_expectations.iter().map(canonicalize_id).collect();
4050

src/tools/clippy/tests/ui/expect_tool_lint_rfc_2383.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ mod rustc_warn {
3636

3737
#[expect(invalid_nan_comparisons)]
3838
//~^ ERROR: this lint expectation is unfulfilled
39-
//~| NOTE: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
40-
//~| ERROR: this lint expectation is unfulfilled
4139
let _b = x == 5;
4240
}
4341
}

src/tools/clippy/tests/ui/expect_tool_lint_rfc_2383.stderr

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,28 @@ LL | #[expect(invalid_nan_comparisons)]
1414
| ^^^^^^^^^^^^^^^^^^^^^^^
1515

1616
error: this lint expectation is unfulfilled
17-
--> tests/ui/expect_tool_lint_rfc_2383.rs:37:18
18-
|
19-
LL | #[expect(invalid_nan_comparisons)]
20-
| ^^^^^^^^^^^^^^^^^^^^^^^
21-
|
22-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
23-
24-
error: this lint expectation is unfulfilled
25-
--> tests/ui/expect_tool_lint_rfc_2383.rs:110:14
17+
--> tests/ui/expect_tool_lint_rfc_2383.rs:108:14
2618
|
2719
LL | #[expect(clippy::almost_swapped)]
2820
| ^^^^^^^^^^^^^^^^^^^^^^
2921

3022
error: this lint expectation is unfulfilled
31-
--> tests/ui/expect_tool_lint_rfc_2383.rs:118:14
23+
--> tests/ui/expect_tool_lint_rfc_2383.rs:116:14
3224
|
3325
LL | #[expect(clippy::bytes_nth)]
3426
| ^^^^^^^^^^^^^^^^^
3527

3628
error: this lint expectation is unfulfilled
37-
--> tests/ui/expect_tool_lint_rfc_2383.rs:124:14
29+
--> tests/ui/expect_tool_lint_rfc_2383.rs:122:14
3830
|
3931
LL | #[expect(clippy::if_same_then_else)]
4032
| ^^^^^^^^^^^^^^^^^^^^^^^^^
4133

4234
error: this lint expectation is unfulfilled
43-
--> tests/ui/expect_tool_lint_rfc_2383.rs:130:14
35+
--> tests/ui/expect_tool_lint_rfc_2383.rs:128:14
4436
|
4537
LL | #[expect(clippy::overly_complex_bool_expr)]
4638
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4739

48-
error: aborting due to 7 previous errors
40+
error: aborting due to 6 previous errors
4941

tests/ui/argument-suggestions/wrong-highlight-span-extra-arguments-147070.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/ui/lint/rfc-2383-lint-reason/expect_multiple_lints.rs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,50 +42,6 @@ fn check_multiple_lints_with_lint_group_1() {
4242

4343
#[expect(unused, while_true)]
4444
//~^ WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
45-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
46-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
47-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
48-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
49-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
50-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
51-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
52-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
53-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
54-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
55-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
56-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
57-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
58-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
59-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
60-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
61-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
62-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
63-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
64-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
65-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
66-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
67-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
68-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
69-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
70-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
71-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
72-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
73-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
74-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
75-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
76-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
77-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
78-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
79-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
80-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
81-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
82-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
83-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
84-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
85-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
86-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
87-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
88-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
8945
fn check_multiple_lints_with_lint_group_2() {
9046
while true {}
9147
}

tests/ui/lint/rfc-2383-lint-reason/expect_multiple_lints.stderr

Lines changed: 1 addition & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -48,181 +48,5 @@ warning: this lint expectation is unfulfilled
4848
LL | #[expect(unused, while_true)]
4949
| ^^^^^^
5050

51-
warning: this lint expectation is unfulfilled
52-
--> $DIR/expect_multiple_lints.rs:43:10
53-
|
54-
LL | #[expect(unused, while_true)]
55-
| ^^^^^^
56-
|
57-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
58-
59-
warning: this lint expectation is unfulfilled
60-
--> $DIR/expect_multiple_lints.rs:43:10
61-
|
62-
LL | #[expect(unused, while_true)]
63-
| ^^^^^^
64-
|
65-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
66-
67-
warning: this lint expectation is unfulfilled
68-
--> $DIR/expect_multiple_lints.rs:43:10
69-
|
70-
LL | #[expect(unused, while_true)]
71-
| ^^^^^^
72-
|
73-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
74-
75-
warning: this lint expectation is unfulfilled
76-
--> $DIR/expect_multiple_lints.rs:43:10
77-
|
78-
LL | #[expect(unused, while_true)]
79-
| ^^^^^^
80-
|
81-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
82-
83-
warning: this lint expectation is unfulfilled
84-
--> $DIR/expect_multiple_lints.rs:43:10
85-
|
86-
LL | #[expect(unused, while_true)]
87-
| ^^^^^^
88-
|
89-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
90-
91-
warning: this lint expectation is unfulfilled
92-
--> $DIR/expect_multiple_lints.rs:43:10
93-
|
94-
LL | #[expect(unused, while_true)]
95-
| ^^^^^^
96-
|
97-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
98-
99-
warning: this lint expectation is unfulfilled
100-
--> $DIR/expect_multiple_lints.rs:43:10
101-
|
102-
LL | #[expect(unused, while_true)]
103-
| ^^^^^^
104-
|
105-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
106-
107-
warning: this lint expectation is unfulfilled
108-
--> $DIR/expect_multiple_lints.rs:43:10
109-
|
110-
LL | #[expect(unused, while_true)]
111-
| ^^^^^^
112-
|
113-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
114-
115-
warning: this lint expectation is unfulfilled
116-
--> $DIR/expect_multiple_lints.rs:43:10
117-
|
118-
LL | #[expect(unused, while_true)]
119-
| ^^^^^^
120-
|
121-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
122-
123-
warning: this lint expectation is unfulfilled
124-
--> $DIR/expect_multiple_lints.rs:43:10
125-
|
126-
LL | #[expect(unused, while_true)]
127-
| ^^^^^^
128-
|
129-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
130-
131-
warning: this lint expectation is unfulfilled
132-
--> $DIR/expect_multiple_lints.rs:43:10
133-
|
134-
LL | #[expect(unused, while_true)]
135-
| ^^^^^^
136-
|
137-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
138-
139-
warning: this lint expectation is unfulfilled
140-
--> $DIR/expect_multiple_lints.rs:43:10
141-
|
142-
LL | #[expect(unused, while_true)]
143-
| ^^^^^^
144-
|
145-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
146-
147-
warning: this lint expectation is unfulfilled
148-
--> $DIR/expect_multiple_lints.rs:43:10
149-
|
150-
LL | #[expect(unused, while_true)]
151-
| ^^^^^^
152-
|
153-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
154-
155-
warning: this lint expectation is unfulfilled
156-
--> $DIR/expect_multiple_lints.rs:43:10
157-
|
158-
LL | #[expect(unused, while_true)]
159-
| ^^^^^^
160-
|
161-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
162-
163-
warning: this lint expectation is unfulfilled
164-
--> $DIR/expect_multiple_lints.rs:43:10
165-
|
166-
LL | #[expect(unused, while_true)]
167-
| ^^^^^^
168-
|
169-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
170-
171-
warning: this lint expectation is unfulfilled
172-
--> $DIR/expect_multiple_lints.rs:43:10
173-
|
174-
LL | #[expect(unused, while_true)]
175-
| ^^^^^^
176-
|
177-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
178-
179-
warning: this lint expectation is unfulfilled
180-
--> $DIR/expect_multiple_lints.rs:43:10
181-
|
182-
LL | #[expect(unused, while_true)]
183-
| ^^^^^^
184-
|
185-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
186-
187-
warning: this lint expectation is unfulfilled
188-
--> $DIR/expect_multiple_lints.rs:43:10
189-
|
190-
LL | #[expect(unused, while_true)]
191-
| ^^^^^^
192-
|
193-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
194-
195-
warning: this lint expectation is unfulfilled
196-
--> $DIR/expect_multiple_lints.rs:43:10
197-
|
198-
LL | #[expect(unused, while_true)]
199-
| ^^^^^^
200-
|
201-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
202-
203-
warning: this lint expectation is unfulfilled
204-
--> $DIR/expect_multiple_lints.rs:43:10
205-
|
206-
LL | #[expect(unused, while_true)]
207-
| ^^^^^^
208-
|
209-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
210-
211-
warning: this lint expectation is unfulfilled
212-
--> $DIR/expect_multiple_lints.rs:43:10
213-
|
214-
LL | #[expect(unused, while_true)]
215-
| ^^^^^^
216-
|
217-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
218-
219-
warning: this lint expectation is unfulfilled
220-
--> $DIR/expect_multiple_lints.rs:43:10
221-
|
222-
LL | #[expect(unused, while_true)]
223-
| ^^^^^^
224-
|
225-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
226-
227-
warning: 30 warnings emitted
51+
warning: 8 warnings emitted
22852

tests/ui/lint/rfc-2383-lint-reason/expect_tool_lint_rfc_2383.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ mod rustc_warn {
3737

3838
#[expect(invalid_nan_comparisons)]
3939
//~^ WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
40-
//~| WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
41-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
4240
let _b = x == 5;
4341
}
4442
}

tests/ui/lint/rfc-2383-lint-reason/expect_tool_lint_rfc_2383.stderr

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,5 @@ warning: this lint expectation is unfulfilled
1212
LL | #[expect(invalid_nan_comparisons)]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^
1414

15-
warning: this lint expectation is unfulfilled
16-
--> $DIR/expect_tool_lint_rfc_2383.rs:38:18
17-
|
18-
LL | #[expect(invalid_nan_comparisons)]
19-
| ^^^^^^^^^^^^^^^^^^^^^^^
20-
|
21-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
22-
23-
warning: 3 warnings emitted
15+
warning: 2 warnings emitted
2416

tests/ui/lint/rfc-2383-lint-reason/expect_unfulfilled_expectation.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,15 @@
1616
pub fn normal_test_fn() {
1717
#[expect(unused_mut, reason = "this expectation will create a diagnostic with the default lint level")]
1818
//~^ WARNING this lint expectation is unfulfilled
19-
//~| WARNING this lint expectation is unfulfilled
2019
//~| NOTE this expectation will create a diagnostic with the default lint level
21-
//~| NOTE this expectation will create a diagnostic with the default lint level
22-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
2320
let mut v = vec![1, 1, 2, 3, 5];
2421
v.sort();
2522

2623
// Check that lint lists including `unfulfilled_lint_expectations` are also handled correctly
2724
#[expect(unused, unfulfilled_lint_expectations, reason = "the expectation for `unused` should be fulfilled")]
2825
//~^ WARNING this lint expectation is unfulfilled
29-
//~| WARNING this lint expectation is unfulfilled
30-
//~| NOTE the expectation for `unused` should be fulfilled
3126
//~| NOTE the expectation for `unused` should be fulfilled
3227
//~| NOTE the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
33-
//~| NOTE the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
34-
//~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
3528
let value = "I'm unused";
3629
}
3730

0 commit comments

Comments
 (0)