Tweak unexpected token wording

This commit is contained in:
Esteban Küber 2019-10-22 11:46:19 -07:00
parent d673d0ac84
commit 1b0836df6f
32 changed files with 42 additions and 41 deletions

View File

@ -274,23 +274,23 @@ impl<'a> Parser<'a> {
expected.sort_by_cached_key(|x| x.to_string());
expected.dedup();
let expect = tokens_to_string(&expected[..]);
let actual = self.this_token_to_string();
let actual = self.this_token_descr();
let (msg_exp, (label_sp, label_exp)) = if expected.len() > 1 {
let short_expect = if expected.len() > 6 {
format!("{} possible tokens", expected.len())
} else {
expect.clone()
};
(format!("expected one of {}, found `{}`", expect, actual),
(format!("expected one of {}, found {}", expect, actual),
(self.sess.source_map().next_point(self.prev_span),
format!("expected one of {} here", short_expect)))
} else if expected.is_empty() {
(format!("unexpected token: `{}`", actual),
(format!("unexpected token: {}", actual),
(self.prev_span, "unexpected token after this".to_string()))
} else {
(format!("expected {}, found `{}`", expect, actual),
(format!("expected {}, found {}", expect, actual),
(self.sess.source_map().next_point(self.prev_span),
format!("expected {} here", expect)))
format!("expected {}", expect)))
};
self.last_unexpected_token_span = Some(self.token.span);
let mut err = self.fatal(&msg_exp);

View File

@ -3,4 +3,4 @@
// compile-flags: --crate-type lib
pub async const fn x() {}
//~^ ERROR expected one of `fn` or `unsafe`, found `const`
//~^ ERROR expected one of `fn` or `unsafe`, found keyword `const`

View File

@ -1,4 +1,4 @@
error: expected one of `fn` or `unsafe`, found `const`
error: expected one of `fn` or `unsafe`, found keyword `const`
--> $DIR/no-async-const.rs:5:11
|
LL | pub async const fn x() {}

View File

@ -4,8 +4,8 @@ struct S;
impl S {
#[cfg(FALSE)]
unsafe async fn g() {} //~ ERROR expected one of `extern` or `fn`, found `async`
unsafe async fn g() {} //~ ERROR expected one of `extern` or `fn`, found keyword `async`
}
#[cfg(FALSE)]
unsafe async fn f() {} //~ ERROR expected one of `extern`, `fn`, or `{`, found `async`
unsafe async fn f() {} //~ ERROR expected one of `extern`, `fn`, or `{`, found keyword `async`

View File

@ -1,10 +1,10 @@
error: expected one of `extern` or `fn`, found `async`
error: expected one of `extern` or `fn`, found keyword `async`
--> $DIR/no-unsafe-async.rs:7:12
|
LL | unsafe async fn g() {}
| ^^^^^ expected one of `extern` or `fn` here
error: expected one of `extern`, `fn`, or `{`, found `async`
error: expected one of `extern`, `fn`, or `{`, found keyword `async`
--> $DIR/no-unsafe-async.rs:11:8
|
LL | unsafe async fn f() {}

View File

@ -16,5 +16,5 @@ pub fn main() {
return break as ();
}
return enum; //~ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `enum`
return enum; //~ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found keyword `enum`
}

View File

@ -1,4 +1,4 @@
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `enum`
error: expected one of `.`, `;`, `?`, `}`, or an operator, found keyword `enum`
--> $DIR/can-begin-expr-check.rs:19:12
|
LL | return enum;

View File

@ -2,7 +2,7 @@ error: expected `|`, found `}`
--> $DIR/issue-43196.rs:3:1
|
LL | |
| - expected `|` here
| - expected `|`
LL | }
| ^ unexpected token

View File

@ -2,7 +2,7 @@ error: expected `fn`, found `::`
--> $DIR/keyword-extern-as-identifier-type.rs:1:16
|
LL | type A = extern::foo::bar;
| ^^ expected `fn` here
| ^^ expected `fn`
error: aborting due to previous error

View File

@ -1,4 +1,4 @@
error: expected one of `crate`, `fn`, `pub`, `static`, or `type`, found `let`
error: expected one of `crate`, `fn`, `pub`, `static`, or `type`, found keyword `let`
--> $DIR/issue-54441.rs:3:9
|
LL | let

View File

@ -1,4 +1,4 @@
error: expected one of `async`, `const`, `extern`, `fn`, `type`, or `unsafe`, found `pub`
error: expected one of `async`, `const`, `extern`, `fn`, `type`, or `unsafe`, found keyword `pub`
--> $DIR/default.rs:22:13
|
LL | default pub fn foo<T: Default>() -> T { T::default() }

View File

@ -1,4 +1,4 @@
error: expected one of `(`, `fn`, `static`, or `type`, found `pub`
error: expected one of `(`, `fn`, `static`, or `type`, found keyword `pub`
--> $DIR/duplicate-visibility.rs:3:9
|
LL | pub pub fn foo();

View File

@ -1,4 +1,4 @@
// Verifies that the expected token errors for `extern crate` are
// raised
extern "C" mod foo; //~ERROR expected one of `fn` or `{`, found `mod`
extern "C" mod foo; //~ERROR expected one of `fn` or `{`, found keyword `mod`

View File

@ -1,4 +1,4 @@
error: expected one of `fn` or `{`, found `mod`
error: expected one of `fn` or `{`, found keyword `mod`
--> $DIR/extern-expected-fn-or-brace.rs:4:12
|
LL | extern "C" mod foo;

View File

