Skip to content

Commit

Permalink
dedup for placeholder typs
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Nov 19, 2023
1 parent 10a98e8 commit 55980d0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub(crate) fn placeholder_type_error<'tcx>(
pub(crate) fn placeholder_type_error_diag<'tcx>(
tcx: TyCtxt<'tcx>,
generics: Option<&hir::Generics<'_>>,
placeholder_types: Vec<Span>,
mut placeholder_types: Vec<Span>,
additional_spans: Vec<Span>,
suggest: bool,
hir_ty: Option<&hir::Ty<'_>>,
Expand All @@ -188,6 +188,8 @@ pub(crate) fn placeholder_type_error_diag<'tcx>(

let params = generics.map(|g| g.params).unwrap_or_default();
let type_name = params.next_type_param_name(None);

placeholder_types.dedup();
let mut sugg: Vec<_> =
placeholder_types.iter().map(|sp| (*sp, (*type_name).to_string())).collect();

Expand Down
10 changes: 10 additions & 0 deletions tests/ui/macros/issue-118048.rs
Original file line number Diff line number Diff line change
@@ -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() {}
18 changes: 18 additions & 0 deletions tests/ui/macros/issue-118048.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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
|
help: use type parameters instead
|
LL ~ fn foo<T>(_: $ty, _: $ty) {}
LL | }
LL | }
LL |
LL ~ foo!(T);
|

error: aborting due to previous error

For more information about this error, try `rustc --explain E0121`.

0 comments on commit 55980d0

Please sign in to comment.