Skip to content

Commit cb918e1

Browse files
committed
Allow non-literal static range pattern for match arms
Fix unintended error problem of: static s: int = 1; static e: int = 42; fn main() { match 7 { s..e => (), ^~ error: expected `=>` but found `..` _ => (), } }
1 parent d74ac9e commit cb918e1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,7 +2383,13 @@ pub impl Parser {
23832383
can_be_enum_or_struct = false
23842384
}
23852385

2386-
if is_plain_ident(&*self.token) && !can_be_enum_or_struct {
2386+
if self.look_ahead(1) == token::DOTDOT {
2387+
let start = self.parse_expr_res(RESTRICT_NO_BAR_OP);
2388+
self.eat(&token::DOTDOT);
2389+
let end = self.parse_expr_res(RESTRICT_NO_BAR_OP);
2390+
pat = pat_range(start, end);
2391+
}
2392+
else if is_plain_ident(&*self.token) && !can_be_enum_or_struct {
23872393
let name = self.parse_path_without_tps();
23882394
let sub;
23892395
if self.eat(&token::AT) {
@@ -2392,7 +2398,7 @@ pub impl Parser {
23922398
} else {
23932399
// or just foo
23942400
sub = None;
2395-
};
2401+
}
23962402
pat = pat_ident(binding_mode, name, sub);
23972403
} else {
23982404
// parse an enum pat
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
static s: int = 1;
2+
static e: int = 42;
3+
4+
fn main() {
5+
match 7 {
6+
s..e => (),
7+
_ => (),
8+
}
9+
}
10+

0 commit comments

Comments
 (0)