Skip to content

Commit c8198a6

Browse files
committed
Improve suggestion for escaping reserved keywords
1 parent 21b4a9c commit c8198a6

File tree

51 files changed

+134
-134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+134
-134
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,10 @@ impl<'a> Parser<'a> {
192192
if ident.is_raw_guess()
193193
&& self.look_ahead(1, |t| valid_follow.contains(&t.kind)) =>
194194
{
195-
err.span_suggestion(
196-
ident.span,
197-
"you can escape reserved keywords to use them as identifiers",
198-
format!("r#{}", ident.name),
195+
err.span_suggestion_verbose(
196+
ident.span.shrink_to_lo(),
197+
&format!("escape `{}` to use it as an identifier", ident.name),
198+
"r#".to_owned(),
199199
Applicability::MaybeIncorrect,
200200
);
201201
}

src/test/ui/async-await/await-keyword/2018-edition-error-in-non-macro-position.stderr

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,76 +4,76 @@ error: expected identifier, found keyword `await`
44
LL | pub mod await {
55
| ^^^^^ expected identifier, found keyword
66
|
7-
help: you can escape reserved keywords to use them as identifiers
7+
help: escape `await` to use it as an identifier
88
|
99
LL | pub mod r#await {
10-
| ~~~~~~~
10+
| ++
1111

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

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

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

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

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

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

7878
error: aborting due to 7 previous errors
7979

src/test/ui/async-await/await-keyword/2018-edition-error.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,54 @@ error: expected identifier, found keyword `await`
44
LL | pub mod await {
55
| ^^^^^ expected identifier, found keyword
66
|
7-
help: you can escape reserved keywords to use them as identifiers
7+
help: escape `await` to use it as an identifier
88
|
99
LL | pub mod r#await {
10-
| ~~~~~~~
10+
| ++
1111

1212
error: expected identifier, found keyword `await`
1313
--> $DIR/2018-edition-error.rs:6:20
1414
|
1515
LL | pub struct await;
1616
| ^^^^^ expected identifier, found keyword
1717
|
18-
help: you can escape reserved keywords to use them as identifiers
18+
help: escape `await` to use it as an identifier
1919
|
2020
LL | pub struct r#await;
21-
| ~~~~~~~
21+
| ++
2222

2323
error: expected identifier, found keyword `await`
2424
--> $DIR/2018-edition-error.rs:9:22
2525
|
2626
LL | use self::outer_mod::await::await;
2727
| ^^^^^ expected identifier, found keyword
2828
|
29-
help: you can escape reserved keywords to use them as identifiers
29+
help: escape `await` to use it as an identifier
3030
|
3131
LL | use self::outer_mod::r#await::await;
32-
| ~~~~~~~
32+
| ++
3333

3434
error: expected identifier, found keyword `await`
3535
--> $DIR/2018-edition-error.rs:9:29
3636
|
3737
LL | use self::outer_mod::await::await;
3838
| ^^^^^ expected identifier, found keyword
3939
|
40-
help: you can escape reserved keywords to use them as identifiers
40+
help: escape `await` to use it as an identifier
4141
|
4242
LL | use self::outer_mod::await::r#await;
43-
| ~~~~~~~
43+
| ++
4444

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

5656
error: expected expression, found `)`
5757
--> $DIR/2018-edition-error.rs:15:12

src/test/ui/editions/edition-keywords-2015-2018-expansion.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | produces_async! {}
55
| ^^^^^^^^^^^^^^^^^^ expected identifier, found keyword
66
|
77
= note: this error originates in the macro `produces_async` (in Nightly builds, run with -Z macro-backtrace for more info)
8-
help: you can escape reserved keywords to use them as identifiers
8+
help: escape `async` to use it as an identifier
99
|
1010
LL | () => (pub fn r#async() {})
11-
| ~~~~~~~
11+
| ++
1212

1313
error: aborting due to previous error
1414

src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ error: expected identifier, found keyword `async`
44
LL | let mut async = 1;
55
| ^^^^^ expected identifier, found keyword
66
|
7-
help: you can escape reserved keywords to use them as identifiers
7+
help: escape `async` to use it as an identifier
88
|
99
LL | let mut r#async = 1;
10-
| ~~~~~~~
10+
| ++
1111

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

2323
error: no rules expected the token `r#async`
2424
--> $DIR/edition-keywords-2018-2015-parsing.rs:20:31

src/test/ui/editions/edition-keywords-2018-2018-expansion.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | produces_async! {}
55
| ^^^^^^^^^^^^^^^^^^ expected identifier, found keyword
66
|
77
= note: this error originates in the macro `produces_async` (in Nightly builds, run with -Z macro-backtrace for more info)
8-
help: you can escape reserved keywords to use them as identifiers
8+
help: escape `async` to use it as an identifier
99
|
1010
LL | () => (pub fn r#async() {})
11-
| ~~~~~~~
11+
| ++
1212

1313
error: aborting due to previous error
1414

src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ error: expected identifier, found keyword `async`
44
LL | let mut async = 1;
55
| ^^^^^ expected identifier, found keyword
66
|
7-
help: you can escape reserved keywords to use them as identifiers
7+
help: escape `async` to use it as an identifier
88
|
99
LL | let mut r#async = 1;
10-
| ~~~~~~~
10+
| ++
1111

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

2323
error: no rules expected the token `r#async`
2424
--> $DIR/edition-keywords-2018-2018-parsing.rs:20:31

src/test/ui/keyword/extern/keyword-extern-as-identifier-pat.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error: expected identifier, found keyword `extern`
44
LL | let extern = 0;
55
| ^^^^^^ expected identifier, found keyword
66
|
7-
help: you can escape reserved keywords to use them as identifiers
7+
help: escape `extern` to use it as an identifier
88
|
99
LL | let r#extern = 0;
10-
| ~~~~~~~~
10+
| ++
1111

1212
error: aborting due to previous error
1313

src/test/ui/keyword/extern/keyword-extern-as-identifier-use.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error: expected identifier, found keyword `extern`
44
LL | use extern::foo;
55
| ^^^^^^ expected identifier, found keyword
66
|
7-
help: you can escape reserved keywords to use them as identifiers
7+
help: escape `extern` to use it as an identifier
88
|
99
LL | use r#extern::foo;
10-
| ~~~~~~~~
10+
| ++
1111

1212
error[E0432]: unresolved import `r#extern`
1313
--> $DIR/keyword-extern-as-identifier-use.rs:1:5

src/test/ui/parser/bad-value-ident-false.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error: expected identifier, found keyword `false`
44
LL | fn false() { }
55
| ^^^^^ expected identifier, found keyword
66
|
7-
help: you can escape reserved keywords to use them as identifiers
7+
help: escape `false` to use it as an identifier
88
|
99
LL | fn r#false() { }
10-
| ~~~~~~~
10+
| ++
1111

1212
error: aborting due to previous error
1313

src/test/ui/parser/bad-value-ident-true.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error: expected identifier, found keyword `true`
44
LL | fn true() { }
55
| ^^^^ expected identifier, found keyword
66
|
7-
help: you can escape reserved keywords to use them as identifiers
7+
help: escape `true` to use it as an identifier
88
|
99
LL | fn r#true() { }
10-
| ~~~~~~
10+
| ++
1111

1212
error: aborting due to previous error
1313

src/test/ui/parser/issues/issue-15980.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ LL |
77
LL | return
88
| ^^^^^^ expected identifier, found keyword
99
|
10-
help: you can escape reserved keywords to use them as identifiers
10+
help: escape `return` to use it as an identifier
1111
|
1212
LL | r#return
13-
|
13+
| ++
1414

1515
error: expected one of `.`, `=>`, `?`, or an operator, found reserved identifier `_`
1616
--> $DIR/issue-15980.rs:13:9

src/test/ui/parser/issues/issue-44406.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error: expected identifier, found keyword `true`
44
LL | foo!(true);
55
| ^^^^ expected identifier, found keyword
66
|
7-
help: you can escape reserved keywords to use them as identifiers
7+
help: escape `true` to use it as an identifier
88
|
99
LL | foo!(r#true);
10-
| ~~~~~~
10+
| ++
1111

1212
error: invalid `struct` delimiters or `fn` call arguments
1313
--> $DIR/issue-44406.rs:3:9

src/test/ui/parser/issues/issue-57198.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error: expected identifier, found keyword `for`
44
LL | m::for();
55
| ^^^ expected identifier, found keyword
66
|
7-
help: you can escape reserved keywords to use them as identifiers
7+
help: escape `for` to use it as an identifier
88
|
99
LL | m::r#for();
10-
| ~~~~~
10+
| ++
1111

1212
error: aborting due to previous error
1313

src/test/ui/parser/issues/issue-81806.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ LL | impl
88
LL | }
99
| - the item list ends here
1010
|
11-
help: you can escape reserved keywords to use them as identifiers
11+
help: escape `impl` to use it as an identifier
1212
|
1313
LL | r#impl
14-
| ~~~~~~
14+
| ++
1515

1616
error: aborting due to previous error
1717

src/test/ui/parser/keyword-abstract.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error: expected identifier, found reserved keyword `abstract`
44
LL | let abstract = ();
55
| ^^^^^^^^ expected identifier, found reserved keyword
66
|
7-
help: you can escape reserved keywords to use them as identifiers
7+
help: escape `abstract` to use it as an identifier
88
|
99
LL | let r#abstract = ();
10-
| ~~~~~~~~~~
10+
| ++
1111

1212
error: aborting due to previous error
1313

src/test/ui/parser/keyword-as-as-identifier.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error: expected identifier, found keyword `as`
44
LL | let as = "foo";
55
| ^^ expected identifier, found keyword
66
|
7-
help: you can escape reserved keywords to use them as identifiers
7+
help: escape `as` to use it as an identifier
88
|
99
LL | let r#as = "foo";
10-
| ~~~~
10+
| ++
1111

1212
error: aborting due to previous error
1313

src/test/ui/parser/keyword-break-as-identifier.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error: expected identifier, found keyword `break`
44
LL | let break = "foo";
55
| ^^^^^ expected identifier, found keyword
66
|
7-
help: you can escape reserved keywords to use them as identifiers
7+
help: escape `break` to use it as an identifier
88
|
99
LL | let r#break = "foo";
10-
| ~~~~~~~
10+
| ++
1111

1212
error: aborting due to previous error
1313

0 commit comments

Comments
 (0)