Skip to content

Commit 8119017

Browse files
committed
Continue evaluating after finding incorrect .. in pattern
1 parent 975f8b5 commit 8119017

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3814,8 +3814,12 @@ impl<'a> Parser<'a> {
38143814
ddpos = Some(fields.len());
38153815
} else {
38163816
// Emit a friendly error, ignore `..` and continue parsing
3817-
self.span_err(self.prev_span,
3818-
"`..` can only be used once per tuple or tuple struct pattern");
3817+
self.struct_span_err(
3818+
self.prev_span,
3819+
"`..` can only be used once per tuple or tuple struct pattern",
3820+
)
3821+
.span_label(self.prev_span, "can only be used once per pattern")
3822+
.emit();
38193823
}
38203824
} else if !self.check(&token::CloseDelim(token::Paren)) {
38213825
fields.push(self.parse_pat(None)?);
@@ -3831,7 +3835,10 @@ impl<'a> Parser<'a> {
38313835

38323836
if ddpos == Some(fields.len()) && trailing_comma {
38333837
// `..` needs to be followed by `)` or `, pat`, `..,)` is disallowed.
3834-
self.span_err(self.prev_span, "trailing comma is not permitted after `..`");
3838+
let msg = "trailing comma is not permitted after `..`";
3839+
self.struct_span_err(self.prev_span, msg)
3840+
.span_label(self.prev_span, msg)
3841+
.emit();
38353842
}
38363843

38373844
Ok((fields, ddpos, trailing_comma))

src/test/ui/parser/pat-tuple-2.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
fn main() {
22
match 0 {
3-
(pat, ..,) => {} //~ ERROR trailing comma is not permitted after `..`
3+
(pat, ..,) => {}
4+
//~^ ERROR trailing comma is not permitted after `..`
5+
//~| ERROR mismatched types
46
}
57
}

src/test/ui/parser/pat-tuple-2.stderr

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
error: trailing comma is not permitted after `..`
22
--> $DIR/pat-tuple-2.rs:3:17
33
|
4-
LL | (pat, ..,) => {} //~ ERROR trailing comma is not permitted after `..`
5-
| ^
4+
LL | (pat, ..,) => {}
5+
| ^ trailing comma is not permitted after `..`
66

7-
error: aborting due to previous error
7+
error[E0308]: mismatched types
8+
--> $DIR/pat-tuple-2.rs:3:9
9+
|
10+
LL | (pat, ..,) => {}
11+
| ^^^^^^^^^^ expected integer, found tuple
12+
|
13+
= note: expected type `{integer}`
14+
found type `(_,)`
15+
16+
error: aborting due to 2 previous errors
817

18+
For more information about this error, try `rustc --explain E0308`.

src/test/ui/parser/pat-tuple-3.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
fn main() {
22
match 0 {
3-
(.., pat, ..) => {} //~ ERROR `..` can only be used once per tuple or tuple struct pattern
3+
(.., pat, ..) => {}
4+
//~^ ERROR `..` can only be used once per tuple or tuple struct pattern
5+
//~| ERROR mismatched types
46
}
57
}

src/test/ui/parser/pat-tuple-3.stderr

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
error: `..` can only be used once per tuple or tuple struct pattern
22
--> $DIR/pat-tuple-3.rs:3:19
33
|
4-
LL | (.., pat, ..) => {} //~ ERROR `..` can only be used once per tuple or tuple struct pattern
5-
| ^^
4+
LL | (.., pat, ..) => {}
5+
| ^^ can only be used once per pattern
66

7-
error: aborting due to previous error
7+
error[E0308]: mismatched types
8+
--> $DIR/pat-tuple-3.rs:3:9
9+
|
10+
LL | (.., pat, ..) => {}
11+
| ^^^^^^^^^^^^^ expected integer, found tuple
12+
|
13+
= note: expected type `{integer}`
14+
found type `(_,)`
15+
16+
error: aborting due to 2 previous errors
817

18+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)