Skip to content

Allow non-literal static range pattern for match arms #6245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2383,7 +2383,13 @@ pub impl Parser {
can_be_enum_or_struct = false
}

if is_plain_ident(&*self.token) && !can_be_enum_or_struct {
if self.look_ahead(1) == token::DOTDOT {
let start = self.parse_expr_res(RESTRICT_NO_BAR_OP);
self.eat(&token::DOTDOT);
let end = self.parse_expr_res(RESTRICT_NO_BAR_OP);
pat = pat_range(start, end);
}
else if is_plain_ident(&*self.token) && !can_be_enum_or_struct {
let name = self.parse_path_without_tps();
let sub;
if self.eat(&token::AT) {
Expand All @@ -2392,7 +2398,7 @@ pub impl Parser {
} else {
// or just foo
sub = None;
};
}
pat = pat_ident(binding_mode, name, sub);
} else {
// parse an enum pat
Expand Down
10 changes: 10 additions & 0 deletions src/test/run-pass/match-range-static.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
static s: int = 1;
static e: int = 42;

fn main() {
match 7 {
s..e => (),
_ => (),
}
}