Skip to content

Commit 44fd3b4

Browse files
committed
Make parse_pat_ident not recover bad name
1 parent abe34e9 commit 44fd3b4

File tree

8 files changed

+15
-274
lines changed

8 files changed

+15
-274
lines changed

compiler/rustc_parse/src/parser/pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ impl<'a> Parser<'a> {
839839
binding_annotation: BindingAnnotation,
840840
syntax_loc: Option<PatternLocation>,
841841
) -> PResult<'a, PatKind> {
842-
let ident = self.parse_ident()?;
842+
let ident = self.parse_ident_common(false)?;
843843

844844
if self.may_recover()
845845
&& !matches!(syntax_loc, Some(PatternLocation::FunctionParameter))

tests/ui/editions/edition-keywords-2018-2015-parsing.stderr

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,5 @@ help: escape `async` to use it as an identifier
99
LL | let mut r#async = 1;
1010
| ++
1111

12-
error: expected identifier, found keyword `async`
13-
--> $DIR/edition-keywords-2018-2015-parsing.rs:26:13
14-
|
15-
LL | module::async();
16-
| ^^^^^ expected identifier, found keyword
17-
|
18-
help: escape `async` to use it as an identifier
19-
|
20-
LL | module::r#async();
21-
| ++
22-
23-
error: no rules expected the token `r#async`
24-
--> $DIR/edition-keywords-2018-2015-parsing.rs:20:31
25-
|
26-
LL | r#async = consumes_async!(r#async);
27-
| ^^^^^^^ no rules expected this token in macro call
28-
|
29-
note: while trying to match `async`
30-
--> $DIR/auxiliary/edition-kw-macro-2015.rs:17:6
31-
|
32-
LL | (async) => (1)
33-
| ^^^^^
34-
35-
error: no rules expected the token `async`
36-
--> $DIR/edition-keywords-2018-2015-parsing.rs:21:35
37-
|
38-
LL | r#async = consumes_async_raw!(async);
39-
| ^^^^^ no rules expected this token in macro call
40-
|
41-
note: while trying to match `r#async`
42-
--> $DIR/auxiliary/edition-kw-macro-2015.rs:22:6
43-
|
44-
LL | (r#async) => (1)
45-
| ^^^^^^^
46-
47-
error: macro expansion ends with an incomplete expression: expected one of `move`, `|`, or `||`
48-
--> $DIR/auxiliary/edition-kw-macro-2015.rs:27:23
49-
|
50-
LL | ($i: ident) => ($i)
51-
| ^ expected one of `move`, `|`, or `||`
52-
|
53-
::: $DIR/edition-keywords-2018-2015-parsing.rs:24:8
54-
|
55-
LL | if passes_ident!(async) == 1 {}
56-
| -------------------- in this macro invocation
57-
58-
error[E0308]: mismatched types
59-
--> $DIR/edition-keywords-2018-2015-parsing.rs:29:33
60-
|
61-
LL | let _recovery_witness: () = 0;
62-
| -- ^ expected `()`, found integer
63-
| |
64-
| expected due to this
65-
66-
error: aborting due to 6 previous errors
12+
error: aborting due to previous error
6713

68-
For more information about this error, try `rustc --explain E0308`.

tests/ui/editions/edition-keywords-2018-2018-parsing.stderr

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,5 @@ help: escape `async` to use it as an identifier
99
LL | let mut r#async = 1;
1010
| ++
1111

12-
error: expected identifier, found keyword `async`
13-
--> $DIR/edition-keywords-2018-2018-parsing.rs:26:13
14-
|
15-
LL | module::async();
16-
| ^^^^^ expected identifier, found keyword
17-
|
18-
help: escape `async` to use it as an identifier
19-
|
20-
LL | module::r#async();
21-
| ++
22-
23-
error: no rules expected the token `r#async`
24-
--> $DIR/edition-keywords-2018-2018-parsing.rs:20:31
25-
|
26-
LL | r#async = consumes_async!(r#async);
27-
| ^^^^^^^ no rules expected this token in macro call
28-
|
29-
note: while trying to match `async`
30-
--> $DIR/auxiliary/edition-kw-macro-2018.rs:17:6
31-
|
32-
LL | (async) => (1)
33-
| ^^^^^
34-
35-
error: no rules expected the token `async`
36-
--> $DIR/edition-keywords-2018-2018-parsing.rs:21:35
37-
|
38-
LL | r#async = consumes_async_raw!(async);
39-
| ^^^^^ no rules expected this token in macro call
40-
|
41-
note: while trying to match `r#async`
42-
--> $DIR/auxiliary/edition-kw-macro-2018.rs:22:6
43-
|
44-
LL | (r#async) => (1)
45-
| ^^^^^^^
46-
47-
error: macro expansion ends with an incomplete expression: expected one of `move`, `|`, or `||`
48-
--> $DIR/auxiliary/edition-kw-macro-2018.rs:27:23
49-
|
50-
LL | ($i: ident) => ($i)
51-
| ^ expected one of `move`, `|`, or `||`
52-
|
53-
::: $DIR/edition-keywords-2018-2018-parsing.rs:24:8
54-
|
55-
LL | if passes_ident!(async) == 1 {}
56-
| -------------------- in this macro invocation
57-
58-
error[E0308]: mismatched types
59-
--> $DIR/edition-keywords-2018-2018-parsing.rs:29:33
60-
|
61-
LL | let _recovery_witness: () = 0;
62-
| -- ^ expected `()`, found integer
63-
| |
64-
| expected due to this
65-
66-
error: aborting due to 6 previous errors
12+
error: aborting due to previous error
6713

68-
For more information about this error, try `rustc --explain E0308`.

tests/ui/issues/issue-66706.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ error: expected identifier, found reserved identifier `_`
2424
--> $DIR/issue-66706.rs:18:26
2525
|
2626
LL | [0; match [|f @ &ref _| () ] {} ]
27-
| ^ expected identifier, found reserved identifier
27+
| ----- ^ expected identifier, found reserved identifier
28+
| |
29+
| while parsing this `match` expression
2830

2931
error[E0282]: type annotations needed
3032
--> $DIR/issue-66706.rs:2:11

tests/ui/parser/issues/issue-104088.stderr

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,6 @@ help: identifiers cannot start with a number
2222
LL | let 23name = 123;
2323
| ^^
2424

25-
error: expected identifier, found `2x`
26-
--> $DIR/issue-104088.rs:12:9
27-
|
28-
LL | let 2x: i32 = 123;
29-
| ^^ expected identifier
30-
|
31-
help: identifiers cannot start with a number
32-
--> $DIR/issue-104088.rs:12:9
33-
|
34-
LL | let 2x: i32 = 123;
35-
| ^
36-
37-
error: expected identifier, found `1x`
38-
--> $DIR/issue-104088.rs:15:9
39-
|
40-
LL | let 1x = 123;
41-
| ^^ expected identifier
42-
|
43-
help: identifiers cannot start with a number
44-
--> $DIR/issue-104088.rs:15:9
45-
|
46-
LL | let 1x = 123;
47-
| ^
48-
4925
error[E0308]: mismatched types
5026
--> $DIR/issue-104088.rs:5:12
5127
|
@@ -54,6 +30,6 @@ LL | if let 2e1 = 123 {
5430
| |
5531
| expected integer, found floating-point number
5632

57-
error: aborting due to 5 previous errors
33+
error: aborting due to 3 previous errors
5834

5935
For more information about this error, try `rustc --explain E0308`.

tests/ui/parser/mut-patterns.stderr

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -72,43 +72,5 @@ help: escape `become` to use it as an identifier
7272
LL | let mut mut yield(r#become, await) = r#yield(0, 0);
7373
| ++
7474

75-
error: expected identifier, found keyword `await`
76-
--> $DIR/mut-patterns.rs:28:31
77-
|
78-
LL | let mut mut yield(become, await) = r#yield(0, 0);
79-
| ^^^^^ expected identifier, found keyword
80-
|
81-
help: escape `await` to use it as an identifier
82-
|
83-
LL | let mut mut yield(become, r#await) = r#yield(0, 0);
84-
| ++
85-
86-
error: `mut` must be attached to each individual binding
87-
--> $DIR/mut-patterns.rs:28:9
88-
|
89-
LL | let mut mut yield(become, await) = r#yield(0, 0);
90-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `mut` to each binding: `r#yield(mut r#become, mut r#await)`
91-
|
92-
= note: `mut` may be followed by `variable` and `variable @ pattern`
93-
94-
error: `mut` must be attached to each individual binding
95-
--> $DIR/mut-patterns.rs:37:9
96-
|
97-
LL | let mut W(mut a, W(b, W(ref c, W(d, B { box f }))))
98-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `mut` to each binding: `W(mut a, W(mut b, W(ref c, W(mut d, B { box mut f }))))`
99-
|
100-
= note: `mut` may be followed by `variable` and `variable @ pattern`
101-
102-
error: expected identifier, found `x`
103-
--> $DIR/mut-patterns.rs:44:21
104-
|
105-
LL | let mut $p = 0;
106-
| ^^ expected identifier
107-
...
108-
LL | foo!(x);
109-
| ------- in this macro invocation
110-
|
111-
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
112-
113-
error: aborting due to 13 previous errors
75+
error: aborting due to 9 previous errors
11476

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,14 @@
1-
error: expected identifier, found keyword `if`
2-
--> $DIR/recover-parens-around-match-arm-head.rs:4:12
3-
|
4-
LL | (0 if true) => {
5-
| ^^ expected identifier, found keyword
6-
71
error: expected one of `)`, `,`, `...`, `..=`, `..`, or `|`, found keyword `if`
82
--> $DIR/recover-parens-around-match-arm-head.rs:4:12
93
|
104
LL | (0 if true) => {
11-
| -^^ expected one of `)`, `,`, `...`, `..=`, `..`, or `|`
12-
| |
13-
| help: missing `,`
14-
15-
error: expected one of `)`, `,`, `@`, or `|`, found keyword `true`
16-
--> $DIR/recover-parens-around-match-arm-head.rs:4:15
17-
|
18-
LL | (0 if true) => {
19-
| -^^^^ expected one of `)`, `,`, `@`, or `|`
20-
| |
21-
| help: missing `,`
5+
| ^^ expected one of `)`, `,`, `...`, `..=`, `..`, or `|`
226

23-
error[E0308]: mismatched types
24-
--> $DIR/recover-parens-around-match-arm-head.rs:4:9
7+
error: expected one of `.`, `=>`, `?`, or an operator, found `)`
8+
--> $DIR/recover-parens-around-match-arm-head.rs:4:19
259
|
26-
LL | let x = match val {
27-
| --- this expression has type `{integer}`
2810
LL | (0 if true) => {
29-
| ^^^^^^^^^^^ expected integer, found `(_, _, _)`
30-
|
31-
= note: expected type `{integer}`
32-
found tuple `(_, _, _)`
33-
34-
error[E0308]: mismatched types
35-
--> $DIR/recover-parens-around-match-arm-head.rs:13:19
36-
|
37-
LL | let _y: u32 = x;
38-
| --- ^ expected `u32`, found `u8`
39-
| |
40-
| expected due to this
41-
|
42-
help: you can convert a `u8` to a `u32`
43-
|
44-
LL | let _y: u32 = x.into();
45-
| +++++++
11+
| ^ expected one of `.`, `=>`, `?`, or an operator
4612

47-
error: aborting due to 5 previous errors
13+
error: aborting due to 2 previous errors
4814

49-
For more information about this error, try `rustc --explain E0308`.

tests/ui/self/self_type_keyword.stderr

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,6 @@ error: expected identifier, found keyword `Self`
1010
LL | ref Self => (),
1111
| ^^^^ expected identifier, found keyword
1212

13-
error: `mut` must be followed by a named binding
14-
--> $DIR/self_type_keyword.rs:16:9
15-
|
16-
LL | mut Self => (),
17-
| ^^^^ help: remove the `mut` prefix
18-
|
19-
= note: `mut` may be followed by `variable` and `variable @ pattern`
20-
21-
error: expected identifier, found keyword `Self`
22-
--> $DIR/self_type_keyword.rs:19:17
23-
|
24-
LL | ref mut Self => (),
25-
| ^^^^ expected identifier, found keyword
26-
27-
error: expected identifier, found keyword `Self`
28-
--> $DIR/self_type_keyword.rs:23:15
29-
|
30-
LL | Foo { Self } => (),
31-
| ^^^^ expected identifier, found keyword
32-
3313
error: expected identifier, found keyword `Self`
3414
--> $DIR/self_type_keyword.rs:31:26
3515
|
@@ -54,24 +34,6 @@ error: lifetimes cannot use keyword names
5434
LL | struct Bar<'Self>;
5535
| ^^^^^
5636

57-
error: cannot find macro `Self` in this scope
58-
--> $DIR/self_type_keyword.rs:21:9
59-
|
60-
LL | Self!() => (),
61-
| ^^^^
62-
63-
error[E0531]: cannot find unit struct, unit variant or constant `Self` in this scope
64-
--> $DIR/self_type_keyword.rs:16:13
65-
|
66-
LL | mut Self => (),
67-
| ^^^^ not found in this scope
68-
|
69-
note: unit struct `foo::Self` exists but is inaccessible
70-
--> $DIR/self_type_keyword.rs:2:3
71-
|
72-
LL | struct Self;
73-
| ^^^^^^^^^^^^ not accessible
74-
7537
error[E0392]: parameter `'Self` is never used
7638
--> $DIR/self_type_keyword.rs:6:12
7739
|
@@ -80,22 +42,6 @@ LL | struct Bar<'Self>;
8042
|
8143
= help: consider removing `'Self`, referring to it in a field, or using a marker such as `PhantomData`
8244

83-
error[E0308]: mismatched types
84-
--> $DIR/self_type_keyword.rs:23:9
85-
|
86-
LL | match 15 {
87-
| -- this expression has type `{integer}`
88-
...
89-
LL | Foo { Self } => (),
90-
| ^^^^^^^^^^^^ expected integer, found `Foo`
91-
92-
error[E0026]: struct `Foo` does not have a field named `Self`
93-
--> $DIR/self_type_keyword.rs:23:15
94-
|
95-
LL | Foo { Self } => (),
96-
| ^^^^ struct `Foo` does not have this field
97-
98-
error: aborting due to 14 previous errors
45+
error: aborting due to 7 previous errors
9946

100-
Some errors have detailed explanations: E0026, E0308, E0392, E0531.
101-
For more information about an error, try `rustc --explain E0026`.
47+
For more information about this error, try `rustc --explain E0392`.

0 commit comments

Comments
 (0)