Skip to content

Commit 8902936

Browse files
committed
Auto merge of #21521 - defuz:interval-with-path, r=pnkfelix
Fixing #21475. Right now this code can not be parsed: ```rust use m::{START, END}; fn main() { match 42u32 { m::START...m::END => {}, // error: expected one of `::`, `=>`, or `|`, found `...` _ => {}, } } mod m { pub const START: u32 = 4; pub const END: u32 = 14; } ``` I fixed the parser and added test for this case, but now there are still problems with mixing literals and paths in interval: ```rust match 42u32 { 0u32...m::END => {}, // mismatched types in range [E0031] m::START...59u32 => {}, // mismatched types in range [E0031] _ => {}, } } ``` I'll try fix this problem and need review.
2 parents 8a69110 + 6c35bf4 commit 8902936

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/libsyntax/parse/parser.rs

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

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

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
0u32...m::END => {},
17+
m::START...59u32 => {},
18+
_ => {},
19+
}
20+
}
21+
22+
mod m {
23+
pub const START: u32 = 4;
24+
pub const END: u32 = 14;
25+
}

0 commit comments

Comments
 (0)