Skip to content

Commit 221d0fb

Browse files
committed
syntax: Stop the bump loop for trait items at } and EOF.
1 parent 6abab49 commit 221d0fb

File tree

6 files changed

+38
-14
lines changed

6 files changed

+38
-14
lines changed

src/libsyntax/parse/parser.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,9 @@ impl<'a> Parser<'a> {
957957
{
958958
self.expect(bra)?;
959959
let result = self.parse_seq_to_before_end(ket, sep, f);
960-
self.bump();
960+
if self.token == *ket {
961+
self.bump();
962+
}
961963
Ok(result)
962964
}
963965

@@ -1292,15 +1294,21 @@ impl<'a> Parser<'a> {
12921294
Ok(cua) => cua,
12931295
Err(e) => {
12941296
loop {
1295-
p.bump();
1296-
if p.token == token::Semi {
1297-
p.bump();
1298-
break;
1299-
}
1297+
match p.token {
1298+
token::Eof => break,
1299+
1300+
token::CloseDelim(token::Brace) |
1301+
token::Semi => {
1302+
p.bump();
1303+
break;
1304+
}
1305+
1306+
token::OpenDelim(token::Brace) => {
1307+
p.parse_token_tree()?;
1308+
break;
1309+
}
13001310

1301-
if p.token == token::OpenDelim(token::DelimToken::Brace) {
1302-
p.parse_token_tree()?;
1303-
break;
1311+
_ => p.bump()
13041312
}
13051313
}
13061314

src/test/compile-fail/issue-10636-2.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@
1414
pub fn trace_option(option: Option<isize>) {
1515
option.map(|some| 42; //~ NOTE: unclosed delimiter
1616
//~^ ERROR: expected one of
17-
//~^^ ERROR: mismatched types
1817
} //~ ERROR: incorrect close delimiter
19-
//~^ ERROR: expected one of
18+
//~^ ERROR: unexpected token

src/test/compile-fail/token-error-correct-3.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ pub mod raw {
2121
if !is_directory(path.as_ref()) { //~ ERROR: unresolved name `is_directory`
2222
callback(path.as_ref(); //~ NOTE: unclosed delimiter
2323
//~^ ERROR: expected one of
24-
fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: expected one of
24+
fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types
2525
} else { //~ ERROR: incorrect close delimiter: `}`
26+
//~^ ERROR: expected one of
2627
Ok(false);
2728
}
2829

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)