Skip to content

Commit

Permalink
Add a note to duplicate diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexendoo committed Oct 4, 2023
1 parent 2ffeb46 commit 7233cec
Show file tree
Hide file tree
Showing 152 changed files with 408 additions and 169 deletions.
11 changes: 8 additions & 3 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,16 +1376,16 @@ impl HandlerInner {
self.emitted_diagnostic_codes.insert(code.clone());
}

let already_emitted = |this: &mut Self| {
let already_emitted = {
let mut hasher = StableHasher::new();
diagnostic.hash(&mut hasher);
let diagnostic_hash = hasher.finish();
!this.emitted_diagnostics.insert(diagnostic_hash)
!self.emitted_diagnostics.insert(diagnostic_hash)
};

// Only emit the diagnostic if we've been asked to deduplicate or
// haven't already emitted an equivalent diagnostic.
if !(self.flags.deduplicate_diagnostics && already_emitted(self)) {
if !(self.flags.deduplicate_diagnostics && already_emitted) {
debug!(?diagnostic);
debug!(?self.emitted_diagnostics);
let already_emitted_sub = |sub: &mut SubDiagnostic| {
Expand All @@ -1401,6 +1401,11 @@ impl HandlerInner {
};

diagnostic.children.extract_if(already_emitted_sub).for_each(|_| {});
if already_emitted {
diagnostic.note(
"duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`",
);
}

self.emitter.emit_diagnostic(diagnostic);
if diagnostic.is_error() {
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/allocator/not-an-allocator.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ LL | static A: usize = 0;
| ^^^^^ the trait `GlobalAlloc` is not implemented for `usize`
|
= help: the trait `GlobalAlloc` is implemented for `System`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
Expand All @@ -29,6 +30,7 @@ LL | static A: usize = 0;
| ^^^^^ the trait `GlobalAlloc` is not implemented for `usize`
|
= help: the trait `GlobalAlloc` is implemented for `System`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
Expand All @@ -40,6 +42,7 @@ LL | static A: usize = 0;
| ^^^^^ the trait `GlobalAlloc` is not implemented for `usize`
|
= help: the trait `GlobalAlloc` is implemented for `System`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
= note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 4 previous errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ note: erroneous constant encountered
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error
Expand Down
1 change: 1 addition & 0 deletions tests/ui/associated-inherent-types/issue-109789.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ LL | fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}
|
= note: expected struct `Foo<fn(&'static ())>`
found struct `Foo<for<'a> fn(&'a ())>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors

Expand Down
12 changes: 12 additions & 0 deletions tests/ui/associated-type-bounds/duplicate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ LL | trait TRS1: Iterator<Item: Copy, Item: Send> {}
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0719]: the value of the associated type `Item` (from trait `Iterator`) is already specified
--> $DIR/duplicate.rs:197:34
Expand All @@ -389,6 +391,8 @@ LL | trait TRS2: Iterator<Item: Copy, Item: Copy> {}
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0719]: the value of the associated type `Item` (from trait `Iterator`) is already specified
--> $DIR/duplicate.rs:200:37
Expand All @@ -405,6 +409,8 @@ LL | trait TRS3: Iterator<Item: 'static, Item: 'static> {}
| ------------- ^^^^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0719]: the value of the associated type `Item` (from trait `Iterator`) is already specified
--> $DIR/duplicate.rs:205:29
Expand Down Expand Up @@ -445,6 +451,8 @@ LL | Self: Iterator<Item: Copy, Item: Send>,
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0719]: the value of the associated type `Item` (from trait `Iterator`) is already specified
--> $DIR/duplicate.rs:230:32
Expand All @@ -461,6 +469,8 @@ LL | Self: Iterator<Item: Copy, Item: Copy>,
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0719]: the value of the associated type `Item` (from trait `Iterator`) is already specified
--> $DIR/duplicate.rs:237:35
Expand All @@ -477,6 +487,8 @@ LL | Self: Iterator<Item: 'static, Item: 'static>,
| ------------- ^^^^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0719]: the value of the associated type `Item` (from trait `Iterator`) is already specified
--> $DIR/duplicate.rs:255:40
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ LL | trait Z<'a, T: ?Sized>
...
LL | for<'b> <T as Z<'b, u16>>::W: Clone,
| ^^^^^ required by this bound in `Z`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 3 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ LL | | });
|
= note: `fn(&'0 ()) -> std::future::Ready<&'0 ()> {std::future::ready::<&'0 ()>}` must implement `FnOnce<(&'1 (),)>`, for any two lifetimes `'0` and `'1`...
= note: ...but it actually implements `FnOnce<(&(),)>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ note: the lifetime requirement is introduced here
|
LL | F: Future + Send + 'static,
| ^^^^
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors; 1 warning emitted

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ note: ...does not necessarily outlive the lifetime `'c` as defined here
|
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
| ^^
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0195]: lifetime parameters or bounds on method `wrong_bound2` do not match the trait declaration
--> $DIR/regions-bound-missing-bound-in-impl.rs:42:20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ LL | #![cfg_attr(foo, crate_type="bin")]
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #91632 <https://github.com/rust-lang/rust/issues/91632>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `crate_name` within an `#![cfg_attr] attribute is deprecated`
--> $DIR/future-compat-crate-attributes-using-cfg_attr.rs:9:18
Expand All @@ -34,6 +35,7 @@ LL | #![cfg_attr(foo, crate_name="bar")]
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #91632 <https://github.com/rust-lang/rust/issues/91632>
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 4 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ LL | #[cfg(feature = $expr)]
LL | generate_s10!(concat!("nonexistent"));
| ------------------------------------- in this macro invocation
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
= note: this error originates in the macro `generate_s10` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 11 previous errors
Expand Down
1 change: 1 addition & 0 deletions tests/ui/const-generics/assoc_const_eq_diagnostic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ note: associated constant defined here
|
LL | const MODE: Mode;
| ^^^^^^^^^^^^^^^^
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 4 previous errors

Expand Down
4 changes: 4 additions & 0 deletions tests/ui/const-generics/issues/issue-74950.min.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ LL | struct Outer<const I: Inner>;
|
= note: the only supported types are integers, `bool` and `char`
= help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `Inner` is forbidden as the type of a const generic parameter
--> $DIR/issue-74950.rs:20:23
Expand All @@ -24,6 +25,7 @@ LL | struct Outer<const I: Inner>;
|
= note: the only supported types are integers, `bool` and `char`
= help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `Inner` is forbidden as the type of a const generic parameter
--> $DIR/issue-74950.rs:20:23
Expand All @@ -33,6 +35,7 @@ LL | struct Outer<const I: Inner>;
|
= note: the only supported types are integers, `bool` and `char`
= help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `Inner` is forbidden as the type of a const generic parameter
--> $DIR/issue-74950.rs:20:23
Expand All @@ -42,6 +45,7 @@ LL | struct Outer<const I: Inner>;
|
= note: the only supported types are integers, `bool` and `char`
= help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 5 previous errors

2 changes: 2 additions & 0 deletions tests/ui/consts/const-err-late.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ note: erroneous constant encountered
|
LL | black_box((S::<i32>::FOO, S::<u32>::FOO));
| ^^^^^^^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors

Expand Down
1 change: 1 addition & 0 deletions tests/ui/consts/const-eval/issue-44578.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ note: erroneous constant encountered
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
= note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/consts/const-eval/panic-assoc-never-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ note: erroneous constant encountered
|
LL | let _ = PrintName::VOID;
| ^^^^^^^^^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ help: the constant being evaluated
|
LL | const Y: u32 = simple_loop(35);
| ^^^^^^^^^^^^
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

warning: constant evaluation is taking a long time
--> $DIR/ctfe-simple-loop.rs:9:5
Expand Down
5 changes: 2 additions & 3 deletions tests/ui/consts/const_in_pattern/reject_non_structural.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// compile-flags: -Zdeduplicate-diagnostics=yes

// This test of structural match checking enumerates the different kinds of
// const definitions, collecting cases where the const pattern is rejected.
//
Expand Down Expand Up @@ -78,9 +80,6 @@ fn main() {
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| NOTE the traits must be derived
//~| NOTE StructuralEq.html for details
//~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| NOTE the traits must be derived
//~| NOTE StructuralEq.html for details

trait Trait: Sized { const ASSOC: Option<Self>; }
impl Trait for NoDerive { const ASSOC: Option<NoDerive> = Some(NoDerive); }
Expand Down
33 changes: 12 additions & 21 deletions tests/ui/consts/const_in_pattern/reject_non_structural.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/reject_non_structural.rs:40:36
--> $DIR/reject_non_structural.rs:42:36
|
LL | match Derive::Some(NoDerive) { ENUM => dbg!(ENUM), _ => panic!("whoops"), };
| ^^^^
Expand All @@ -8,7 +8,7 @@ LL | match Derive::Some(NoDerive) { ENUM => dbg!(ENUM), _ => panic!("whoops"
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details

error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/reject_non_structural.rs:46:28
--> $DIR/reject_non_structural.rs:48:28
|
LL | match Some(NoDerive) { FIELD => dbg!(FIELD), _ => panic!("whoops"), };
| ^^^^^
Expand All @@ -17,7 +17,7 @@ LL | match Some(NoDerive) { FIELD => dbg!(FIELD), _ => panic!("whoops"), };
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details

error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/reject_non_structural.rs:53:27
--> $DIR/reject_non_structural.rs:55:27
|
LL | match Some(NoDerive) {INDIRECT => dbg!(INDIRECT), _ => panic!("whoops"), };
| ^^^^^^^^
Expand All @@ -26,7 +26,7 @@ LL | match Some(NoDerive) {INDIRECT => dbg!(INDIRECT), _ => panic!("whoops")
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details

error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/reject_non_structural.rs:59:36
--> $DIR/reject_non_structural.rs:61:36
|
LL | match (None, Some(NoDerive)) { TUPLE => dbg!(TUPLE), _ => panic!("whoops"), };
| ^^^^^
Expand All @@ -35,7 +35,7 @@ LL | match (None, Some(NoDerive)) { TUPLE => dbg!(TUPLE), _ => panic!("whoop
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details

error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/reject_non_structural.rs:65:28
--> $DIR/reject_non_structural.rs:67:28
|
LL | match Some(NoDerive) { TYPE_ASCRIPTION => dbg!(TYPE_ASCRIPTION), _ => panic!("whoops"), };
| ^^^^^^^^^^^^^^^
Expand All @@ -44,7 +44,7 @@ LL | match Some(NoDerive) { TYPE_ASCRIPTION => dbg!(TYPE_ASCRIPTION), _ => p
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details

error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/reject_non_structural.rs:71:36
--> $DIR/reject_non_structural.rs:73:36
|
LL | match [None, Some(NoDerive)] { ARRAY => dbg!(ARRAY), _ => panic!("whoops"), };
| ^^^^^
Expand All @@ -53,7 +53,7 @@ LL | match [None, Some(NoDerive)] { ARRAY => dbg!(ARRAY), _ => panic!("whoop
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details

error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/reject_non_structural.rs:77:33
--> $DIR/reject_non_structural.rs:79:33
|
LL | match [Some(NoDerive); 2] { REPEAT => dbg!(REPEAT), _ => panic!("whoops"), };
| ^^^^^^
Expand All @@ -62,16 +62,7 @@ LL | match [Some(NoDerive); 2] { REPEAT => dbg!(REPEAT), _ => panic!("whoops
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details

error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/reject_non_structural.rs:77:33
|
LL | match [Some(NoDerive); 2] { REPEAT => dbg!(REPEAT), _ => panic!("whoops"), };
| ^^^^^^
|
= note: the traits must be derived, manual `impl`s are not sufficient
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details

error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/reject_non_structural.rs:87:28
--> $DIR/reject_non_structural.rs:86:28
|
LL | match Some(NoDerive) { NoDerive::ASSOC => dbg!(NoDerive::ASSOC), _ => panic!("whoops"), };
| ^^^^^^^^^^^^^^^
Expand All @@ -80,7 +71,7 @@ LL | match Some(NoDerive) { NoDerive::ASSOC => dbg!(NoDerive::ASSOC), _ => p
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details

error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/reject_non_structural.rs:93:28
--> $DIR/reject_non_structural.rs:92:28
|
LL | match Some(NoDerive) { BLOCK => dbg!(BLOCK), _ => panic!("whoops"), };
| ^^^^^
Expand All @@ -89,7 +80,7 @@ LL | match Some(NoDerive) { BLOCK => dbg!(BLOCK), _ => panic!("whoops"), };
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details

warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/reject_non_structural.rs:99:29
--> $DIR/reject_non_structural.rs:98:29
|
LL | match &Some(NoDerive) { ADDR_OF => dbg!(ADDR_OF), _ => panic!("whoops"), };
| ^^^^^^^
Expand All @@ -99,10 +90,10 @@ LL | match &Some(NoDerive) { ADDR_OF => dbg!(ADDR_OF), _ => panic!("whoops")
= note: the traits must be derived, manual `impl`s are not sufficient
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
note: the lint level is defined here
--> $DIR/reject_non_structural.rs:12:9
--> $DIR/reject_non_structural.rs:14:9
|
LL | #![warn(indirect_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 10 previous errors; 1 warning emitted
error: aborting due to 9 previous errors; 1 warning emitted

1 change: 1 addition & 0 deletions tests/ui/consts/enum-discr-type-err.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ LL | | B = T,
LL | | }
| |_- in this macro invocation
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors
Expand Down
Loading

0 comments on commit 7233cec

Please sign in to comment.