From 75895f59b0742126a7b5abeb86b35df2dfa8ee59 Mon Sep 17 00:00:00 2001 From: yukang Date: Wed, 15 May 2024 10:26:07 +0800 Subject: [PATCH] Fix the dedup error because of spans from suggestion --- compiler/rustc_errors/src/diagnostic.rs | 2 +- tests/ui/macros/macro-span-issue-116502.rs | 16 ++++++++++ .../ui/macros/macro-span-issue-116502.stderr | 30 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/ui/macros/macro-span-issue-116502.rs create mode 100644 tests/ui/macros/macro-span-issue-116502.stderr diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 1610135a0efad..18bb71bd99f73 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -896,7 +896,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { style: SuggestionStyle, ) -> &mut Self { suggestion.sort_unstable(); - suggestion.dedup(); + suggestion.dedup_by(|(s1, m1), (s2, m2)| s1.source_equal(*s2) && m1 == m2); let parts = suggestion .into_iter() diff --git a/tests/ui/macros/macro-span-issue-116502.rs b/tests/ui/macros/macro-span-issue-116502.rs new file mode 100644 index 0000000000000..4c254289ee684 --- /dev/null +++ b/tests/ui/macros/macro-span-issue-116502.rs @@ -0,0 +1,16 @@ +#![allow(dead_code)] +#![allow(unused_variables)] + +fn bug() { + macro_rules! m { + () => { + _ //~ ERROR the placeholder `_` is not allowed within types on item signatures for structs + }; + } + struct S(m!(), T) + where + T: Trait; +} +trait Trait {} + +fn main() {} diff --git a/tests/ui/macros/macro-span-issue-116502.stderr b/tests/ui/macros/macro-span-issue-116502.stderr new file mode 100644 index 0000000000000..da02855660a4f --- /dev/null +++ b/tests/ui/macros/macro-span-issue-116502.stderr @@ -0,0 +1,30 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/macro-span-issue-116502.rs:7:13 + | +LL | _ + | ^ + | | + | not allowed in type signatures + | not allowed in type signatures + | not allowed in type signatures +... +LL | struct S(m!(), T) + | ---- ---- in this macro invocation + | | + | in this macro invocation +LL | where +LL | T: Trait; + | ---- in this macro invocation + | + = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use type parameters instead + | +LL ~ U +LL | }; +LL | } +LL ~ struct S(m!(), T) + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0121`.