Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve suggestion for escaping reserved keywords #93395

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

Loading