Address review comments
- Suggest raw ident escaping in all editions - Keep primary label in all cases
This commit is contained in:
parent
833f12ebd7
commit
2cd0d14eb1
18 changed files with 68 additions and 19 deletions
|
@ -798,18 +798,19 @@ impl<'a> Parser<'a> {
|
||||||
let mut err = self.struct_span_err(self.span,
|
let mut err = self.struct_span_err(self.span,
|
||||||
&format!("expected identifier, found {}",
|
&format!("expected identifier, found {}",
|
||||||
self.this_token_descr()));
|
self.this_token_descr()));
|
||||||
if let (true, token::Ident(ref s, false), true) = (
|
if let token::Ident(ident, false) = &self.token {
|
||||||
self.span.rust_2018(),
|
if ident.is_reserved() && !ident.is_path_segment_keyword() &&
|
||||||
&self.token,
|
ident.name != keywords::Underscore.name()
|
||||||
self.token.is_used_keyword() || self.token.is_unused_keyword(),
|
{
|
||||||
) {
|
err.span_suggestion_with_applicability(
|
||||||
err.span_suggestion_with_applicability(
|
self.span,
|
||||||
self.span,
|
"you can escape reserved keywords to use them as identifiers",
|
||||||
"you can escape reserved keywords to use them as identifiers",
|
format!("r#{}", ident),
|
||||||
format!("r#{}", s.to_string()),
|
Applicability::MaybeIncorrect,
|
||||||
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));
|
err.span_label(self.span, format!("expected identifier, found {}", token_descr));
|
||||||
} else {
|
} else {
|
||||||
err.span_label(self.span, "expected identifier");
|
err.span_label(self.span, "expected identifier");
|
||||||
|
|
|
@ -2,7 +2,7 @@ error: expected identifier, found reserved keyword `async`
|
||||||
--> $DIR/edition-keywords-2015-2018-expansion.rs:8:5
|
--> $DIR/edition-keywords-2015-2018-expansion.rs:8:5
|
||||||
|
|
|
|
||||||
LL | produces_async! {} //~ ERROR expected identifier, found reserved keyword
|
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)
|
= 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
|
help: you can escape reserved keywords to use them as identifiers
|
||||||
|
|
|
@ -2,7 +2,7 @@ error: expected identifier, found reserved keyword `async`
|
||||||
--> $DIR/edition-keywords-2018-2015-parsing.rs:8:13
|
--> $DIR/edition-keywords-2018-2015-parsing.rs:8:13
|
||||||
|
|
|
|
||||||
LL | let mut async = 1; //~ ERROR expected identifier, found reserved keyword `async`
|
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
|
help: you can escape reserved keywords to use them as identifiers
|
||||||
|
|
|
|
||||||
LL | let mut r#async = 1; //~ ERROR expected identifier, found reserved keyword `async`
|
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
|
--> $DIR/edition-keywords-2018-2015-parsing.rs:18:13
|
||||||
|
|
|
|
||||||
LL | module::async(); //~ ERROR expected identifier, found reserved keyword `async`
|
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
|
help: you can escape reserved keywords to use them as identifiers
|
||||||
|
|
|
|
||||||
LL | module::r#async(); //~ ERROR expected identifier, found reserved keyword `async`
|
LL | module::r#async(); //~ ERROR expected identifier, found reserved keyword `async`
|
||||||
|
|
|
@ -2,7 +2,7 @@ error: expected identifier, found reserved keyword `async`
|
||||||
--> $DIR/edition-keywords-2018-2018-expansion.rs:8:5
|
--> $DIR/edition-keywords-2018-2018-expansion.rs:8:5
|
||||||
|
|
|
|
||||||
LL | produces_async! {} //~ ERROR expected identifier, found reserved keyword `async`
|
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)
|
= 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
|
help: you can escape reserved keywords to use them as identifiers
|
||||||
|
|
|
@ -2,7 +2,7 @@ error: expected identifier, found reserved keyword `async`
|
||||||
--> $DIR/edition-keywords-2018-2018-parsing.rs:8:13
|
--> $DIR/edition-keywords-2018-2018-parsing.rs:8:13
|
||||||
|
|
|
|
||||||
LL | let mut async = 1; //~ ERROR expected identifier, found reserved keyword `async`
|
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
|
help: you can escape reserved keywords to use them as identifiers
|
||||||
|
|
|
|
||||||
LL | let mut r#async = 1; //~ ERROR expected identifier, found reserved keyword `async`
|
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
|
--> $DIR/edition-keywords-2018-2018-parsing.rs:18:13
|
||||||
|
|
|
|
||||||
LL | module::async(); //~ ERROR expected identifier, found reserved keyword `async`
|
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
|
help: you can escape reserved keywords to use them as identifiers
|
||||||
|
|
|
|
||||||
LL | module::r#async(); //~ ERROR expected identifier, found reserved keyword `async`
|
LL | module::r#async(); //~ ERROR expected identifier, found reserved keyword `async`
|
||||||
|
|
|
@ -3,6 +3,10 @@ error: expected identifier, found keyword `pub`
|
||||||
|
|
|
|
||||||
LL | pub duck,
|
LL | pub duck,
|
||||||
| ^^^ expected identifier, found keyword
|
| ^^^ 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`
|
error: expected one of `(`, `,`, `=`, `{`, or `}`, found `duck`
|
||||||
--> $DIR/issue-28433.rs:4:9
|
--> $DIR/issue-28433.rs:4:9
|
||||||
|
|
|
@ -3,6 +3,10 @@ error: expected identifier, found keyword `true`
|
||||||
|
|
|
|
||||||
LL | foo!(true); //~ ERROR expected type, found keyword
|
LL | foo!(true); //~ ERROR expected type, found keyword
|
||||||
| ^^^^ expected identifier, 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`
|
error: expected type, found keyword `true`
|
||||||
--> $DIR/issue-44406.rs:8:10
|
--> $DIR/issue-44406.rs:8:10
|
||||||
|
|
|
@ -3,6 +3,10 @@ error: expected identifier, found keyword `loop`
|
||||||
|
|
|
|
||||||
LL | loop { break 'label: loop { break 'label 42; }; }
|
LL | loop { break 'label: loop { break 'label 42; }; }
|
||||||
| ^^^^ expected identifier, found keyword
|
| ^^^^ 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`
|
error: expected type, found keyword `loop`
|
||||||
--> $DIR/lifetime_starts_expressions.rs:6:26
|
--> $DIR/lifetime_starts_expressions.rs:6:26
|
||||||
|
|
|
@ -3,6 +3,10 @@ error: expected identifier, found keyword `for`
|
||||||
|
|
|
|
||||||
LL | fn foo2<I>(x: <I as for<'x> Foo<&'x isize>>::A)
|
LL | fn foo2<I>(x: <I as for<'x> Foo<&'x isize>>::A)
|
||||||
| ^^^ expected identifier, found keyword
|
| ^^^ 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`
|
error: expected one of `::` or `>`, found `Foo`
|
||||||
--> $DIR/associated-types-project-from-hrtb-explicit.rs:12:29
|
--> $DIR/associated-types-project-from-hrtb-explicit.rs:12:29
|
||||||
|
|
|
@ -3,6 +3,10 @@ error: expected identifier, found keyword `false`
|
||||||
|
|
|
|
||||||
LL | fn false() { } //~ ERROR expected identifier, found keyword `false`
|
LL | fn false() { } //~ ERROR expected identifier, found keyword `false`
|
||||||
| ^^^^^ expected identifier, found keyword
|
| ^^^^^ 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
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,10 @@ error: expected identifier, found keyword `true`
|
||||||
|
|
|
|
||||||
LL | fn true() { } //~ ERROR expected identifier, found keyword `true`
|
LL | fn true() { } //~ ERROR expected identifier, found keyword `true`
|
||||||
| ^^^^ expected identifier, found keyword
|
| ^^^^ 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
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,10 @@ LL | Err(ref e) if e.kind == io::EndOfFile {
|
||||||
LL | //~^ NOTE while parsing this struct
|
LL | //~^ NOTE while parsing this struct
|
||||||
LL | return
|
LL | return
|
||||||
| ^^^^^^ expected identifier, found keyword
|
| ^^^^^^ 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 `_`
|
error: expected one of `.`, `=>`, `?`, or an operator, found `_`
|
||||||
--> $DIR/issue-15980.rs:15:9
|
--> $DIR/issue-15980.rs:15:9
|
||||||
|
|
|
@ -3,6 +3,10 @@ error: expected identifier, found keyword `break`
|
||||||
|
|
|
|
||||||
LL | pub mod break {
|
LL | pub mod break {
|
||||||
| ^^^^^ expected identifier, found keyword
|
| ^^^^^ 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
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,10 @@ error: expected identifier, found reserved keyword `macro`
|
||||||
|
|
|
|
||||||
LL | fn macro() { //~ ERROR expected identifier, found reserved keyword `macro`
|
LL | fn macro() { //~ ERROR expected identifier, found reserved keyword `macro`
|
||||||
| ^^^^^ expected identifier, found reserved keyword
|
| ^^^^^ 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
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,10 @@ error: expected identifier, found keyword `let`
|
||||||
|
|
|
|
||||||
LL | let foo: (),
|
LL | let foo: (),
|
||||||
| ^^^ expected identifier, found keyword
|
| ^^^ expected identifier, found keyword
|
||||||
|
help: you can escape reserved keywords to use them as identifiers
|
||||||
|
|
|
||||||
|
LL | r#let foo: (),
|
||||||
|
| ^^^^^
|
||||||
|
|
||||||
error: expected `:`, found `foo`
|
error: expected `:`, found `foo`
|
||||||
--> $DIR/removed-syntax-field-let.rs:4:9
|
--> $DIR/removed-syntax-field-let.rs:4:9
|
||||||
|
|
|
@ -3,6 +3,10 @@ error: expected identifier, found keyword `as`
|
||||||
|
|
|
|
||||||
LL | use std::any:: as foo; //~ ERROR expected identifier, found keyword `as`
|
LL | use std::any:: as foo; //~ ERROR expected identifier, found keyword `as`
|
||||||
| ^^ expected identifier, found keyword
|
| ^^ 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`
|
error: expected one of `::`, `;`, or `as`, found `foo`
|
||||||
--> $DIR/use-as-where-use-ends-with-mod-sep.rs:3:19
|
--> $DIR/use-as-where-use-ends-with-mod-sep.rs:3:19
|
||||||
|
|
|
@ -2,7 +2,7 @@ error: expected identifier, found keyword `dyn`
|
||||||
--> $DIR/dyn-trait-compatibility.rs:4:16
|
--> $DIR/dyn-trait-compatibility.rs:4:16
|
||||||
|
|
|
|
||||||
LL | type A1 = dyn::dyn; //~ERROR expected identifier, found keyword `dyn`
|
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
|
help: you can escape reserved keywords to use them as identifiers
|
||||||
|
|
|
|
||||||
LL | type A1 = dyn::r#dyn; //~ERROR expected identifier, found keyword `dyn`
|
LL | type A1 = dyn::r#dyn; //~ERROR expected identifier, found keyword `dyn`
|
||||||
|
|
|
@ -6,6 +6,10 @@ LL | let try_result: Option<_> = try {
|
||||||
LL | //~^ ERROR expected struct, variant or union type, found macro `try`
|
LL | //~^ ERROR expected struct, variant or union type, found macro `try`
|
||||||
LL | let x = 5; //~ ERROR expected identifier, found keyword
|
LL | let x = 5; //~ ERROR expected identifier, found keyword
|
||||||
| ^^^ 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`
|
error[E0574]: expected struct, variant or union type, found macro `try`
|
||||||
--> $DIR/try-block-in-edition2015.rs:4:33
|
--> $DIR/try-block-in-edition2015.rs:4:33
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue