Skip to content

Commit c016754

Browse files
eddybpnkfelix
authored andcommittedApr 7, 2016
syntax: Stop the bump loop for trait items at } and EOF.
backport of 221d0fb to beta with hand-resolution of conflicts and reverting to `try!` syntax.
1 parent 39d612b commit c016754

File tree

5 files changed

+36
-13
lines changed

5 files changed

+36
-13
lines changed
 

‎src/libsyntax/parse/parser.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,9 @@ impl<'a> Parser<'a> {
941941
{
942942
try!(self.expect(bra));
943943
let result = self.parse_seq_to_before_end(ket, sep, f);
944-
self.bump();
944+
if self.token == *ket {
945+
self.bump();
946+
}
945947
Ok(result)
946948
}
947949

@@ -1276,15 +1278,21 @@ impl<'a> Parser<'a> {
12761278
Ok(cua) => cua,
12771279
Err(e) => {
12781280
loop {
1279-
p.bump();
1280-
if p.token == token::Semi {
1281-
p.bump();
1282-
break;
1283-
}
1281+
match p.token {
1282+
token::Eof => break,
1283+
1284+
token::CloseDelim(token::Brace) |
1285+
token::Semi => {
1286+
p.bump();
1287+
break;
1288+
}
1289+
1290+
token::OpenDelim(token::Brace) => {
1291+
try!(p.parse_token_tree());
1292+
break;
1293+
}
12841294

1285-
if p.token == token::OpenDelim(token::DelimToken::Brace) {
1286-
try!(p.parse_token_tree());
1287-
break;
1295+
_ => p.bump()
12881296
}
12891297
}
12901298

‎src/test/parse-fail/issue-10636-2.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ pub fn trace_option(option: Option<isize>) { //~ HELP did you mean to close this
1717
option.map(|some| 42; //~ NOTE: unclosed delimiter
1818
//~^ ERROR: expected one of
1919
} //~ ERROR: incorrect close delimiter
20-
//~^ ERROR: expected one of
21-
//~ ERROR: this file contains an un-closed delimiter
20+
//~^ ERROR: unexpected token

‎src/test/parse-fail/issue-32446.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 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+
// compile-flags: -Z parse-only
12+
13+
fn main() {}
14+
15+
// This used to end up in an infite loop trying to bump past EOF.
16+
trait T { ... } //~ ERROR

‎src/test/parse-fail/pat-lt-bracket-6.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
fn main() {
1212
let Test(&desc[..]) = x; //~ error: expected one of `,` or `@`, found `[`
13-
//~^ ERROR expected one of `:`, `;`, or `=`, found `..`
13+
//~^ ERROR expected one of `:`, `;`, `=`, or `@`, found `[`
1414
}

‎src/test/parse-fail/pat-lt-bracket-7.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
fn main() {
1212
for thing(x[]) in foo {} //~ error: expected one of `,` or `@`, found `[`
13-
//~^ ERROR: expected `in`, found `]`
13+
//~^ ERROR expected one of `@` or `in`, found `[`
1414
}

0 commit comments

Comments
 (0)
Please sign in to comment.