Skip to content

Commit

Permalink
Improve suggestion for escaping reserved keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
camelid committed Jan 27, 2022
1 parent 21b4a9c commit c8198a6
Show file tree
Hide file tree
Showing 51 changed files with 134 additions and 134 deletions.
8 changes: 4 additions & 4 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Expand Up @@ -192,10 +192,10 @@ impl<'a> Parser<'a> {
if ident.is_raw_guess()
&& self.look_ahead(1, |t| valid_follow.contains(&t.kind)) =>
{
err.span_suggestion(
ident.span,
"you can escape reserved keywords to use them as identifiers",
format!("r#{}", ident.name),
err.span_suggestion_verbose(
ident.span.shrink_to_lo(),
&format!("escape `{}` to use it as an identifier", ident.name),
"r#".to_owned(),
Applicability::MaybeIncorrect,
);
}
Expand Down
Expand Up @@ -4,76 +4,76 @@ error: expected identifier, found keyword `await`
LL | pub mod await {
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `await` to use it as an identifier
|
LL | pub mod r#await {
| ~~~~~~~
| ++

error: expected identifier, found keyword `await`
--> $DIR/2018-edition-error-in-non-macro-position.rs:7:20
|
LL | pub struct await;
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `await` to use it as an identifier
|
LL | pub struct r#await;
| ~~~~~~~
| ++

error: expected identifier, found keyword `await`
--> $DIR/2018-edition-error-in-non-macro-position.rs:10:22
|
LL | use self::outer_mod::await::await;
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `await` to use it as an identifier
|
LL | use self::outer_mod::r#await::await;
| ~~~~~~~
| ++

error: expected identifier, found keyword `await`
--> $DIR/2018-edition-error-in-non-macro-position.rs:10:29
|
LL | use self::outer_mod::await::await;
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `await` to use it as an identifier
|
LL | use self::outer_mod::await::r#await;
| ~~~~~~~
| ++

error: expected identifier, found keyword `await`
--> $DIR/2018-edition-error-in-non-macro-position.rs:13:14
|
LL | struct Foo { await: () }
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `await` to use it as an identifier
|
LL | struct Foo { r#await: () }
| ~~~~~~~
| ++

error: expected identifier, found keyword `await`
--> $DIR/2018-edition-error-in-non-macro-position.rs:16:15
|
LL | impl Foo { fn await() {} }
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `await` to use it as an identifier
|
LL | impl Foo { fn r#await() {} }
| ~~~~~~~
| ++

error: expected identifier, found keyword `await`
--> $DIR/2018-edition-error-in-non-macro-position.rs:19:14
|
LL | macro_rules! await {
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `await` to use it as an identifier
|
LL | macro_rules! r#await {
| ~~~~~~~
| ++

error: aborting due to 7 previous errors

20 changes: 10 additions & 10 deletions src/test/ui/async-await/await-keyword/2018-edition-error.stderr
Expand Up @@ -4,54 +4,54 @@ error: expected identifier, found keyword `await`
LL | pub mod await {
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `await` to use it as an identifier
|
LL | pub mod r#await {
| ~~~~~~~
| ++

error: expected identifier, found keyword `await`
--> $DIR/2018-edition-error.rs:6:20
|
LL | pub struct await;
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `await` to use it as an identifier
|
LL | pub struct r#await;
| ~~~~~~~
| ++

error: expected identifier, found keyword `await`
--> $DIR/2018-edition-error.rs:9:22
|
LL | use self::outer_mod::await::await;
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `await` to use it as an identifier
|
LL | use self::outer_mod::r#await::await;
| ~~~~~~~
| ++

error: expected identifier, found keyword `await`
--> $DIR/2018-edition-error.rs:9:29
|
LL | use self::outer_mod::await::await;
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `await` to use it as an identifier
|
LL | use self::outer_mod::await::r#await;
| ~~~~~~~
| ++

error: expected identifier, found keyword `await`
--> $DIR/2018-edition-error.rs:12:14
|
LL | macro_rules! await { () => {}; }
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `await` to use it as an identifier
|
LL | macro_rules! r#await { () => {}; }
| ~~~~~~~
| ++

error: expected expression, found `)`
--> $DIR/2018-edition-error.rs:15:12
Expand Down
Expand Up @@ -5,10 +5,10 @@ LL | produces_async! {}
| ^^^^^^^^^^^^^^^^^^ expected identifier, found keyword
|
= note: this error originates in the macro `produces_async` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you can escape reserved keywords to use them as identifiers
help: escape `async` to use it as an identifier
|
LL | () => (pub fn r#async() {})
| ~~~~~~~
| ++

error: aborting due to previous error

Expand Up @@ -4,21 +4,21 @@ error: expected identifier, found keyword `async`
LL | let mut async = 1;
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `async` to use it as an identifier
|
LL | let mut r#async = 1;
| ~~~~~~~
| ++

error: expected identifier, found keyword `async`
--> $DIR/edition-keywords-2018-2015-parsing.rs:26:13
|
LL | module::async();
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `async` to use it as an identifier
|
LL | module::r#async();
| ~~~~~~~
| ++

error: no rules expected the token `r#async`
--> $DIR/edition-keywords-2018-2015-parsing.rs:20:31
Expand Down
Expand Up @@ -5,10 +5,10 @@ LL | produces_async! {}
| ^^^^^^^^^^^^^^^^^^ expected identifier, found keyword
|
= note: this error originates in the macro `produces_async` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you can escape reserved keywords to use them as identifiers
help: escape `async` to use it as an identifier
|
LL | () => (pub fn r#async() {})
| ~~~~~~~
| ++

error: aborting due to previous error

Expand Up @@ -4,21 +4,21 @@ error: expected identifier, found keyword `async`
LL | let mut async = 1;
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `async` to use it as an identifier
|
LL | let mut r#async = 1;
| ~~~~~~~
| ++

error: expected identifier, found keyword `async`
--> $DIR/edition-keywords-2018-2018-parsing.rs:26:13
|
LL | module::async();
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `async` to use it as an identifier
|
LL | module::r#async();
| ~~~~~~~
| ++

error: no rules expected the token `r#async`
--> $DIR/edition-keywords-2018-2018-parsing.rs:20:31
Expand Down
Expand Up @@ -4,10 +4,10 @@ error: expected identifier, found keyword `extern`
LL | let extern = 0;
| ^^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `extern` to use it as an identifier
|
LL | let r#extern = 0;
| ~~~~~~~~
| ++

error: aborting due to previous error

Expand Up @@ -4,10 +4,10 @@ error: expected identifier, found keyword `extern`
LL | use extern::foo;
| ^^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `extern` to use it as an identifier
|
LL | use r#extern::foo;
| ~~~~~~~~
| ++

error[E0432]: unresolved import `r#extern`
--> $DIR/keyword-extern-as-identifier-use.rs:1:5
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/bad-value-ident-false.stderr
Expand Up @@ -4,10 +4,10 @@ error: expected identifier, found keyword `false`
LL | fn false() { }
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `false` to use it as an identifier
|
LL | fn r#false() { }
| ~~~~~~~
| ++

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/parser/bad-value-ident-true.stderr
Expand Up @@ -4,10 +4,10 @@ error: expected identifier, found keyword `true`
LL | fn true() { }
| ^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `true` to use it as an identifier
|
LL | fn r#true() { }
| ~~~~~~
| ++

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/parser/issues/issue-15980.stderr
Expand Up @@ -7,10 +7,10 @@ LL |
LL | return
| ^^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `return` to use it as an identifier
|
LL | r#return
|
| ++

error: expected one of `.`, `=>`, `?`, or an operator, found reserved identifier `_`
--> $DIR/issue-15980.rs:13:9
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/issues/issue-44406.stderr
Expand Up @@ -4,10 +4,10 @@ error: expected identifier, found keyword `true`
LL | foo!(true);
| ^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `true` to use it as an identifier
|
LL | foo!(r#true);
| ~~~~~~
| ++

error: invalid `struct` delimiters or `fn` call arguments
--> $DIR/issue-44406.rs:3:9
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/issues/issue-57198.stderr
Expand Up @@ -4,10 +4,10 @@ error: expected identifier, found keyword `for`
LL | m::for();
| ^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `for` to use it as an identifier
|
LL | m::r#for();
| ~~~~~
| ++

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/parser/issues/issue-81806.stderr
Expand Up @@ -8,10 +8,10 @@ LL | impl
LL | }
| - the item list ends here
|
help: you can escape reserved keywords to use them as identifiers
help: escape `impl` to use it as an identifier
|
LL | r#impl
| ~~~~~~
| ++

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/parser/keyword-abstract.stderr
Expand Up @@ -4,10 +4,10 @@ error: expected identifier, found reserved keyword `abstract`
LL | let abstract = ();
| ^^^^^^^^ expected identifier, found reserved keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `abstract` to use it as an identifier
|
LL | let r#abstract = ();
| ~~~~~~~~~~
| ++

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/parser/keyword-as-as-identifier.stderr
Expand Up @@ -4,10 +4,10 @@ error: expected identifier, found keyword `as`
LL | let as = "foo";
| ^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `as` to use it as an identifier
|
LL | let r#as = "foo";
| ~~~~
| ++

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/parser/keyword-break-as-identifier.stderr
Expand Up @@ -4,10 +4,10 @@ error: expected identifier, found keyword `break`
LL | let break = "foo";
| ^^^^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
help: escape `break` to use it as an identifier
|
LL | let r#break = "foo";
| ~~~~~~~
| ++

error: aborting due to previous error

0 comments on commit c8198a6

Please sign in to comment.