The following code: playground:
trait MyTrait {}
impl MyTrait for bool {}
fn make_it<T>() -> impl MyTrait {
true
}
fn main() {
let mut a = make_it::<String>();
a = make_it::<u8>();
}
produces the following error:
error[E0308]: mismatched types
--> src/main.rs:10:9
|
10 | a = make_it::<u8>();
| ^^^^^^^^^^^^^^^ expected struct `std::string::String`, found u8
|
= note: expected type `impl MyTrait` (struct `std::string::String`)
found type `impl MyTrait` (u8)
However, it does not explain where u8 and String come from.
When emitting a 'mistmatched type' error for two 'impl trait' types with the same DefId, we should explain that each set of generic parameters creates a unique opaque type, which is not equivalent to other opaque types generated by the same function.
See #66463 (comment) for the original discussion
The following code: playground:
produces the following error:
However, it does not explain where
u8andStringcome from.When emitting a 'mistmatched type' error for two 'impl trait' types with the same
DefId, we should explain that each set of generic parameters creates a unique opaque type, which is not equivalent to other opaque types generated by the same function.See #66463 (comment) for the original discussion