- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code: playground
struct Wrap<T, S>(T, S);
fn main() {
    let s = Wrap(None, None);
    s.0 = Some(1);
    s.1 = Some(2);
    let z: Wrap<Option<i32>, Option<&str>> = s;
}The current output is:
error[E0308]: mismatched types
 --> src/main.rs:7:46
  |
5 |     s.0 = Some(1);
  |     - here the type of `s` is inferred to be `Wrap<Option<{integer}>, Option<_>>`
6 |     s.1 = Some(2);
7 |     let z: Wrap<Option<i32>, Option<&str>> = s;
  |            -------------------------------   ^ expected `&str`, found integer
  |            |
  |            expected due to this
  |
  = note: expected struct `Wrap<Option<i32>, Option<&str>>`
             found struct `Wrap<Option<{integer}>, Option<{integer}>>`
Ideally the output should look like:
error[E0308]: mismatched types
 --> src/main.rs:7:46
  |
5 |     s.0 = Some(1);
6 |     s.1 = Some(2);
  |     - here the type of `s` is inferred to be `Wrap<Option<{integer}>, Option<{integer}>>`
7 |     let z: Wrap<Option<i32>, Option<&str>> = s;
  |            -------------------------------   ^ expected `&str`, found integer
  |            |
  |            expected due to this
  |
  = note: expected struct `Wrap<Option<i32>, Option<&str>>`
             found struct `Wrap<Option<{integer}>, Option<{integer}>>`
The problem here is that while s.0 = .. is the first expression to constrain Wrap<_, _>, it's not the expression which constrains Wrap<_, _> in such a way that causes the type error, so pointing to it is possibly misleading -- possibly even more confusing if the lines are further separated.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.