Continue evaluating after finding incorrect .. in pattern

This commit is contained in:
Esteban Küber 2019-01-11 21:33:57 -08:00
parent 975f8b5e32
commit 8119017746
5 changed files with 42 additions and 11 deletions

View file

@ -3814,8 +3814,12 @@ impl<'a> Parser<'a> {
ddpos = Some(fields.len()); ddpos = Some(fields.len());
} else { } else {
// Emit a friendly error, ignore `..` and continue parsing // Emit a friendly error, ignore `..` and continue parsing
self.span_err(self.prev_span, self.struct_span_err(
"`..` can only be used once per tuple or tuple struct pattern"); self.prev_span,
"`..` can only be used once per tuple or tuple struct pattern",
)
.span_label(self.prev_span, "can only be used once per pattern")
.emit();
} }
} else if !self.check(&token::CloseDelim(token::Paren)) { } else if !self.check(&token::CloseDelim(token::Paren)) {
fields.push(self.parse_pat(None)?); fields.push(self.parse_pat(None)?);
@ -3831,7 +3835,10 @@ impl<'a> Parser<'a> {
if ddpos == Some(fields.len()) && trailing_comma { if ddpos == Some(fields.len()) && trailing_comma {
// `..` needs to be followed by `)` or `, pat`, `..,)` is disallowed. // `..` needs to be followed by `)` or `, pat`, `..,)` is disallowed.
self.span_err(self.prev_span, "trailing comma is not permitted after `..`"); let msg = "trailing comma is not permitted after `..`";
self.struct_span_err(self.prev_span, msg)
.span_label(self.prev_span, msg)
.emit();
} }
Ok((fields, ddpos, trailing_comma)) Ok((fields, ddpos, trailing_comma))

View file

@ -1,5 +1,7 @@
fn main() { fn main() {
match 0 { match 0 {
(pat, ..,) => {} //~ ERROR trailing comma is not permitted after `..` (pat, ..,) => {}
//~^ ERROR trailing comma is not permitted after `..`
//~| ERROR mismatched types
} }
} }

View file

@ -1,8 +1,18 @@
error: trailing comma is not permitted after `..` error: trailing comma is not permitted after `..`
--> $DIR/pat-tuple-2.rs:3:17 --> $DIR/pat-tuple-2.rs:3:17
| |
LL | (pat, ..,) => {} //~ ERROR trailing comma is not permitted after `..` LL | (pat, ..,) => {}
| ^ | ^ trailing comma is not permitted after `..`
error: aborting due to previous error error[E0308]: mismatched types
--> $DIR/pat-tuple-2.rs:3:9
|
LL | (pat, ..,) => {}
| ^^^^^^^^^^ expected integer, found tuple
|
= note: expected type `{integer}`
found type `(_,)`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.

View file

@ -1,5 +1,7 @@
fn main() { fn main() {
match 0 { match 0 {
(.., pat, ..) => {} //~ ERROR `..` can only be used once per tuple or tuple struct pattern (.., pat, ..) => {}
//~^ ERROR `..` can only be used once per tuple or tuple struct pattern
//~| ERROR mismatched types
} }
} }

View file

@ -1,8 +1,18 @@
error: `..` can only be used once per tuple or tuple struct pattern error: `..` can only be used once per tuple or tuple struct pattern
--> $DIR/pat-tuple-3.rs:3:19 --> $DIR/pat-tuple-3.rs:3:19
| |
LL | (.., pat, ..) => {} //~ ERROR `..` can only be used once per tuple or tuple struct pattern LL | (.., pat, ..) => {}
| ^^ | ^^ can only be used once per pattern
error: aborting due to previous error error[E0308]: mismatched types
--> $DIR/pat-tuple-3.rs:3:9
|
LL | (.., pat, ..) => {}
| ^^^^^^^^^^^^^ expected integer, found tuple
|
= note: expected type `{integer}`
found type `(_,)`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.