Pass the correct DefId when suggesting writing the aliased Self type out
This commit is contained in:
parent
fe61575228
commit
87ced1561f
@ -1071,7 +1071,7 @@ fn explain_self_literal(
|
|||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
*span,
|
*span,
|
||||||
"use the type name directly",
|
"use the type name directly",
|
||||||
self.tcx.value_path_str_with_args(*alias_to, e_args),
|
self.tcx.value_path_str_with_args(e_def.did(), e_args),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
25
tests/ui/typeck/ice-self-mismatch-const-generics.rs
Normal file
25
tests/ui/typeck/ice-self-mismatch-const-generics.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Checks that the following does not ICE when constructing type mismatch diagnostic involving
|
||||||
|
// `Self` and const generics.
|
||||||
|
// Issue: <https://github.com/rust-lang/rust/issues/122467>
|
||||||
|
|
||||||
|
pub struct GenericStruct<const N: usize, T> {
|
||||||
|
thing: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> GenericStruct<0, T> {
|
||||||
|
pub fn new(thing: T) -> GenericStruct<1, T> {
|
||||||
|
Self { thing }
|
||||||
|
//~^ ERROR mismatched types
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct GenericStruct2<const M: usize, T>(T);
|
||||||
|
|
||||||
|
impl<T> GenericStruct2<0, T> {
|
||||||
|
pub fn new(thing: T) -> GenericStruct2<1, T> {
|
||||||
|
Self { 0: thing }
|
||||||
|
//~^ ERROR mismatched types
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
37
tests/ui/typeck/ice-self-mismatch-const-generics.stderr
Normal file
37
tests/ui/typeck/ice-self-mismatch-const-generics.stderr
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/ice-self-mismatch-const-generics.rs:11:9
|
||||||
|
|
|
||||||
|
LL | impl<T> GenericStruct<0, T> {
|
||||||
|
| ------------------- this is the type of the `Self` literal
|
||||||
|
LL | pub fn new(thing: T) -> GenericStruct<1, T> {
|
||||||
|
| ------------------- expected `GenericStruct<1, T>` because of return type
|
||||||
|
LL | Self { thing }
|
||||||
|
| ^^^^^^^^^^^^^^ expected `1`, found `0`
|
||||||
|
|
|
||||||
|
= note: expected struct `GenericStruct<_, 1>`
|
||||||
|
found struct `GenericStruct<_, 0>`
|
||||||
|
help: use the type name directly
|
||||||
|
|
|
||||||
|
LL | GenericStruct::<1, T> { thing }
|
||||||
|
| ~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/ice-self-mismatch-const-generics.rs:20:9
|
||||||
|
|
|
||||||
|
LL | impl<T> GenericStruct2<0, T> {
|
||||||
|
| -------------------- this is the type of the `Self` literal
|
||||||
|
LL | pub fn new(thing: T) -> GenericStruct2<1, T> {
|
||||||
|
| -------------------- expected `GenericStruct2<1, T>` because of return type
|
||||||
|
LL | Self { 0: thing }
|
||||||
|
| ^^^^^^^^^^^^^^^^^ expected `1`, found `0`
|
||||||
|
|
|
||||||
|
= note: expected struct `GenericStruct2<_, 1>`
|
||||||
|
found struct `GenericStruct2<_, 0>`
|
||||||
|
help: use the type name directly
|
||||||
|
|
|
||||||
|
LL | GenericStruct2::<1, T> { 0: thing }
|
||||||
|
| ~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Reference in New Issue
Block a user