diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2023-12-09 14:05:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-09 14:05:09 +0100 |
| commit | 0865eefcafa3d4a034e367a476891b114895083c (patch) | |
| tree | 2a606c7bfe8fb958a9d709a49b6be0284477ca0f | |
| parent | c57b0549af086cf237bb74fe2a056dbad226f144 (diff) | |
| parent | 199098b71b7495fbbc91d62e20b831f17761c95b (diff) | |
| download | rust-0865eefcafa3d4a034e367a476891b114895083c.tar.gz rust-0865eefcafa3d4a034e367a476891b114895083c.zip | |
Rollup merge of #118057 - bvanjoi:fix-118048, r=cjgillot
dedup for duplicate suggestions Fixes #118048 An easy fix.
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic.rs | 9 | ||||
| -rw-r--r-- | tests/ui/macros/issue-118048.rs | 10 | ||||
| -rw-r--r-- | tests/ui/macros/issue-118048.stderr | 21 |
3 files changed, 36 insertions, 4 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 6aaf4a0f5cf..4fb63d67e78 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -591,17 +591,18 @@ impl Diagnostic { pub fn multipart_suggestion_with_style( &mut self, msg: impl Into<SubdiagnosticMessage>, - suggestion: Vec<(Span, String)>, + mut suggestion: Vec<(Span, String)>, applicability: Applicability, style: SuggestionStyle, ) -> &mut Self { - let mut parts = suggestion + suggestion.sort_unstable(); + suggestion.dedup(); + + let parts = suggestion .into_iter() .map(|(span, snippet)| SubstitutionPart { snippet, span }) .collect::<Vec<_>>(); - parts.sort_unstable_by_key(|part| part.span); - assert!(!parts.is_empty()); debug_assert_eq!( parts.iter().find(|part| part.span.is_empty() && part.snippet.is_empty()), diff --git a/tests/ui/macros/issue-118048.rs b/tests/ui/macros/issue-118048.rs new file mode 100644 index 00000000000..15a834fa2df --- /dev/null +++ b/tests/ui/macros/issue-118048.rs @@ -0,0 +1,10 @@ +macro_rules! foo { + ($ty:ty) => { + fn foo(_: $ty, _: $ty) {} + } +} + +foo!(_); +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + +fn main() {} diff --git a/tests/ui/macros/issue-118048.stderr b/tests/ui/macros/issue-118048.stderr new file mode 100644 index 00000000000..6acf78f63b2 --- /dev/null +++ b/tests/ui/macros/issue-118048.stderr @@ -0,0 +1,21 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/issue-118048.rs:7:6 + | +LL | foo!(_); + | ^ + | | + | not allowed in type signatures + | not allowed in type signatures + | +help: use type parameters instead + | +LL ~ fn foo<T>(_: $ty, _: $ty) {} +LL | } +LL | } +LL | +LL ~ foo!(T); + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0121`. |
