Skip to content

Commit f9543a9

Browse files
committed
Auto merge of #31555 - nrc:err-recover, r=pnkfelix
Recover from missing brackets in the parser
2 parents 2808df9 + 73a8513 commit f9543a9

18 files changed

+330
-125
lines changed

src/libsyntax/parse/parser.rs

+269-107
Large diffs are not rendered by default.

src/test/compile-fail/issue-30715.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ macro_rules! parallel {
2525
fn main() {
2626
parallel! {
2727
for i in 0..n {
28-
x += i; //~ ERROR no rules expected the token `+=`
29-
}
28+
x += i; //~ ERROR expected `:`, found `+=`
29+
} //~ ERROR unexpected end of macro invocation
3030
}
3131
}

src/test/compile-fail/macro-incomplete-parse.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ macro_rules! ignored_item {
1818

1919
macro_rules! ignored_expr {
2020
() => ( 1, //~ ERROR unexpected token: `,`
21-
2 ) //~ ERROR macro expansion ignores token `2`
21+
2 )
2222
}
2323

2424
macro_rules! ignored_pat {
@@ -28,7 +28,7 @@ macro_rules! ignored_pat {
2828
ignored_item!(); //~ NOTE caused by the macro expansion here
2929

3030
fn main() {
31-
ignored_expr!(); //~ NOTE caused by the macro expansion here
31+
ignored_expr!();
3232
match 1 {
3333
ignored_pat!() => (), //~ NOTE caused by the macro expansion here
3434
_ => (),
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
// Test that we can recover from missing braces in the parser.
12+
13+
trait Foo {
14+
fn bar() {
15+
let x = foo(); //~ ERROR unresolved name `foo`
16+
17+
}
18+
19+
fn main() {
20+
let x = y.; //~ ERROR unexpected token
21+
//~^ ERROR unresolved name `y`
22+
} //~ ERROR this file contains an un-closed delimiter
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -8,11 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags: -Z parse-only
11+
// Test that we can recover from mismatched braces in the parser.
1212

13-
extern {
14-
fn printf(...); //~ ERROR: variadic function must be declared with at least one named argument
15-
fn printf(..., foo: isize); //~ ERROR: `...` must be last in argument list for variadic function
13+
trait Foo {
14+
fn bar() {
15+
let x = foo(); //~ ERROR unresolved name `foo`
16+
) //~ ERROR incorrect close delimiter: `)`
1617
}
1718

18-
fn main() {}
19+
fn main() {
20+
let x = y.; //~ ERROR unexpected token
21+
//~^ ERROR unresolved name `y`
22+
}

src/test/parse-fail/brace-after-qualified-path-in-match.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z parse-only
12+
1113
fn foo() {
1214
match x {
1315
<T as Trait>::Type{key: value} => (),

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// FIXME(31528) we emit a bunch of silly errors here due to continuing past the
12+
// first one. This would be easy-ish to address by better recovery in tokenisation.
13+
1114
// compile-flags: -Z parse-only
1215

13-
pub fn trace_option(option: Option<isize>) {
16+
pub fn trace_option(option: Option<isize>) { //~ HELP did you mean to close this delimiter?
1417
option.map(|some| 42; //~ NOTE: unclosed delimiter
18+
//~^ ERROR: expected one of
1519
} //~ ERROR: incorrect close delimiter
20+
//~^ ERROR: expected one of
21+
//~ ERROR: this file contains an un-closed delimiter

src/test/parse-fail/issue-14303-path.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212

1313
fn bar<'a, T>(x: mymodule::X<'a, T, 'b, 'c>) {}
1414
//~^ ERROR lifetime parameters must be declared prior to type parameters
15+
//~^^ ERROR unexpected token

src/test/parse-fail/issue-2354.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
fn foo() { //~ HELP did you mean to close this delimiter?
1414
match Some(x) {
15-
Some(y) { panic!(); }
16-
None { panic!(); }
15+
Some(y) => { panic!(); }
16+
None => { panic!(); }
1717
}
1818

1919
fn bar() {

src/test/parse-fail/match-refactor-to-expr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z parse-only
12+
1113
fn main() {
1214
let foo =
1315
match //~ NOTE did you mean to remove this `match` keyword?

src/test/parse-fail/paren-after-qualified-path-in-match.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z parse-only
12+
1113
fn foo() {
1214
match x {
1315
<T as Trait>::Type(2) => (),

src/test/parse-fail/pat-lt-bracket-4.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z parse-only
12+
1113
enum BtNode {
1214
Node(u32,Box<BtNode>,Box<BtNode>),
1315
Leaf(u32),

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

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

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

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
// except according to those terms.
1010

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

src/test/parse-fail/struct-literal-in-for.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl Foo {
2323
fn main() {
2424
for x in Foo {
2525
x: 3 //~ ERROR expected type, found `3`
26-
}.hi() {
26+
}.hi() { //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `{`
2727
println!("yo");
2828
}
2929
}

src/test/parse-fail/struct-literal-in-if.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl Foo {
2323
fn main() {
2424
if Foo {
2525
x: 3 //~ ERROR expected type, found `3`
26-
}.hi() {
26+
}.hi() { //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `{`
2727
println!("yo");
2828
}
2929
}

src/test/parse-fail/struct-literal-in-match-discriminant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ fn main() {
2020
} {
2121
Foo {
2222
x: x
23-
} => {}
23+
} => {} //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `=>`
2424
}
2525
}

src/test/parse-fail/struct-literal-in-while.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl Foo {
2323
fn main() {
2424
while Foo {
2525
x: 3 //~ ERROR expected type, found `3`
26-
}.hi() {
26+
}.hi() { //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `{`
2727
println!("yo");
2828
}
2929
}

0 commit comments

Comments
 (0)