Skip to content

Commit

Permalink
Tweak unexpected token wording
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 28, 2019
1 parent d673d0a commit 1b0836d
Show file tree
Hide file tree
Showing 32 changed files with 42 additions and 41 deletions.
10 changes: 5 additions & 5 deletions src/libsyntax/parse/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/async-await/no-async-const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
2 changes: 1 addition & 1 deletion src/test/ui/async-await/no-async-const.stderr
Original file line number Diff line number Diff line change
@@ -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() {}
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/async-await/no-unsafe-async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
4 changes: 2 additions & 2 deletions src/test/ui/async-await/no-unsafe-async.stderr
Original file line number Diff line number Diff line change
@@ -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() {}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/can-begin-expr-check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
}
2 changes: 1 addition & 1 deletion src/test/ui/can-begin-expr-check.stderr
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-43196.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: expected `|`, found `}`
--> $DIR/issue-43196.rs:3:1
|
LL | |
| - expected `|` here
| - expected `|`
LL | }
| ^ unexpected token

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion src/test/ui/macros/issue-54441.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/default.stderr
Original file line number Diff line number Diff line change
@@ -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() }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/duplicate-visibility.stderr
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/extern-expected-fn-or-brace.rs
Original file line number Diff line number Diff line change
@@ -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`
2 changes: 1 addition & 1 deletion src/test/ui/parser/extern-expected-fn-or-brace.stderr
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/impl-parsing.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion src/test/ui/parser/import-from-path.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions src/test/ui/parser/import-from-rename.stderr
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion src/test/ui/parser/import-glob-path.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions src/test/ui/parser/import-glob-rename.stderr
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion src/test/ui/parser/issue-15980.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion src/test/ui/parser/issue-15980.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 | }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/issue-19398.rs
Original file line number Diff line number Diff line change
@@ -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() {}
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-19398.stderr
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion src/test/ui/parser/raw/raw-literal-keywords.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn test_if() {
r#if true { } //~ ERROR found `true`
r#if true { } //~ ERROR found keyword `true`
}

fn test_struct() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/raw/raw-literal-keywords.stderr
Original file line number Diff line number Diff line change
@@ -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 { }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/recover-for-loop-parens-around-head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/removed-syntax-static-fn.stderr
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/parser/removed-syntax-uniq-mut-ty.rs
Original file line number Diff line number Diff line change
@@ -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`
2 changes: 1 addition & 1 deletion src/test/ui/parser/removed-syntax-uniq-mut-ty.stderr
Original file line number Diff line number Diff line change
@@ -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>;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/underscore_item_not_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
2 changes: 1 addition & 1 deletion src/test/ui/parser/underscore_item_not_const.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 1b0836d

Please sign in to comment.