Continue evaluating after finding incorrect .. in pattern
This commit is contained in:
parent
975f8b5e32
commit
8119017746
5 changed files with 42 additions and 11 deletions
|
@ -3814,8 +3814,12 @@ impl<'a> Parser<'a> {
|
|||
ddpos = Some(fields.len());
|
||||
} else {
|
||||
// Emit a friendly error, ignore `..` and continue parsing
|
||||
self.span_err(self.prev_span,
|
||||
"`..` can only be used once per tuple or tuple struct pattern");
|
||||
self.struct_span_err(
|
||||
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)) {
|
||||
fields.push(self.parse_pat(None)?);
|
||||
|
@ -3831,7 +3835,10 @@ impl<'a> Parser<'a> {
|
|||
|
||||
if ddpos == Some(fields.len()) && trailing_comma {
|
||||
// `..` 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))
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
fn main() {
|
||||
match 0 {
|
||||
(pat, ..,) => {} //~ ERROR trailing comma is not permitted after `..`
|
||||
(pat, ..,) => {}
|
||||
//~^ ERROR trailing comma is not permitted after `..`
|
||||
//~| ERROR mismatched types
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
error: trailing comma is not permitted after `..`
|
||||
--> $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`.
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
fn main() {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
error: `..` can only be used once per tuple or tuple struct pattern
|
||||
--> $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`.
|
||||
|
|
Loading…
Add table
Reference in a new issue