Skip to content

Commit 0865eef

Browse files
Rollup merge of #118057 - bvanjoi:fix-118048, r=cjgillot
dedup for duplicate suggestions Fixes #118048 An easy fix.
2 parents c57b054 + 199098b commit 0865eef

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

compiler/rustc_errors/src/diagnostic.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -591,17 +591,18 @@ impl Diagnostic {
591591
pub fn multipart_suggestion_with_style(
592592
&mut self,
593593
msg: impl Into<SubdiagnosticMessage>,
594-
suggestion: Vec<(Span, String)>,
594+
mut suggestion: Vec<(Span, String)>,
595595
applicability: Applicability,
596596
style: SuggestionStyle,
597597
) -> &mut Self {
598-
let mut parts = suggestion
598+
suggestion.sort_unstable();
599+
suggestion.dedup();
600+
601+
let parts = suggestion
599602
.into_iter()
600603
.map(|(span, snippet)| SubstitutionPart { snippet, span })
601604
.collect::<Vec<_>>();
602605

603-
parts.sort_unstable_by_key(|part| part.span);
604-
605606
assert!(!parts.is_empty());
606607
debug_assert_eq!(
607608
parts.iter().find(|part| part.span.is_empty() && part.snippet.is_empty()),

tests/ui/macros/issue-118048.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
macro_rules! foo {
2+
($ty:ty) => {
3+
fn foo(_: $ty, _: $ty) {}
4+
}
5+
}
6+
7+
foo!(_);
8+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
9+
10+
fn main() {}

tests/ui/macros/issue-118048.stderr

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
2+
--> $DIR/issue-118048.rs:7:6
3+
|
4+
LL | foo!(_);
5+
| ^
6+
| |
7+
| not allowed in type signatures
8+
| not allowed in type signatures
9+
|
10+
help: use type parameters instead
11+
|
12+
LL ~ fn foo<T>(_: $ty, _: $ty) {}
13+
LL | }
14+
LL | }
15+
LL |
16+
LL ~ foo!(T);
17+
|
18+
19+
error: aborting due to 1 previous error
20+
21+
For more information about this error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)