Improve wording and spans for unexpected token
* Point at where the token was expected instead of the last token successfuly parsed. * Only show `unexpected token` if the next char and the unexpected token don't have the same span. * Change some cfail and pfail tests to ui test. * Don't show all possible tokens in span label if they are more than 6.
This commit is contained in:
parent
03eca71381
commit
78ae8feebb
13 changed files with 102 additions and 15 deletions
|
|
@ -14,15 +14,13 @@ error: expected one of `,`, `.`, `?`, or an operator, found `;`
|
|||
--> $DIR/token-error-correct-3.rs:23:35
|
||||
|
|
||||
23 | callback(path.as_ref(); //~ NOTE: unclosed delimiter
|
||||
| -^ unexpected token
|
||||
| |
|
||||
| expected one of `,`, `.`, `?`, or an operator after this
|
||||
| ^ expected one of `,`, `.`, `?`, or an operator here
|
||||
|
||||
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
|
||||
--> $DIR/token-error-correct-3.rs:29:9
|
||||
|
|
||||
25 | fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types
|
||||
| - expected one of `.`, `;`, `?`, `}`, or an operator after this
|
||||
| - expected one of `.`, `;`, `?`, `}`, or an operator here
|
||||
...
|
||||
29 | } else { //~ ERROR: incorrect close delimiter: `}`
|
||||
| ^ unexpected token
|
||||
|
|
|
|||
|
|
@ -32,9 +32,7 @@ error: expected one of `)`, `,`, `.`, `<`, `?`, `break`, `continue`, `false`, `f
|
|||
--> $DIR/token-error-correct.rs:14:13
|
||||
|
|
||||
14 | foo(bar(;
|
||||
| -^ unexpected token
|
||||
| |
|
||||
| expected one of `)`, `,`, `.`, `<`, `?`, `break`, `continue`, `false`, `for`, `if`, `loop`, `match`, `move`, `return`, `true`, `unsafe`, `while`, or an operator after this
|
||||
| ^ expected one of 18 possible tokens here
|
||||
|
||||
error: expected expression, found `)`
|
||||
--> $DIR/token-error-correct.rs:23:1
|
||||
|
|
|
|||
17
src/test/ui/token/bounds-obj-parens.rs
Normal file
17
src/test/ui/token/bounds-obj-parens.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// compile-flags: -Z parse-only
|
||||
|
||||
type A = Box<(Fn(D::Error) -> E) + 'static + Send + Sync>; // OK (but see #39318)
|
||||
|
||||
FAIL
|
||||
//~^ ERROR
|
||||
//~| ERROR
|
||||
7
src/test/ui/token/bounds-obj-parens.stderr
Normal file
7
src/test/ui/token/bounds-obj-parens.stderr
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
error: expected one of `!` or `::`, found `<eof>`
|
||||
--> $DIR/bounds-obj-parens.rs:15:1
|
||||
|
|
||||
15 | FAIL
|
||||
| ^^^^ expected one of `!` or `::` here
|
||||
|
||||
error: aborting due to previous error
|
||||
20
src/test/ui/token/issue-10636-2.rs
Normal file
20
src/test/ui/token/issue-10636-2.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2013-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.
|
||||
|
||||
// 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.
|
||||
|
||||
pub fn trace_option(option: Option<isize>) {
|
||||
option.map(|some| 42; //~ NOTE: unclosed delimiter
|
||||
//~^ ERROR: expected one of
|
||||
//~| NOTE: expected one of
|
||||
//~| NOTE: unexpected token
|
||||
} //~ ERROR: incorrect close delimiter
|
||||
//~^ ERROR: expected expression, found `)`
|
||||
27
src/test/ui/token/issue-10636-2.stderr
Normal file
27
src/test/ui/token/issue-10636-2.stderr
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
error: incorrect close delimiter: `}`
|
||||
--> $DIR/issue-10636-2.rs:19:1
|
||||
|
|
||||
19 | } //~ ERROR: incorrect close delimiter
|
||||
| ^
|
||||
|
|
||||
note: unclosed delimiter
|
||||
--> $DIR/issue-10636-2.rs:15:15
|
||||
|
|
||||
15 | option.map(|some| 42; //~ NOTE: unclosed delimiter
|
||||
| ^
|
||||
|
||||
error: expected one of `,`, `.`, `?`, or an operator, found `;`
|
||||
--> $DIR/issue-10636-2.rs:15:25
|
||||
|
|
||||
15 | option.map(|some| 42; //~ NOTE: unclosed delimiter
|
||||
| ^ expected one of `,`, `.`, `?`, or an operator here
|
||||
|
||||
error: expected expression, found `)`
|
||||
--> $DIR/issue-10636-2.rs:19:1
|
||||
|
|
||||
19 | } //~ ERROR: incorrect close delimiter
|
||||
| ^
|
||||
|
||||
error: main function not found
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
40
src/test/ui/token/macro-incomplete-parse.rs
Normal file
40
src/test/ui/token/macro-incomplete-parse.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright 2013 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.
|
||||
|
||||
// compile-flags: -Z continue-parse-after-error
|
||||
|
||||
macro_rules! ignored_item {
|
||||
() => {
|
||||
fn foo() {}
|
||||
fn bar() {}
|
||||
, //~ ERROR macro expansion ignores token `,`
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! ignored_expr {
|
||||
() => ( 1, //~ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `,`
|
||||
//~^ NOTE expected one of `.`, `;`, `?`, `}`, or an operator here
|
||||
//~| NOTE unexpected token
|
||||
2 )
|
||||
}
|
||||
|
||||
macro_rules! ignored_pat {
|
||||
() => ( 1, 2 ) //~ ERROR macro expansion ignores token `,`
|
||||
}
|
||||
|
||||
ignored_item!(); //~ NOTE caused by the macro expansion here
|
||||
|
||||
fn main() {
|
||||
ignored_expr!();
|
||||
match 1 {
|
||||
ignored_pat!() => (), //~ NOTE caused by the macro expansion here
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
31
src/test/ui/token/macro-incomplete-parse.stderr
Normal file
31
src/test/ui/token/macro-incomplete-parse.stderr
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
error: macro expansion ignores token `,` and any following
|
||||
--> $DIR/macro-incomplete-parse.rs:17:9
|
||||
|
|
||||
17 | , //~ ERROR macro expansion ignores token `,`
|
||||
| ^
|
||||
|
|
||||
note: caused by the macro expansion here; the usage of `ignored_item!` is likely invalid in item context
|
||||
--> $DIR/macro-incomplete-parse.rs:32:1
|
||||
|
|
||||
32 | ignored_item!(); //~ NOTE caused by the macro expansion here
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `,`
|
||||
--> $DIR/macro-incomplete-parse.rs:22:14
|
||||
|
|
||||
22 | () => ( 1, //~ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `,`
|
||||
| ^ expected one of `.`, `;`, `?`, `}`, or an operator here
|
||||
|
||||
error: macro expansion ignores token `,` and any following
|
||||
--> $DIR/macro-incomplete-parse.rs:29:14
|
||||
|
|
||||
29 | () => ( 1, 2 ) //~ ERROR macro expansion ignores token `,`
|
||||
| ^
|
||||
|
|
||||
note: caused by the macro expansion here; the usage of `ignored_pat!` is likely invalid in pattern context
|
||||
--> $DIR/macro-incomplete-parse.rs:37:9
|
||||
|
|
||||
37 | ignored_pat!() => (), //~ NOTE caused by the macro expansion here
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
21
src/test/ui/token/trailing-plus-in-bounds.rs
Normal file
21
src/test/ui/token/trailing-plus-in-bounds.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2012 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.
|
||||
|
||||
// compile-flags: -Z parse-only -Z continue-parse-after-error
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
fn main() {
|
||||
let x: Box<Debug+> = box 3 as Box<Debug+>; // Trailing `+` is OK
|
||||
}
|
||||
|
||||
FAIL
|
||||
//~^ ERROR
|
||||
//~| ERROR
|
||||
7
src/test/ui/token/trailing-plus-in-bounds.stderr
Normal file
7
src/test/ui/token/trailing-plus-in-bounds.stderr
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
error: expected one of `!` or `::`, found `<eof>`
|
||||
--> ../../src/test/ui/token/trailing-plus-in-bounds.rs:19:1
|
||||
|
|
||||
19 | FAIL
|
||||
| ^^^^ expected one of `!` or `::` here
|
||||
|
||||
error: aborting due to previous error
|
||||
Loading…
Add table
Add a link
Reference in a new issue