Rollup merge of #139981 - compiler-errors:name-2, r=nnethercote

Don't compute name of associated item if it's an RPITIT

Another simple fix for an RPITIT name ICE.

Fixes https://github.com/rust-lang/rust/issues/139941
Fixes #140084

r? nnethercote
This commit is contained in:
Chris Denton 2025-04-22 01:22:11 +00:00 committed by GitHub
commit 32862fba47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 72 additions and 10 deletions

View file

@ -0,0 +1,12 @@
trait Foo {
fn rpitit() -> impl Sized;
}
// Ensure that we don't try to probe the name of the RPITIT when looking for
// fixes to suggest for the redundant generic below.
fn test<T: Foo<i32, Assoc = i32>>() {}
//~^ ERROR trait takes 0 generic arguments but 1 generic argument was supplied
//~| ERROR associated type `Assoc` not found for `Foo`
fn main() {}

View file

@ -0,0 +1,24 @@
error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
--> $DIR/dont-probe-missing-item-name-2.rs:8:12
|
LL | fn test<T: Foo<i32, Assoc = i32>>() {}
| ^^^------------------ help: remove the unnecessary generics
| |
| expected 0 generic arguments
|
note: trait defined here, with 0 generic parameters
--> $DIR/dont-probe-missing-item-name-2.rs:1:7
|
LL | trait Foo {
| ^^^
error[E0220]: associated type `Assoc` not found for `Foo`
--> $DIR/dont-probe-missing-item-name-2.rs:8:21
|
LL | fn test<T: Foo<i32, Assoc = i32>>() {}
| ^^^^^ associated type `Assoc` not found
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0107, E0220.
For more information about an error, try `rustc --explain E0107`.

View file

@ -0,0 +1,11 @@
trait Trait {
fn method() -> impl Sized;
}
// Ensure that we don't try to probe the name of the RPITIT when looking for
// fixes to suggest for the missing associated type's trait path below.
fn foo() -> i32::Assoc {}
//~^ ERROR ambiguous associated type
fn main() {}

View file

@ -0,0 +1,15 @@
error[E0223]: ambiguous associated type
--> $DIR/dont-probe-missing-item-name-3.rs:8:13
|
LL | fn foo() -> i32::Assoc {}
| ^^^^^^^^^^
|
help: if there were a trait named `Example` with associated type `Assoc` implemented for `i32`, you could use the fully-qualified path
|
LL - fn foo() -> i32::Assoc {}
LL + fn foo() -> <i32 as Example>::Assoc {}
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0223`.