Improve diagnostics for incorrect .. usage
When using `..` somewhere other than the end, parse the rest of the pattern correctly while still emitting an error. Add suggestions to either remove trailing `,` or moving the `..` to the end.
This commit is contained in:
parent
8f4a5429c2
commit
cbc70a0d68
3 changed files with 170 additions and 82 deletions
|
|
@ -17,5 +17,8 @@ struct Point { x: u8, y: u8 }
|
|||
|
||||
fn main() {
|
||||
let p = Point { x: 0, y: 0 };
|
||||
let Point { .., y, } = p; //~ ERROR expected `}`, found `,`
|
||||
let Point { .., y } = p; //~ ERROR expected `}`, found `,`
|
||||
let Point { .., } = p; //~ ERROR expected `}`, found `,`
|
||||
let Point { .. } = p;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,38 @@
|
|||
error: expected `}`, found `,`
|
||||
--> $DIR/issue-49257.rs:20:19
|
||||
|
|
||||
LL | let Point { .., y, } = p; //~ ERROR expected `}`, found `,`
|
||||
| --^
|
||||
| | |
|
||||
| | expected `}`
|
||||
| `..` must be at the end and cannot have a trailing comma
|
||||
help: move the `..` to the end of the field list
|
||||
|
|
||||
LL | let Point { y, , .. } = p; //~ ERROR expected `}`, found `,`
|
||||
| -- ^^^^^^
|
||||
|
||||
error: expected `}`, found `,`
|
||||
--> $DIR/issue-49257.rs:21:19
|
||||
|
|
||||
LL | let Point { .., y } = p; //~ ERROR expected `}`, found `,`
|
||||
| ^ `..` must be in the last position, and cannot have a trailing comma
|
||||
| --^
|
||||
| | |
|
||||
| | expected `}`
|
||||
| `..` must be at the end and cannot have a trailing comma
|
||||
help: move the `..` to the end of the field list
|
||||
|
|
||||
LL | let Point { y , .. } = p; //~ ERROR expected `}`, found `,`
|
||||
| -- ^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
error: expected `}`, found `,`
|
||||
--> $DIR/issue-49257.rs:22:19
|
||||
|
|
||||
LL | let Point { .., } = p; //~ ERROR expected `}`, found `,`
|
||||
| --^
|
||||
| | |
|
||||
| | expected `}`
|
||||
| | help: remove this comma
|
||||
| `..` must be at the end and cannot have a trailing comma
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0027`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue