Skip to content

Recover from missing brackets in the parser #31555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
376 changes: 269 additions & 107 deletions src/libsyntax/parse/parser.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/test/compile-fail/issue-30715.rs
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ macro_rules! parallel {
fn main() {
parallel! {
for i in 0..n {
x += i; //~ ERROR no rules expected the token `+=`
}
x += i; //~ ERROR expected `:`, found `+=`
} //~ ERROR unexpected end of macro invocation
}
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/macro-incomplete-parse.rs
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ macro_rules! ignored_item {

macro_rules! ignored_expr {
() => ( 1, //~ ERROR unexpected token: `,`
2 ) //~ ERROR macro expansion ignores token `2`
2 )
}

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

fn main() {
ignored_expr!(); //~ NOTE caused by the macro expansion here
ignored_expr!();
match 1 {
ignored_pat!() => (), //~ NOTE caused by the macro expansion here
_ => (),
22 changes: 22 additions & 0 deletions src/test/compile-fail/parser-recovery-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

// Test that we can recover from missing braces in the parser.

trait Foo {
fn bar() {
let x = foo(); //~ ERROR unresolved name `foo`

}

fn main() {
let x = y.; //~ ERROR unexpected token
//~^ ERROR unresolved name `y`
} //~ ERROR this file contains an un-closed delimiter
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// 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.
//
@@ -8,11 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

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

fn main() {}
fn main() {
let x = y.; //~ ERROR unexpected token
//~^ ERROR unresolved name `y`
}
2 changes: 2 additions & 0 deletions src/test/parse-fail/brace-after-qualified-path-in-match.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only

fn foo() {
match x {
<T as Trait>::Type{key: value} => (),
8 changes: 7 additions & 1 deletion src/test/parse-fail/issue-10636-2.rs
Original file line number Diff line number Diff line change
@@ -8,8 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// FIXME(31528) we emit a bunch of silly errors here due to continuing past the
// first one. This would be easy-ish to address by better recovery in tokenisation.

// compile-flags: -Z parse-only

pub fn trace_option(option: Option<isize>) {
pub fn trace_option(option: Option<isize>) { //~ HELP did you mean to close this delimiter?
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
1 change: 1 addition & 0 deletions src/test/parse-fail/issue-14303-path.rs
Original file line number Diff line number Diff line change
@@ -12,3 +12,4 @@

fn bar<'a, T>(x: mymodule::X<'a, T, 'b, 'c>) {}
//~^ ERROR lifetime parameters must be declared prior to type parameters
//~^^ ERROR unexpected token
4 changes: 2 additions & 2 deletions src/test/parse-fail/issue-2354.rs
Original file line number Diff line number Diff line change
@@ -12,8 +12,8 @@

fn foo() { //~ HELP did you mean to close this delimiter?
match Some(x) {
Some(y) { panic!(); }
None { panic!(); }
Some(y) => { panic!(); }
None => { panic!(); }
}

fn bar() {
2 changes: 2 additions & 0 deletions src/test/parse-fail/match-refactor-to-expr.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only

fn main() {
let foo =
match //~ NOTE did you mean to remove this `match` keyword?
2 changes: 2 additions & 0 deletions src/test/parse-fail/paren-after-qualified-path-in-match.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only

fn foo() {
match x {
<T as Trait>::Type(2) => (),
2 changes: 2 additions & 0 deletions src/test/parse-fail/pat-lt-bracket-4.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only

enum BtNode {
Node(u32,Box<BtNode>,Box<BtNode>),
Leaf(u32),
1 change: 1 addition & 0 deletions src/test/parse-fail/pat-lt-bracket-6.rs
Original file line number Diff line number Diff line change
@@ -10,4 +10,5 @@

fn main() {
let Test(&desc[..]) = x; //~ error: expected one of `,` or `@`, found `[`
//~^ ERROR expected one of `:`, `;`, or `=`, found `..`
}
3 changes: 2 additions & 1 deletion src/test/parse-fail/pat-lt-bracket-7.rs
Original file line number Diff line number Diff line change
@@ -9,5 +9,6 @@
// except according to those terms.

fn main() {
for thing(x[]) {} //~ error: expected one of `,` or `@`, found `[`
for thing(x[]) in foo {} //~ error: expected one of `,` or `@`, found `[`
//~^ ERROR: expected `in`, found `]`
}
2 changes: 1 addition & 1 deletion src/test/parse-fail/struct-literal-in-for.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ impl Foo {
fn main() {
for x in Foo {
x: 3 //~ ERROR expected type, found `3`
}.hi() {
}.hi() { //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `{`
println!("yo");
}
}
2 changes: 1 addition & 1 deletion src/test/parse-fail/struct-literal-in-if.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ impl Foo {
fn main() {
if Foo {
x: 3 //~ ERROR expected type, found `3`
}.hi() {
}.hi() { //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `{`
println!("yo");
}
}
Original file line number Diff line number Diff line change
@@ -20,6 +20,6 @@ fn main() {
} {
Foo {
x: x
} => {}
} => {} //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `=>`
}
}
2 changes: 1 addition & 1 deletion src/test/parse-fail/struct-literal-in-while.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ impl Foo {
fn main() {
while Foo {
x: 3 //~ ERROR expected type, found `3`
}.hi() {
}.hi() { //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `{`
println!("yo");
}
}