Suggest using raw identifiers in 2018 edition when using keywords
This commit is contained in:
parent
433ef826f0
commit
833f12ebd7
@ -798,7 +798,18 @@ 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 Some(token_descr) = self.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(),
|
||||||
|
) {
|
||||||
|
err.span_suggestion_with_applicability(
|
||||||
|
self.span,
|
||||||
|
"you can escape reserved keywords to use them as identifiers",
|
||||||
|
format!("r#{}", s.to_string()),
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
|
} else 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,9 +2,13 @@ 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
|
||||||
|
|
|
||||||
|
LL | ( ) => ( pub fn r#async ( ) { } )
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -2,13 +2,21 @@ 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
|
||||||
|
|
|
||||||
|
LL | let mut r#async = 1; //~ ERROR expected identifier, found reserved keyword `async`
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
error: expected identifier, found reserved keyword `async`
|
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
|
||||||
|
|
|
||||||
|
LL | module::r#async(); //~ ERROR expected identifier, found reserved keyword `async`
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
error: no rules expected the token `r#async`
|
error: no rules expected the token `r#async`
|
||||||
--> $DIR/edition-keywords-2018-2015-parsing.rs:12:31
|
--> $DIR/edition-keywords-2018-2015-parsing.rs:12:31
|
||||||
|
@ -2,9 +2,13 @@ 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
|
||||||
|
|
|
||||||
|
LL | ( ) => ( pub fn r#async ( ) { } )
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -2,13 +2,21 @@ 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
|
||||||
|
|
|
||||||
|
LL | let mut r#async = 1; //~ ERROR expected identifier, found reserved keyword `async`
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
error: expected identifier, found reserved keyword `async`
|
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
|
||||||
|
|
|
||||||
|
LL | module::r#async(); //~ ERROR expected identifier, found reserved keyword `async`
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
error: no rules expected the token `r#async`
|
error: no rules expected the token `r#async`
|
||||||
--> $DIR/edition-keywords-2018-2018-parsing.rs:12:31
|
--> $DIR/edition-keywords-2018-2018-parsing.rs:12:31
|
||||||
|
@ -2,7 +2,11 @@ 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
|
||||||
|
|
|
||||||
|
LL | type A1 = dyn::r#dyn; //~ERROR expected identifier, found keyword `dyn`
|
||||||
|
| ^^^^^
|
||||||
|
|
||||||
error: expected identifier, found `<`
|
error: expected identifier, found `<`
|
||||||
--> $DIR/dyn-trait-compatibility.rs:5:14
|
--> $DIR/dyn-trait-compatibility.rs:5:14
|
||||||
|
Loading…
x
Reference in New Issue
Block a user