Closed
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.