Skip to content

Commit 52fa187

Browse files
committed
FIX #21475: Interval match patterns won't parse namespace specifiers correctly
1 parent 48aeaba commit 52fa187

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,6 +3539,19 @@ impl<'a> Parser<'a> {
35393539
self.bump();
35403540
pat = PatStruct(enum_path, fields, etc);
35413541
}
3542+
token::DotDotDot => {
3543+
let hi = self.last_span.hi;
3544+
let start = self.mk_expr(lo, hi, ExprPath(enum_path));
3545+
self.eat(&token::DotDotDot);
3546+
let end = if self.token.is_ident() || self.token.is_path() {
3547+
let path = self.parse_path(LifetimeAndTypesWithColons);
3548+
let hi = self.span.hi;
3549+
self.mk_expr(lo, hi, ExprPath(path))
3550+
} else {
3551+
self.parse_literal_maybe_minus()
3552+
};
3553+
pat = PatRange(start, end);
3554+
}
35423555
_ => {
35433556
let mut args: Vec<P<Pat>> = Vec::new();
35443557
match self.token {

src/test/run-pass/issue-21475.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use m::{START, END};
12+
13+
fn main() {
14+
match 42u32 {
15+
m::START...m::END => {},
16+
// FIXME: Should also work (now: mismatched types in range [E0031])
17+
// 0u32...m::END => {},
18+
// m::START...59u32 => {},
19+
_ => {},
20+
}
21+
}
22+
23+
mod m {
24+
pub const START: u32 = 4;
25+
pub const END: u32 = 14;
26+
}

0 commit comments

Comments
 (0)