Skip to content

Commit 55980d0

Browse files
committed
dedup for placeholder typs
1 parent 10a98e8 commit 55980d0

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

compiler/rustc_hir_analysis/src/collect.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ pub(crate) fn placeholder_type_error<'tcx>(
176176
pub(crate) fn placeholder_type_error_diag<'tcx>(
177177
tcx: TyCtxt<'tcx>,
178178
generics: Option<&hir::Generics<'_>>,
179-
placeholder_types: Vec<Span>,
179+
mut placeholder_types: Vec<Span>,
180180
additional_spans: Vec<Span>,
181181
suggest: bool,
182182
hir_ty: Option<&hir::Ty<'_>>,
@@ -188,6 +188,8 @@ pub(crate) fn placeholder_type_error_diag<'tcx>(
188188

189189
let params = generics.map(|g| g.params).unwrap_or_default();
190190
let type_name = params.next_type_param_name(None);
191+
192+
placeholder_types.dedup();
191193
let mut sugg: Vec<_> =
192194
placeholder_types.iter().map(|sp| (*sp, (*type_name).to_string())).collect();
193195

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

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
| ^ not allowed in type signatures
6+
|
7+
help: use type parameters instead
8+
|
9+
LL ~ fn foo<T>(_: $ty, _: $ty) {}
10+
LL | }
11+
LL | }
12+
LL |
13+
LL ~ foo!(T);
14+
|
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)