diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2016-03-26 21:37:53 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2016-04-07 15:37:07 +0200 |
| commit | c0167543dbaaf0dff10b8296955b7aa824e6973d (patch) | |
| tree | c2d8c3aa1b6846dd8fe20f7f1fbfdd22e86d1f26 | |
| parent | 39d612b7ac08aa97fb78b1791c47584cbdc46d8f (diff) | |
| download | rust-c0167543dbaaf0dff10b8296955b7aa824e6973d.tar.gz rust-c0167543dbaaf0dff10b8296955b7aa824e6973d.zip | |
syntax: Stop the bump loop for trait items at } and EOF.
backport of 221d0fbad0b201ef9264d3c9a30cd8c143ed51b2 to beta with hand-resolution of conflicts and reverting to `try!` syntax.
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 26 | ||||
| -rw-r--r-- | src/test/parse-fail/issue-10636-2.rs | 3 | ||||
| -rw-r--r-- | src/test/parse-fail/issue-32446.rs | 16 | ||||
| -rw-r--r-- | src/test/parse-fail/pat-lt-bracket-6.rs | 2 | ||||
| -rw-r--r-- | src/test/parse-fail/pat-lt-bracket-7.rs | 2 |
5 files changed, 36 insertions, 13 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ccb9654aed4..64dd60feb4e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -941,7 +941,9 @@ impl<'a> Parser<'a> { { try!(self.expect(bra)); let result = self.parse_seq_to_before_end(ket, sep, f); - self.bump(); + if self.token == *ket { + self.bump(); + } Ok(result) } @@ -1276,15 +1278,21 @@ impl<'a> Parser<'a> { Ok(cua) => cua, Err(e) => { loop { - p.bump(); - if p.token == token::Semi { - p.bump(); - break; - } + match p.token { + token::Eof => break, + + token::CloseDelim(token::Brace) | + token::Semi => { + p.bump(); + break; + } + + token::OpenDelim(token::Brace) => { + try!(p.parse_token_tree()); + break; + } - if p.token == token::OpenDelim(token::DelimToken::Brace) { - try!(p.parse_token_tree()); - break; + _ => p.bump() } } diff --git a/src/test/parse-fail/issue-10636-2.rs b/src/test/parse-fail/issue-10636-2.rs index 41a3b06e655..1361f3d31ac 100644 --- a/src/test/parse-fail/issue-10636-2.rs +++ b/src/test/parse-fail/issue-10636-2.rs @@ -17,5 +17,4 @@ pub fn trace_option(option: Option<isize>) { //~ HELP did you mean to close this option.map(|some| 42; //~ NOTE: unclosed delimiter //~^ ERROR: expected one of } //~ ERROR: incorrect close delimiter -//~^ ERROR: expected one of -//~ ERROR: this file contains an un-closed delimiter +//~^ ERROR: unexpected token diff --git a/src/test/parse-fail/issue-32446.rs b/src/test/parse-fail/issue-32446.rs new file mode 100644 index 00000000000..90b9a4aae8b --- /dev/null +++ b/src/test/parse-fail/issue-32446.rs @@ -0,0 +1,16 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -Z parse-only + +fn main() {} + +// This used to end up in an infite loop trying to bump past EOF. +trait T { ... } //~ ERROR diff --git a/src/test/parse-fail/pat-lt-bracket-6.rs b/src/test/parse-fail/pat-lt-bracket-6.rs index bc27aedb627..5ed8f6dee8c 100644 --- a/src/test/parse-fail/pat-lt-bracket-6.rs +++ b/src/test/parse-fail/pat-lt-bracket-6.rs @@ -10,5 +10,5 @@ fn main() { let Test(&desc[..]) = x; //~ error: expected one of `,` or `@`, found `[` - //~^ ERROR expected one of `:`, `;`, or `=`, found `..` + //~^ ERROR expected one of `:`, `;`, `=`, or `@`, found `[` } diff --git a/src/test/parse-fail/pat-lt-bracket-7.rs b/src/test/parse-fail/pat-lt-bracket-7.rs index 3e9478da44d..00681e61497 100644 --- a/src/test/parse-fail/pat-lt-bracket-7.rs +++ b/src/test/parse-fail/pat-lt-bracket-7.rs @@ -10,5 +10,5 @@ fn main() { for thing(x[]) in foo {} //~ error: expected one of `,` or `@`, found `[` - //~^ ERROR: expected `in`, found `]` + //~^ ERROR expected one of `@` or `in`, found `[` } |
