Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diagnostic should explain that 'impl trait' captures generic parameters #68020

Open
Aaron1011 opened this issue Jan 8, 2020 · 0 comments
Open

Diagnostic should explain that 'impl trait' captures generic parameters #68020

Aaron1011 opened this issue Jan 8, 2020 · 0 comments

Comments

@Aaron1011
Copy link
Contributor

@Aaron1011 Aaron1011 commented Jan 8, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.