Improve error messages for generics with default parameters
Fixes #120785
This commit is contained in:
parent
c475e2303b
commit
49961947c8
4 changed files with 82 additions and 4 deletions
|
|
@ -0,0 +1,11 @@
|
|||
struct What<W = usize, X = Vec<W>>(W, X);
|
||||
|
||||
fn main() {
|
||||
let mut b: What<usize> = What(5, vec![1, 2, 3]);
|
||||
let c: What<usize, String> = What(1, String::from("meow"));
|
||||
b = c; //~ ERROR mismatched types
|
||||
|
||||
let mut e: What<usize> = What(5, vec![1, 2, 3]);
|
||||
let f: What<usize, Vec<String>> = What(1, vec![String::from("meow")]);
|
||||
e = f; //~ ERROR mismatched types
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/clarify-error-for-generics-with-default-issue-120785.rs:6:9
|
||||
|
|
||||
LL | let mut b: What<usize> = What(5, vec![1, 2, 3]);
|
||||
| ----------- expected due to this type
|
||||
LL | let c: What<usize, String> = What(1, String::from("meow"));
|
||||
LL | b = c;
|
||||
| ^ expected `What`, found `What<usize, String>`
|
||||
|
|
||||
= note: expected struct `What<_, Vec<usize>>`
|
||||
found struct `What<_, String>`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/clarify-error-for-generics-with-default-issue-120785.rs:10:9
|
||||
|
|
||||
LL | let mut e: What<usize> = What(5, vec![1, 2, 3]);
|
||||
| ----------- expected due to this type
|
||||
LL | let f: What<usize, Vec<String>> = What(1, vec![String::from("meow")]);
|
||||
LL | e = f;
|
||||
| ^ expected `What`, found `What<usize, Vec<String>>`
|
||||
|
|
||||
= note: expected struct `What<_, Vec<usize>>`
|
||||
found struct `What<_, Vec<String>>`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue