Skip to content

Commit 108bca5

Browse files
committed
Make the parser’s ‘expected <foo>, found <bar>’ errors more accurate
As an example of what this changes, the following code: let x: [int ..4]; Currently spits out ‘expected `]`, found `..`’. However, a comma would also be valid there, as would a number of other tokens. This change adjusts the parser to produce more accurate errors, so that that example now produces ‘expected one of `(`, `+`, `,`, `::`, or `]`, found `..`’.
1 parent 3a325c6 commit 108bca5

29 files changed

+155
-95
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 115 additions & 68 deletions
Large diffs are not rendered by default.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 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+
fn main() {
12+
let x: [int ..3]; //~ ERROR expected one of `(`, `+`, `,`, `::`, or `]`, found `..`
13+
}

src/test/compile-fail/column-offset-1-based.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
# //~ ERROR 11:1: 11:2 error: expected `[`, found `<eof>`
11+
# //~ ERROR 11:1: 11:2 error: expected one of `!` or `[`, found `<eof>`

src/test/compile-fail/empty-impl-semicolon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
impl Foo; //~ ERROR expected `{`, found `;`
11+
impl Foo; //~ ERROR expected one of `(`, `+`, `::`, or `{`, found `;`

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

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

11-
// error-pattern:expected `[`, found `vec`
11+
// error-pattern:expected one of `!` or `[`, found `vec`
1212
mod blade_runner {
1313
#vec[doc(
1414
brief = "Blade Runner is probably the best movie ever",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212

1313
fn main() {
1414
let t = (42i, 42i);
15-
t.0::<int>; //~ ERROR expected one of `;`, `}`, found `::`
15+
t.0::<int>; //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `::`
1616
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
fn main()
1414
{
1515
let x = 3
16-
} //~ ERROR: expected `;`, found `}`
16+
} //~ ERROR: expected one of `.`, `;`, or an operator, found `}`

src/test/compile-fail/match-vec-invalid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
fn main() {
1212
let a = Vec::new();
1313
match a {
14-
[1, tail.., tail..] => {}, //~ ERROR: expected `,`, found `..`
14+
[1, tail.., tail..] => {}, //~ ERROR: expected one of `!`, `,`, or `@`, found `..`
1515
_ => ()
1616
}
1717
}

src/test/compile-fail/multitrait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct S {
1212
y: int
1313
}
1414

15-
impl Cmp, ToString for S { //~ ERROR: expected `{`, found `,`
15+
impl Cmp, ToString for S { //~ ERROR: expected one of `(`, `+`, `::`, or `{`, found `,`
1616
fn eq(&&other: S) { false }
1717
fn to_string(&self) -> String { "hi".to_string() }
1818
}

src/test/compile-fail/mut-patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212

1313
pub fn main() {
1414
struct Foo { x: int }
15-
let mut Foo { x: x } = Foo { x: 3 }; //~ ERROR: expected `;`, found `{`
15+
let mut Foo { x: x } = Foo { x: 3 }; //~ ERROR: expected one of `:`, `;`, `=`, or `@`, found `{`
1616
}

0 commit comments

Comments
 (0)