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

Confusing diagnostic when type mismatch on a tuple struct's generic type: Consider removing the `` #104242

Closed
fee1-dead opened this issue Nov 10, 2022 · 0 comments · Fixed by #104261
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fee1-dead
Copy link
Member

Given the following code:

pub trait Foo { type T; }
impl Foo for i32 { type T = f32; }

pub struct U<T1, T2>(T1, S<T2>) where T1: Foo<T = T2>;

pub struct S<T>(T);

fn a() {
    let _: U<_, u32> = U(1, S(3u32));
}

The current output is:

error[E0308]: mismatched types
 --> src/lib.rs:9:29
  |
9 |     let _: U<_, u32> = U(1, S(3u32));
  |                        -    ^^^^^^^ expected `f32`, found `u32`
  |                        |
  |                        arguments to this struct are incorrect
  |
  = note: expected struct `S<_>` (`f32`)
             found struct `S<_>` (`u32`)
note: tuple struct defined here
 --> src/lib.rs:4:12
  |
4 | pub struct U<T1, T2>(T1, S<T2>) where T1: Foo<T = T2>;
  |            ^
help: consider removing the ``
  |
9 |     let _: U<_, u32> = U(1, S(3u32));
  |

error[E0308]: mismatched types
 --> src/lib.rs:9:24
  |
9 |     let _: U<_, u32> = U(1, S(3u32));
  |            ---------   ^^^^^^^^^^^^^ expected `u32`, found `f32`
  |            |
  |            expected due to this
  |
  = note: expected struct `U<_, u32>`
             found struct `U<i32, f32>`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to 2 previous errors
@fee1-dead fee1-dead added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. and removed A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Nov 10, 2022
@compiler-errors compiler-errors self-assigned this Nov 10, 2022
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Nov 12, 2022
…d-differ, r=estebank

More accurately report error when formal and expected signature types differ

Fixes rust-lang#104242
@bors bors closed this as completed in fe80364 Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants