Skip to content
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

Make the parser’s ‘expected <foo>, found <bar>’ errors more accurate #19494

Merged
merged 1 commit into from
Dec 5, 2014
Merged
Show file tree
Hide file tree
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
183 changes: 115 additions & 68 deletions src/libsyntax/parse/parser.rs

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/test/compile-fail/better-expected.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2014 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.

fn main() {
let x: [int ..3]; //~ ERROR expected one of `(`, `+`, `,`, `::`, or `]`, found `..`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/column-offset-1-based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

# //~ ERROR 11:1: 11:2 error: expected `[`, found `<eof>`
# //~ ERROR 11:1: 11:2 error: expected one of `!` or `[`, found `<eof>`
2 changes: 1 addition & 1 deletion src/test/compile-fail/empty-impl-semicolon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

impl Foo; //~ ERROR expected `{`, found `;`
impl Foo; //~ ERROR expected one of `(`, `+`, `::`, or `{`, found `;`
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-1655.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:expected `[`, found `vec`
// error-pattern:expected one of `!` or `[`, found `vec`
mod blade_runner {
#vec[doc(
brief = "Blade Runner is probably the best movie ever",
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-19096.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

fn main() {
let t = (42i, 42i);
t.0::<int>; //~ ERROR expected one of `;`, `}`, found `::`
t.0::<int>; //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `::`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-3036.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
fn main()
{
let x = 3
} //~ ERROR: expected `;`, found `}`
} //~ ERROR: expected one of `.`, `;`, or an operator, found `}`
2 changes: 1 addition & 1 deletion src/test/compile-fail/match-vec-invalid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
fn main() {
let a = Vec::new();
match a {
[1, tail.., tail..] => {}, //~ ERROR: expected `,`, found `..`
[1, tail.., tail..] => {}, //~ ERROR: expected one of `!`, `,`, or `@`, found `..`
_ => ()
}
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/multitrait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct S {
y: int
}

impl Cmp, ToString for S { //~ ERROR: expected `{`, found `,`
impl Cmp, ToString for S { //~ ERROR: expected one of `(`, `+`, `::`, or `{`, found `,`
fn eq(&&other: S) { false }
fn to_string(&self) -> String { "hi".to_string() }
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/mut-patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

pub fn main() {
struct Foo { x: int }
let mut Foo { x: x } = Foo { x: 3 }; //~ ERROR: expected `;`, found `{`
let mut Foo { x: x } = Foo { x: 3 }; //~ ERROR: expected one of `:`, `;`, `=`, or `@`, found `{`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/omitted-arg-in-item-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn foo(x) { //~ ERROR expected `:`, found `)`
fn foo(x) { //~ ERROR expected one of `!`, `:`, or `@`, found `)`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/pat-range-bad-dots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

pub fn main() {
match 22i {
0 .. 3 => {} //~ ERROR expected `=>`, found `..`
0 .. 3 => {} //~ ERROR expected one of `...`, `=>`, or `|`, found `..`
_ => {}
}
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/raw-str-unbalanced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

static s: &'static str =
r#"
"## //~ ERROR expected `;`, found `#`
"## //~ ERROR expected one of `.`, `;`, or an operator, found `#`
;
2 changes: 1 addition & 1 deletion src/test/compile-fail/removed-syntax-closure-lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

type closure = Box<lt/fn()>; //~ ERROR expected `,`, found `/`
type closure = Box<lt/fn()>; //~ ERROR expected one of `(`, `+`, `,`, `::`, or `>`, found `/`
2 changes: 1 addition & 1 deletion src/test/compile-fail/removed-syntax-enum-newtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

enum e = int; //~ ERROR expected `{`, found `=`
enum e = int; //~ ERROR expected one of `<` or `{`, found `=`
2 changes: 1 addition & 1 deletion src/test/compile-fail/removed-syntax-fixed-vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

type v = [int * 3]; //~ ERROR expected `]`, found `*`
type v = [int * 3]; //~ ERROR expected one of `(`, `+`, `,`, `::`, or `]`, found `*`
2 changes: 1 addition & 1 deletion src/test/compile-fail/removed-syntax-larrow-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
fn removed_moves() {
let mut x = 0;
let y <- x;
//~^ ERROR expected `;`, found `<-`
//~^ ERROR expected one of `!`, `:`, `;`, `=`, or `@`, found `<-`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/removed-syntax-larrow-move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ fn removed_moves() {
let mut x = 0;
let y = 0;
y <- x;
//~^ ERROR expected one of `;`, `}`, found `<-`
//~^ ERROR expected one of `!`, `.`, `::`, `;`, `{`, `}`, or an operator, found `<-`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/removed-syntax-mut-vec-expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
fn f() {
let v = [mut 1, 2, 3, 4];
//~^ ERROR expected identifier, found keyword `mut`
//~^^ ERROR expected `]`, found `1`
//~^^ ERROR expected one of `!`, `,`, `.`, `::`, `]`, `{`, or an operator, found `1`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/removed-syntax-mut-vec-ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

type v = [mut int];
//~^ ERROR expected identifier, found keyword `mut`
//~^^ ERROR expected `]`, found `int`
//~^^ ERROR expected one of `(`, `+`, `,`, `::`, or `]`, found `int`
2 changes: 1 addition & 1 deletion src/test/compile-fail/removed-syntax-ptr-lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

type bptr = &lifetime/int; //~ ERROR expected `;`, found `/`
type bptr = &lifetime/int; //~ ERROR expected one of `(`, `+`, `::`, or `;`, found `/`
2 changes: 1 addition & 1 deletion src/test/compile-fail/removed-syntax-record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

type t = { f: () }; //~ ERROR expected type, found token OpenDelim(Brace)
type t = { f: () }; //~ ERROR expected type, found `{`
2 changes: 1 addition & 1 deletion src/test/compile-fail/removed-syntax-uniq-mut-expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
fn f() {
let a_box = box mut 42;
//~^ ERROR expected identifier, found keyword `mut`
//~^^ ERROR expected `;`, found `42`
//~^^ ERROR expected one of `!`, `.`, `::`, `;`, `{`, or an operator, found `42`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/removed-syntax-uniq-mut-ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

type mut_box = Box<mut int>;
//~^ ERROR expected identifier, found keyword `mut`
//~^^ ERROR expected `,`, found `int`
//~^^ ERROR expected one of `(`, `+`, `,`, `::`, or `>`, found `int`
2 changes: 1 addition & 1 deletion src/test/compile-fail/removed-syntax-with-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ fn removed_with() {

let a = S { foo: (), bar: () };
let b = S { foo: () with a };
//~^ ERROR expected one of `,`, `}`, found `with`
//~^ ERROR expected one of `,`, `.`, `}`, or an operator, found `with`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/struct-literal-in-for.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Foo {

fn main() {
for x in Foo {
x: 3 //~ ERROR expected one of `;`, `}`
x: 3 //~ ERROR expected one of `!`, `.`, `::`, `;`, `{`, `}`, or an operator, found `:`
}.hi() {
println!("yo");
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/struct-literal-in-if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Foo {

fn main() {
if Foo {
x: 3 //~ ERROR expected one of `;`, `}`
x: 3 //~ ERROR expected one of `!`, `.`, `::`, `;`, `{`, `}`, or an operator, found `:`
}.hi() {
println!("yo");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Foo {

fn main() {
match Foo {
x: 3 //~ ERROR expected `=>`
x: 3 //~ ERROR expected one of `!`, `=>`, `@`, or `|`, found `:`
} {
Foo {
x: x
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/struct-literal-in-while.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Foo {

fn main() {
while Foo {
x: 3 //~ ERROR expected one of `;`, `}`
x: 3 //~ ERROR expected one of `!`, `.`, `::`, `;`, `{`, `}`, or an operator, found `:`
}.hi() {
println!("yo");
}
Expand Down