Closed
Description
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
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Category: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.