about summary refs log tree commit diff
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2024-05-15 10:26:07 +0800
committeryukang <moorekang@gmail.com>2024-05-15 10:28:44 +0800
commit75895f59b0742126a7b5abeb86b35df2dfa8ee59 (patch)
treef00fcd07109aa7d921f6f17070e1ca867c71a8f2
parent8387315ab3c26a57a1f53a90f188f0bc88514bca (diff)
downloadrust-75895f59b0742126a7b5abeb86b35df2dfa8ee59.tar.gz
rust-75895f59b0742126a7b5abeb86b35df2dfa8ee59.zip
Fix the dedup error because of spans from suggestion
-rw-r--r--compiler/rustc_errors/src/diagnostic.rs2
-rw-r--r--tests/ui/macros/macro-span-issue-116502.rs16
-rw-r--r--tests/ui/macros/macro-span-issue-116502.stderr30
3 files changed, 47 insertions, 1 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs
index 1610135a0ef..18bb71bd99f 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 00000000000..4c254289ee6
--- /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<T = m!()>(m!(), T)
+    where
+        T: Trait<m!()>;
+}
+trait Trait<T> {}
+
+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 00000000000..da02855660a
--- /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<T = m!()>(m!(), T)
+   |                  ----  ---- in this macro invocation
+   |                  |
+   |                  in this macro invocation
+LL |     where
+LL |         T: Trait<m!()>;
+   |                  ---- 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<U>(m!(), T)
+   |
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0121`.