about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-02-28 18:36:00 +0000
committerbors <bors@rust-lang.org>2015-02-28 18:36:00 +0000
commit890293655251c372ea99694c0c9f0795e2663286 (patch)
treedcd899519544caface9bf0d5d6b07c762c89bc50 /src/libsyntax/parse
parent8a69110c3b1122596ddc8999bb2403a5777bb8ed (diff)
parent6c35bf4fbc4f795eb18bbb0c750ed478a47fff4e (diff)
downloadrust-890293655251c372ea99694c0c9f0795e2663286.tar.gz
rust-890293655251c372ea99694c0c9f0795e2663286.zip
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.


Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 9de7b0ede78..c1acee57cf8 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -3538,6 +3538,19 @@ impl<'a> Parser<'a> {
                         self.bump();
                         pat = PatStruct(enum_path, fields, etc);
                     }
+                    token::DotDotDot => {
+                        let hi = self.last_span.hi;
+                        let start = self.mk_expr(lo, hi, ExprPath(None, enum_path));
+                        self.eat(&token::DotDotDot);
+                        let end = if self.token.is_ident() || self.token.is_path() {
+                            let path = self.parse_path(LifetimeAndTypesWithColons);
+                            let hi = self.span.hi;
+                            self.mk_expr(lo, hi, ExprPath(None, path))
+                        } else {
+                            self.parse_literal_maybe_minus()
+                        };
+                        pat = PatRange(start, end);
+                    }
                     _ => {
                         let mut args: Vec<P<Pat>> = Vec::new();
                         match self.token {