forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#121416 - veera-sivarajan:bugfix-120785, r=nnethercote Improve error messages for generics with default parameters Fixes rust-lang#120785 Issue: Previously, all type parameters with default types were deliberately ignored to simplify error messages. For example, an error message for Box type would display `Box<T>` instead of `Box<T, _>`. But, this resulted in unclear error message when a concrete type was used instead of the default type. Fix: This PR fixes it by checking if a concrete type is specified after a default type to display the entire type name or the simplified type name.
- Loading branch information
Showing
4 changed files
with
79 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
tests/ui/type/clarify-error-for-generics-with-default-issue-120785.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 f: What<usize, Vec<String>> = What(1, vec![String::from("meow")]); | ||
let e: What<usize> = What(5, vec![1, 2, 3]); | ||
f = e; //~ ERROR mismatched types | ||
} |
27 changes: 27 additions & 0 deletions
27
tests/ui/type/clarify-error-for-generics-with-default-issue-120785.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 f: What<usize, Vec<String>> = What(1, vec![String::from("meow")]); | ||
| ------------------------ expected due to this type | ||
LL | let e: What<usize> = What(5, vec![1, 2, 3]); | ||
LL | f = e; | ||
| ^ expected `What<usize, Vec<String>>`, found `What` | ||
| | ||
= note: expected struct `What<_, Vec<String>>` | ||
found struct `What<_, Vec<usize>>` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |