Skip to content

Commit ca27f03

Browse files
committed
Fix #88256, remove duplicated diagnostic
1 parent 26feefd commit ca27f03

11 files changed

+59
-65
lines changed

compiler/rustc_errors/src/diagnostic.rs

+48-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ use rustc_lint_defs::Applicability;
99
use rustc_serialize::json::Json;
1010
use rustc_span::{MultiSpan, Span, DUMMY_SP};
1111
use std::fmt;
12+
use std::hash::{Hash, Hasher};
1213

1314
#[must_use]
14-
#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)]
15+
#[derive(Clone, Debug, Encodable, Decodable)]
1516
pub struct Diagnostic {
1617
pub level: Level,
1718
pub message: Vec<(String, Style)>,
@@ -24,6 +25,10 @@ pub struct Diagnostic {
2425
/// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of
2526
/// `span` if there is one. Otherwise, it is `DUMMY_SP`.
2627
pub sort_span: Span,
28+
29+
/// If diagnostic is from Lint, custom hash function ignores notes
30+
/// otherwise hash is based on the all the fields
31+
pub is_lint: bool,
2732
}
2833

2934
#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
@@ -91,6 +96,7 @@ impl Diagnostic {
9196
children: vec![],
9297
suggestions: vec![],
9398
sort_span: DUMMY_SP,
99+
is_lint: false,
94100
}
95101
}
96102

@@ -558,6 +564,11 @@ impl Diagnostic {
558564
self
559565
}
560566

567+
pub fn set_is_lint(&mut self) -> &mut Self {
568+
self.is_lint = true;
569+
self
570+
}
571+
561572
pub fn code(&mut self, s: DiagnosticId) -> &mut Self {
562573
self.code = Some(s);
563574
self
@@ -617,6 +628,42 @@ impl Diagnostic {
617628
let sub = SubDiagnostic { level, message, span, render_span };
618629
self.children.push(sub);
619630
}
631+
632+
/// Fields used for Hash, and PartialEq trait
633+
fn keys(
634+
&self,
635+
) -> (
636+
&Level,
637+
&Vec<(String, Style)>,
638+
&Option<DiagnosticId>,
639+
&MultiSpan,
640+
&Vec<CodeSuggestion>,
641+
Option<&Vec<SubDiagnostic>>,
642+
) {
643+
(
644+
&self.level,
645+
&self.message,
646+
&self.code,
647+
&self.span,
648+
&self.suggestions,
649+
(if self.is_lint { None } else { Some(&self.children) }),
650+
)
651+
}
652+
}
653+
654+
impl Hash for Diagnostic {
655+
fn hash<H>(&self, state: &mut H)
656+
where
657+
H: Hasher,
658+
{
659+
self.keys().hash(state);
660+
}
661+
}
662+
663+
impl PartialEq for Diagnostic {
664+
fn eq(&self, other: &Self) -> bool {
665+
self.keys() == other.keys()
666+
}
620667
}
621668

622669
impl SubDiagnostic {

compiler/rustc_errors/src/diagnostic_builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ impl<'a> DiagnosticBuilder<'a> {
242242
sp: S,
243243
msg: &str,
244244
) -> &mut Self);
245+
forward!(pub fn set_is_lint(&mut self,) -> &mut Self);
245246