@ -26,7 +26,7 @@ error: expected `impl`, found `FAIL`
--> $DIR/impl-parsing.rs:11:16
|
LL | default unsafe FAIL
| ^^^^ expected `impl` here
| ^^^^ expected `impl`
error: aborting due to 5 previous errors

View File

@ -2,7 +2,7 @@ error: expected `;`, found `::`
--> $DIR/import-from-path.rs:2:15
|
LL | use foo::{bar}::baz
| ^^ expected `;` here
| ^^ expected `;`
error: aborting due to previous error

View File

@ -1,8 +1,8 @@
error: expected `;`, found `as`
error: expected `;`, found keyword `as`
--> $DIR/import-from-rename.rs:3:16
|
LL | use foo::{bar} as baz;
| ^^ expected `;` here
| ^^ expected `;`
error: aborting due to previous error

View File

@ -2,7 +2,7 @@ error: expected `;`, found `::`
--> $DIR/import-glob-path.rs:2:11
|
LL | use foo::*::bar
| ^^ expected `;` here
| ^^ expected `;`
error: aborting due to previous error

View File

@ -1,8 +1,8 @@
error: expected `;`, found `as`
error: expected `;`, found keyword `as`
--> $DIR/import-glob-rename.rs:3:12
|
LL | use foo::* as baz;
| ^^ expected `;` here
| ^^ expected `;`
error: aborting due to previous error

View File

@ -11,7 +11,7 @@ fn main(){
}
//~^ NOTE expected one of `.`, `=>`, `?`, or an operator here
_ => {}
//~^ ERROR expected one of `.`, `=>`, `?`, or an operator, found `_`
//~^ ERROR expected one of `.`, `=>`, `?`, or an operator, found reserved identifier `_`
//~| NOTE unexpected token
}
}

View File

@ -12,7 +12,7 @@ help: you can escape reserved keywords to use them as identifiers
LL | r#return
|
error: expected one of `.`, `=>`, `?`, or an operator, found `_`
error: expected one of `.`, `=>`, `?`, or an operator, found reserved identifier `_`
--> $DIR/issue-15980.rs:13:9
|
LL | }

View File

@ -1,5 +1,5 @@
trait T {
extern "Rust" unsafe fn foo(); //~ ERROR expected `fn`, found `unsafe`
extern "Rust" unsafe fn foo(); //~ ERROR expected `fn`, found keyword `unsafe`
}
fn main() {}

View File

@ -1,8 +1,8 @@
error: expected `fn`, found `unsafe`
error: expected `fn`, found keyword `unsafe`
--> $DIR/issue-19398.rs:2:19
|
LL | extern "Rust" unsafe fn foo();
| ^^^^^^ expected `fn` here
| ^^^^^^ expected `fn`
error: aborting due to previous error

View File

@ -1,5 +1,5 @@
fn test_if() {
r#if true { } //~ ERROR found `true`
r#if true { } //~ ERROR found keyword `true`
}
fn test_struct() {

View File

@ -1,4 +1,4 @@
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `true`
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found keyword `true`
--> $DIR/raw-literal-keywords.rs:2:10
|
LL | r#if true { }

View File

@ -8,7 +8,7 @@ fn main() {
let vec = vec![1, 2, 3];
for ( elem in vec ) {
//~^ ERROR expected one of `)`, `,`, `@`, or `|`, found `in`
//~^ ERROR expected one of `)`, `,`, `@`, or `|`, found keyword `in`
//~| ERROR unexpected closing `)`
const RECOVERY_WITNESS: () = 0; //~ ERROR mismatched types
}

View File

@ -1,4 +1,4 @@
error: expected one of `)`, `,`, `@`, or `|`, found `in`
error: expected one of `)`, `,`, `@`, or `|`, found keyword `in`
--> $DIR/recover-for-loop-parens-around-head.rs:10:16
|
LL | for ( elem in vec ) {

View File

@ -1,4 +1,4 @@
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `static`
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found keyword `static`
--> $DIR/removed-syntax-static-fn.rs:4:5
|
LL | impl S {

View File

@ -1 +1,2 @@
type mut_box = Box<mut isize>; //~ ERROR expected one of `>`, const, lifetime, or type, found `mut`
type mut_box = Box<mut isize>;
//~^ ERROR expected one of `>`, const, lifetime, or type, found keyword `mut`

View File

@ -1,4 +1,4 @@
error: expected one of `>`, const, lifetime, or type, found `mut`
error: expected one of `>`, const, lifetime, or type, found keyword `mut`
--> $DIR/removed-syntax-uniq-mut-ty.rs:1:20
|
LL | type mut_box = Box<mut isize>;

View File

@ -25,6 +25,6 @@ use _ as g; //~ ERROR expected identifier, found reserved identifier `_`
trait _ {} //~ ERROR expected identifier, found reserved identifier `_`
trait _ = Copy; //~ ERROR expected identifier, found reserved identifier `_`
macro_rules! _ { () => {} } //~ ERROR expected identifier, found reserved identifier `_`
union _ { f: u8 } //~ ERROR expected one of `!` or `::`, found `_`
union _ { f: u8 } //~ ERROR expected one of `!` or `::`, found reserved identifier `_`
fn main() {}

View File

@ -82,7 +82,7 @@ error: expected identifier, found reserved identifier `_`
LL | macro_rules! _ { () => {} }
| ^ expected identifier, found reserved identifier
error: expected one of `!` or `::`, found `_`
error: expected one of `!` or `::`, found reserved identifier `_`
--> $DIR/underscore_item_not_const.rs:28:7
|
LL | union _ { f: u8 }