-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #109957 - fmease:fix-109905, r=petrochenkov
diagnostics: account for self type when looking for source of unsolved type variable Fixes #109905. When searching for the source of an unsolved infer var inside of a list of generic args, we look through the `tcx.generics_of(…).own_substs(…)` which *skips* the self type if present. However, the computed `argument_index` is later[^1] used to index into `tcx.generics_of(…).params` which may still contain the self type. In such case, we are off by one when indexing into the parameters. From now on, we account for this immediately after calling `own_substs` which keeps things local. This also fixes the wrong output in the preexisting UI test `inference/need_type_info/concrete-impl.rs` which was overlooked. It used to claim that the *type of type parameter `Self`* couldn't be inferred in `<Struct as Ambiguous<_>>::method()` which of course isn't true: `Self` equals `Struct` here, `A` couldn't be inferred. `@rustbot` label A-diagnostics [^1]: https://github.com/rust-lang/rust/blob/f98a2718141593fbb8dbad10acc537786d748156/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs#L471
- Loading branch information
Showing
5 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Test that we show the correct type parameter that couldn't be inferred and that we don't | ||
// end up stating nonsense like "type parameter `'a`" which we used to do. | ||
|
||
trait Trait<'a, T> { | ||
fn m(self); | ||
} | ||
|
||
impl<'a, A> Trait<'a, A> for () { | ||
fn m(self) {} | ||
} | ||
|
||
fn qualified() { | ||
<() as Trait<'static, _>>::m(()); | ||
//~^ ERROR type annotations needed | ||
//~| NOTE cannot infer type of the type parameter `T` | ||
|
||
} | ||
|
||
fn unqualified() { | ||
Trait::<'static, _>::m(()); | ||
//~^ ERROR type annotations needed | ||
//~| NOTE cannot infer type of the type parameter `T` | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0282]: type annotations needed | ||
--> $DIR/issue-109905.rs:13:5 | ||
| | ||
LL | <() as Trait<'static, _>>::m(()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the trait `Trait` | ||
|
||
error[E0282]: type annotations needed | ||
--> $DIR/issue-109905.rs:20:5 | ||
| | ||
LL | Trait::<'static, _>::m(()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the trait `Trait` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0282`. |