Skip to content

diagnostics: avoid ICE for undeclared generic parameter in impl#154182

Open
Unique-Usman wants to merge 1 commit intorust-lang:mainfrom
Unique-Usman:ua/constnotype2
Open

diagnostics: avoid ICE for undeclared generic parameter in impl#154182
Unique-Usman wants to merge 1 commit intorust-lang:mainfrom
Unique-Usman:ua/constnotype2

Conversation

@Unique-Usman
Copy link
Contributor

@Unique-Usman Unique-Usman commented Mar 21, 2026

Avoid an ICE for:

struct A;
impl A<B> {}

The compiler no longer panics and can proceed to emit existing diagnostics.

Adds tests/ui/missing/undeclared-generic-parameter.rs.

Fixes #154165 and introduced by #152913

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 21, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 21, 2026

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 15 candidates

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

Avoid an ICE for:

    struct A;
    impl A<B> {}

The compiler no longer panics and can proceed to emit existing diagnostics.

Adds `tests/ui/missing/undeclared-generic-parameter.rs`.

Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
@Unique-Usman Unique-Usman changed the title diagnostics: ICE for undeclared generic parameter in impl diagnostics: avoid ICE for undeclared generic parameter in impl Mar 21, 2026
@Unique-Usman
Copy link
Contributor Author

Unique-Usman commented Mar 21, 2026

r? @matthiaskrgr

@rustbot rustbot assigned matthiaskrgr and unassigned petrochenkov Mar 21, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 21, 2026

matthiaskrgr is currently at their maximum review capacity.
They may take a while to respond.

@Kivooeo
Copy link
Member

Kivooeo commented Mar 21, 2026

Please, don't assign Matthias

r? compiler

@rustbot rustbot assigned jieyouxu and unassigned matthiaskrgr Mar 21, 2026
@estebank
Copy link
Contributor

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 21, 2026

📌 Commit b31dc4a has been approved by estebank

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 21, 2026
Comment on lines +1 to +17
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> {}
| +++
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].

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 21, 2026
…tebank

diagnostics: avoid ICE for undeclared generic parameter in impl

Avoid an ICE for:

    struct A;
    impl A<B> {}

The compiler no longer panics and can proceed to emit existing diagnostics.

Adds `tests/ui/missing/undeclared-generic-parameter.rs`.

Fixes rust-lang#154165 and introduced by rust-lang#152913
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 21, 2026
…tebank

diagnostics: avoid ICE for undeclared generic parameter in impl

Avoid an ICE for:

    struct A;
    impl A<B> {}

The compiler no longer panics and can proceed to emit existing diagnostics.

Adds `tests/ui/missing/undeclared-generic-parameter.rs`.

Fixes rust-lang#154165 and introduced by rust-lang#152913
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: diagnostics: index out of bounds let target_param = &struct_generics.params[idx]

7 participants