246247
/// See [`Diagnostic::multipart_suggestion()`].
247248
pub fn multipart_suggestion(

compiler/rustc_middle/src/lint.rs

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ impl<'a> LintDiagnosticBuilder<'a> {
192192
/// Return the inner DiagnosticBuilder, first setting the primary message to `msg`.
193193
pub fn build(mut self, msg: &str) -> DiagnosticBuilder<'a> {
194194
self.0.set_primary_message(msg);
195+
self.0.set_is_lint();
195196
self.0
196197
}
197198

src/test/ui/lint/issue-70819-dont-override-forbid-in-same-scope.rs

-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ fn forbid_first(num: i32) -> i32 {
2121
#![deny(unused)]
2222
//~^ ERROR: deny(unused) incompatible with previous forbid
2323
//~| WARNING being phased out
24-
//~| ERROR: deny(unused) incompatible with previous forbid
25-
//~| WARNING being phased out
2624
#![warn(unused)]
2725
#![allow(unused)]
2826

src/test/ui/lint/issue-70819-dont-override-forbid-in-same-scope.stderr

+1-12
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,5 @@ LL | #![forbid(forbidden_lint_groups)]
1414
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1515
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
1616

17-
error: deny(unused) incompatible with previous forbid
18-
--> $DIR/issue-70819-dont-override-forbid-in-same-scope.rs:21:13
19-
|
20-
LL | #![forbid(unused)]
21-
| ------ `forbid` level set here
22-
LL | #![deny(unused)]
23-
| ^^^^^^ overruled by previous forbid
24-
|
25-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
26-
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
27-
28-
error: aborting due to 2 previous errors
17+
error: aborting due to previous error
2918

src/test/ui/lint/outer-forbid.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
#![forbid(unused, non_snake_case)]
1818
#![forbid(forbidden_lint_groups)]
1919

20-
#[allow(unused_variables)] //~ ERROR incompatible with previous
20+
#[allow(unused_variables)]
2121
//~^ ERROR incompatible with previous
2222
//~| WARNING this was previously accepted by the compiler
23-
//~| WARNING this was previously accepted by the compiler
2423
fn foo() {}
2524

2625
#[allow(unused)] //~ ERROR incompatible with previous

src/test/ui/lint/outer-forbid.stderr

+3-15
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | #![forbid(forbidden_lint_groups)]
1616
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
1717

1818
error: allow(unused) incompatible with previous forbid
19-
--> $DIR/outer-forbid.rs:26:9
19+
--> $DIR/outer-forbid.rs:25:9
2020
|
2121
LL | #![forbid(unused, non_snake_case)]
2222
| ------ `forbid` level set here
@@ -28,26 +28,14 @@ LL | #[allow(unused)]
2828
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
2929

3030
error[E0453]: allow(nonstandard_style) incompatible with previous forbid
31-
--> $DIR/outer-forbid.rs:30:9
31+
--> $DIR/outer-forbid.rs:29:9
3232
|
3333
LL | #![forbid(unused, non_snake_case)]
3434
| -------------- `forbid` level set here
3535
...
3636
LL | #[allow(nonstandard_style)]
3737
| ^^^^^^^^^^^^^^^^^ overruled by previous forbid
3838

39-
error: allow(unused_variables) incompatible with previous forbid
40-
--> $DIR/outer-forbid.rs:20:9
41-
|
42-
LL | #![forbid(unused, non_snake_case)]
43-
| ------ `forbid` level set here
44-
...
45-
LL | #[allow(unused_variables)]
46-
| ^^^^^^^^^^^^^^^^ overruled by previous forbid
47-
|
48-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
49-
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
50-
51-
error: aborting due to 4 previous errors
39+
error: aborting due to 3 previous errors
5240

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

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

+1-19
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,6 @@ LL | 1 => 2,
106106
| ^
107107
= help: ...or consider changing the match arm bodies
108108

109-
error: this `match` has identical arm bodies
110-
--> $DIR/match_same_arms.rs:33:14
111-
|
112-
LL | 3 => 2, //~ ERROR 3rd matched arms have same body
113-
| ^
114-
|
115-
note: same as this
116-
--> $DIR/match_same_arms.rs:32:14
117-
|
118-
LL | 2 => 2, //~ ERROR 2nd matched arms have same body
119-
| ^
120-
help: consider refactoring into `2 | 3`
121-
--> $DIR/match_same_arms.rs:32:9
122-
|
123-
LL | 2 => 2, //~ ERROR 2nd matched arms have same body
124-
| ^
125-
= help: ...or consider changing the match arm bodies
126-
127109
error: this `match` has identical arm bodies
128110
--> $DIR/match_same_arms.rs:50:55
129111
|
@@ -142,5 +124,5 @@ LL | CommandInfo::BuiltIn { name, .. } => name.to_string(),
142124
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
143125
= help: ...or consider changing the match arm bodies
144126

145-
error: aborting due to 8 previous errors
127+
error: aborting due to 7 previous errors
146128

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

+1-7
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ LL | const ONE: u32 = 1 * 1;
4646
|
4747
= note: `-D clippy::identity-op` implied by `-D warnings`
4848

49-
error: the operation is ineffective. Consider reducing it to `1`
50-
--> $DIR/modulo_one.rs:13:22
51-
|
52-
LL | const ONE: u32 = 1 * 1;
53-
| ^^^^^
54-
5549
error: any number modulo 1 will be 0
5650
--> $DIR/modulo_one.rs:17:5
5751
|
@@ -70,5 +64,5 @@ error: any number modulo -1 will panic/overflow or result in 0
7064
LL | INT_MIN % NEG_ONE; // also caught by rustc
7165
| ^^^^^^^^^^^^^^^^^
7266

73-
error: aborting due to 11 previous errors
67+
error: aborting due to 10 previous errors
7468

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

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ LL | self.x == other.y && self.y == other.y && self.z == other.z
66
|
77
= note: `-D clippy::suspicious-operation-groupings` implied by `-D warnings`
88

9-
error: this sequence of operators looks suspiciously like a bug
10-
--> $DIR/suspicious_operation_groupings.rs:14:9
11-
|
12-
LL | self.x == other.y && self.y == other.y && self.z == other.z
13-
| ^^^^^^^^^^^^^^^^^ help: did you mean: `self.x == other.x`
14-
159
error: this sequence of operators looks suspiciously like a bug
1610
--> $DIR/suspicious_operation_groupings.rs:27:20
1711
|
@@ -162,5 +156,5 @@ error: this sequence of operators looks suspiciously like a bug
162156
LL | -(if -s1.a < -s2.a && -s1.a < -s2.b { s1.c } else { s2.a })
163157
| ^^^^^^^^^^^^^ help: did you mean: `-s1.b < -s2.b`
164158

165-
error: aborting due to 27 previous errors
159+
error: aborting due to 26 previous errors
166160

src/tools/rustfmt/src/syntux/session.rs

+1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ mod tests {
311311
suggestions: vec![],
312312
span: span.unwrap_or_else(MultiSpan::new),
313313
sort_span: DUMMY_SP,
314+
is_lint: false,
314315
}
315316
}
316317

0 commit comments

Comments
 (0)