Skip to content

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

Closed
@fee1-dead

Description

@fee1-dead

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

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions