Auto merge of #51201 - estebank:dotdot, r=petrochenkov

Accept `..` in incorrect position to avoid further errors

We currently give a specific message when encountering a `..` anywhere
other than the end of a pattern. Modify the parser to accept it (while
still emitting the error) so that we don't also trigger "missing fields
in pattern" errors afterwards.

Add suggestions to either remove trailing `,` or moving the `..` to the
end.

Follow up to #49268.
This commit is contained in:
bors 2018-06-06 14:04:06 +00:00
commit 35aeecb8aa
4 changed files with 169 additions and 78 deletions

View file

@ -13,7 +13,7 @@
fn main() {
struct Foo { x: isize }
match (Foo { x: 10 }) {
Foo { ref x: ref x } => {}, //~ ERROR expected `,`, found `:`
Foo { ref x: ref x } => {}, //~ ERROR expected `,`
_ => {}
}
}

View file

@ -17,6 +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 `,`
//~| ERROR pattern does not mention fields `x`, `y`
let Point { .., } = p; //~ ERROR expected `}`, found `,`
let Point { .. } = p;
}

View file

@ -1,15 +1,38 @@
error: expected `}`, found `,`
--> $DIR/issue-49257.rs:20:19
|
LL | let Point { .., y } = p; //~ ERROR expected `}`, found `,`
| ^ `..` must be in the last position, and cannot have a trailing comma
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[E0027]: pattern does not mention fields `x`, `y`
--> $DIR/issue-49257.rs:20:9
error: expected `}`, found `,`
--> $DIR/issue-49257.rs:21:19
|
LL | let Point { .., y } = p; //~ ERROR expected `}`, found `,`
| ^^^^^^^^^^^^^^^ missing fields `x`, `y`
| --^
| | |
| | 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 2 previous errors
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`.