1
Fork 0

Address review comments

- Suggest raw ident escaping in all editions
- Keep primary label in all cases
This commit is contained in:
Esteban Küber 2018-12-30 11:52:15 -08:00
parent 833f12ebd7
commit 2cd0d14eb1
18 changed files with 68 additions and 19 deletions

View file

@ -798,18 +798,19 @@ impl<'a> Parser<'a> {
let mut err = self.struct_span_err(self.span,
&format!("expected identifier, found {}",
self.this_token_descr()));
if let (true, token::Ident(ref s, false), true) = (
self.span.rust_2018(),
&self.token,
self.token.is_used_keyword() || self.token.is_unused_keyword(),
) {
if let token::Ident(ident, false) = &self.token {
if ident.is_reserved() && !ident.is_path_segment_keyword() &&
ident.name != keywords::Underscore.name()
{
err.span_suggestion_with_applicability(
self.span,
"you can escape reserved keywords to use them as identifiers",
format!("r#{}", s.to_string()),
format!("r#{}", ident),
Applicability::MaybeIncorrect,
);
} else if let Some(token_descr) = self.token_descr() {
}
}
if let Some(token_descr) = self.token_descr() {
err.span_label(self.span, format!("expected identifier, found {}", token_descr));
} else {
err.span_label(self.span, "expected identifier");

View file

@ -2,7 +2,7 @@ error: expected identifier, found reserved keyword `async`
--> $DIR/edition-keywords-2015-2018-expansion.rs:8:5
|
LL | produces_async! {} //~ ERROR expected identifier, found reserved keyword
| ^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^ expected identifier, found reserved keyword
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
help: you can escape reserved keywords to use them as identifiers

View file

@ -2,7 +2,7 @@ error: expected identifier, found reserved keyword `async`
--> $DIR/edition-keywords-2018-2015-parsing.rs:8:13
|
LL | let mut async = 1; //~ ERROR expected identifier, found reserved keyword `async`
| ^^^^^
| ^^^^^ expected identifier, found reserved keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | let mut r#async = 1; //~ ERROR expected identifier, found reserved keyword `async`
@ -12,7 +12,7 @@ error: expected identifier, found reserved keyword `async`
--> $DIR/edition-keywords-2018-2015-parsing.rs:18:13
|
LL | module::async(); //~ ERROR expected identifier, found reserved keyword `async`
| ^^^^^
| ^^^^^ expected identifier, found reserved keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | module::r#async(); //~ ERROR expected identifier, found reserved keyword `async`

View file

@ -2,7 +2,7 @@ error: expected identifier, found reserved keyword `async`
--> $DIR/edition-keywords-2018-2018-expansion.rs:8:5
|
LL | produces_async! {} //~ ERROR expected identifier, found reserved keyword `async`
| ^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^ expected identifier, found reserved keyword
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
help: you can escape reserved keywords to use them as identifiers

View file

@ -2,7 +2,7 @@ error: expected identifier, found reserved keyword `async`
--> $DIR/edition-keywords-2018-2018-parsing.rs:8:13
|
LL | let mut async = 1; //~ ERROR expected identifier, found reserved keyword `async`
| ^^^^^
| ^^^^^ expected identifier, found reserved keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | let mut r#async = 1; //~ ERROR expected identifier, found reserved keyword `async`
@ -12,7 +12,7 @@ error: expected identifier, found reserved keyword `async`
--> $DIR/edition-keywords-2018-2018-parsing.rs:18:13
|
LL | module::async(); //~ ERROR expected identifier, found reserved keyword `async`
| ^^^^^
| ^^^^^ expected identifier, found reserved keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | module::r#async(); //~ ERROR expected identifier, found reserved keyword `async`

View file

@ -3,6 +3,10 @@ error: expected identifier, found keyword `pub`
|
LL | pub duck,
| ^^^ expected identifier, found keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | r#pub duck,
| ^^^^^
error: expected one of `(`, `,`, `=`, `{`, or `}`, found `duck`
--> $DIR/issue-28433.rs:4:9

View file

@ -3,6 +3,10 @@ error: expected identifier, found keyword `true`
|
LL | foo!(true); //~ ERROR expected type, found keyword
| ^^^^ expected identifier, found keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | foo!(r#true); //~ ERROR expected type, found keyword
| ^^^^^^
error: expected type, found keyword `true`
--> $DIR/issue-44406.rs:8:10

View file

@ -3,6 +3,10 @@ error: expected identifier, found keyword `loop`
|
LL | loop { break 'label: loop { break 'label 42; }; }
| ^^^^ expected identifier, found keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | loop { break 'label: r#loop { break 'label 42; }; }
| ^^^^^^
error: expected type, found keyword `loop`
--> $DIR/lifetime_starts_expressions.rs:6:26

View file

@ -3,6 +3,10 @@ error: expected identifier, found keyword `for`
|
LL | fn foo2<I>(x: <I as for<'x> Foo<&'x isize>>::A)
| ^^^ expected identifier, found keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | fn foo2<I>(x: <I as r#for<'x> Foo<&'x isize>>::A)
| ^^^^^
error: expected one of `::` or `>`, found `Foo`
--> $DIR/associated-types-project-from-hrtb-explicit.rs:12:29

View file

@ -3,6 +3,10 @@ error: expected identifier, found keyword `false`
|
LL | fn false() { } //~ ERROR expected identifier, found keyword `false`
| ^^^^^ expected identifier, found keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | fn r#false() { } //~ ERROR expected identifier, found keyword `false`
| ^^^^^^^
error: aborting due to previous error

View file

@ -3,6 +3,10 @@ error: expected identifier, found keyword `true`
|
LL | fn true() { } //~ ERROR expected identifier, found keyword `true`
| ^^^^ expected identifier, found keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | fn r#true() { } //~ ERROR expected identifier, found keyword `true`
| ^^^^^^
error: aborting due to previous error

View file

@ -6,6 +6,10 @@ LL | Err(ref e) if e.kind == io::EndOfFile {
LL | //~^ NOTE while parsing this struct
LL | return
| ^^^^^^ expected identifier, found keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | r#return
|
error: expected one of `.`, `=>`, `?`, or an operator, found `_`
--> $DIR/issue-15980.rs:15:9

View file

@ -3,6 +3,10 @@ error: expected identifier, found keyword `break`
|
LL | pub mod break {
| ^^^^^ expected identifier, found keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | pub mod r#break {
| ^^^^^^^
error: aborting due to previous error

View file

@ -3,6 +3,10 @@ error: expected identifier, found reserved keyword `macro`
|
LL | fn macro() { //~ ERROR expected identifier, found reserved keyword `macro`
| ^^^^^ expected identifier, found reserved keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | fn r#macro() { //~ ERROR expected identifier, found reserved keyword `macro`
| ^^^^^^^
error: aborting due to previous error

View file

@ -3,6 +3,10 @@ error: expected identifier, found keyword `let`
|
LL | let foo: (),
| ^^^ expected identifier, found keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | r#let foo: (),
| ^^^^^
error: expected `:`, found `foo`
--> $DIR/removed-syntax-field-let.rs:4:9

View file

@ -3,6 +3,10 @@ error: expected identifier, found keyword `as`
|
LL | use std::any:: as foo; //~ ERROR expected identifier, found keyword `as`
| ^^ expected identifier, found keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | use std::any:: r#as foo; //~ ERROR expected identifier, found keyword `as`
| ^^^^
error: expected one of `::`, `;`, or `as`, found `foo`
--> $DIR/use-as-where-use-ends-with-mod-sep.rs:3:19

View file

@ -2,7 +2,7 @@ error: expected identifier, found keyword `dyn`
--> $DIR/dyn-trait-compatibility.rs:4:16
|
LL | type A1 = dyn::dyn; //~ERROR expected identifier, found keyword `dyn`
| ^^^
| ^^^ expected identifier, found keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | type A1 = dyn::r#dyn; //~ERROR expected identifier, found keyword `dyn`

View file

@ -6,6 +6,10 @@ LL | let try_result: Option<_> = try {
LL | //~^ ERROR expected struct, variant or union type, found macro `try`
LL | let x = 5; //~ ERROR expected identifier, found keyword
| ^^^ expected identifier, found keyword
help: you can escape reserved keywords to use them as identifiers
|
LL | r#let x = 5; //~ ERROR expected identifier, found keyword
| ^^^^^
error[E0574]: expected struct, variant or union type, found macro `try`
--> $DIR/try-block-in-edition2015.rs:4:33