Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3381,7 +3381,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
&& def_id.is_local()
&& let Some(local_def_id) = def_id.as_local()
&& let Some(struct_generics) = self.r.struct_generics.get(&local_def_id)
&& let target_param = &struct_generics.params[idx]
&& let Some(target_param) = &struct_generics.params.get(idx)
&& let GenericParamKind::Const { ty, .. } = &target_param.kind
&& let TyKind::Path(_, path) = &ty.kind
{
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/missing/undeclared-generic-parameter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
struct A;
impl A<B> {}
//~^ ERROR cannot find type `B` in this scope
//~| ERROR struct takes 0 generic arguments but 1 generic argument was supplied
fn main() {}
36 changes: 36 additions & 0 deletions tests/ui/missing/undeclared-generic-parameter.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
error[E0425]: cannot find type `B` in this scope
--> $DIR/undeclared-generic-parameter.rs:2:8
|
LL | struct A;
| --------- similarly named struct `A` defined here
LL | impl A<B> {}
| ^
|
help: a struct with a similar name exists
|
LL - impl A<B> {}
LL + impl A<A> {}
|
help: you might be missing a type parameter
|
LL | impl<B> A<B> {}
| +++
Comment on lines +1 to +17
Copy link
Contributor

@estebank estebank Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Not for this PR) It'd be nice if we didn't provide any suggestion in this case and instead mentioned that A takes no parameter (at this place, same thing for struct A<T> and impl<T> A<T, K> {} so that we emit a single error instead of two, but this is [p-low].


error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
--> $DIR/undeclared-generic-parameter.rs:2:6
|
LL | impl A<B> {}
| ^--- help: remove the unnecessary generics
| |
| expected 0 generic arguments
|
note: struct defined here, with 0 generic parameters
--> $DIR/undeclared-generic-parameter.rs:1:8
|
LL | struct A;
| ^

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0107, E0425.
For more information about an error, try `rustc --explain E0107`.
Loading