From 44fd3b4d4648c9ea2dfa052fe5d3dbb2dfb4f492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 6 Nov 2023 21:00:13 +0000 Subject: [PATCH] Make `parse_pat_ident` not recover bad name --- compiler/rustc_parse/src/parser/pat.rs | 2 +- .../edition-keywords-2018-2015-parsing.stderr | 57 +----------------- .../edition-keywords-2018-2018-parsing.stderr | 57 +----------------- tests/ui/issues/issue-66706.stderr | 4 +- tests/ui/parser/issues/issue-104088.stderr | 26 +-------- tests/ui/parser/mut-patterns.stderr | 40 +------------ ...ecover-parens-around-match-arm-head.stderr | 45 ++------------ tests/ui/self/self_type_keyword.stderr | 58 +------------------ 8 files changed, 15 insertions(+), 274 deletions(-) diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index b05868e235a..ff36ac952ad 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -839,7 +839,7 @@ impl<'a> Parser<'a> { binding_annotation: BindingAnnotation, syntax_loc: Option, ) -> PResult<'a, PatKind> { - let ident = self.parse_ident()?; + let ident = self.parse_ident_common(false)?; if self.may_recover() && !matches!(syntax_loc, Some(PatternLocation::FunctionParameter)) diff --git a/tests/ui/editions/edition-keywords-2018-2015-parsing.stderr b/tests/ui/editions/edition-keywords-2018-2015-parsing.stderr index 1a4a94e9733..20a58236855 100644 --- a/tests/ui/editions/edition-keywords-2018-2015-parsing.stderr +++ b/tests/ui/editions/edition-keywords-2018-2015-parsing.stderr @@ -9,60 +9,5 @@ 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: escape `async` to use it as an identifier - | -LL | module::r#async(); - | ++ +error: aborting due to previous error -error: no rules expected the token `r#async` - --> $DIR/edition-keywords-2018-2015-parsing.rs:20:31 - | -LL | r#async = consumes_async!(r#async); - | ^^^^^^^ no rules expected this token in macro call - | -note: while trying to match `async` - --> $DIR/auxiliary/edition-kw-macro-2015.rs:17:6 - | -LL | (async) => (1) - | ^^^^^ - -error: no rules expected the token `async` - --> $DIR/edition-keywords-2018-2015-parsing.rs:21:35 - | -LL | r#async = consumes_async_raw!(async); - | ^^^^^ no rules expected this token in macro call - | -note: while trying to match `r#async` - --> $DIR/auxiliary/edition-kw-macro-2015.rs:22:6 - | -LL | (r#async) => (1) - | ^^^^^^^ - -error: macro expansion ends with an incomplete expression: expected one of `move`, `|`, or `||` - --> $DIR/auxiliary/edition-kw-macro-2015.rs:27:23 - | -LL | ($i: ident) => ($i) - | ^ expected one of `move`, `|`, or `||` - | - ::: $DIR/edition-keywords-2018-2015-parsing.rs:24:8 - | -LL | if passes_ident!(async) == 1 {} - | -------------------- in this macro invocation - -error[E0308]: mismatched types - --> $DIR/edition-keywords-2018-2015-parsing.rs:29:33 - | -LL | let _recovery_witness: () = 0; - | -- ^ expected `()`, found integer - | | - | expected due to this - -error: aborting due to 6 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/editions/edition-keywords-2018-2018-parsing.stderr b/tests/ui/editions/edition-keywords-2018-2018-parsing.stderr index 19eb7ac9823..e904165a5ce 100644 --- a/tests/ui/editions/edition-keywords-2018-2018-parsing.stderr +++ b/tests/ui/editions/edition-keywords-2018-2018-parsing.stderr @@ -9,60 +9,5 @@ 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: escape `async` to use it as an identifier - | -LL | module::r#async(); - | ++ +error: aborting due to previous error -error: no rules expected the token `r#async` - --> $DIR/edition-keywords-2018-2018-parsing.rs:20:31 - | -LL | r#async = consumes_async!(r#async); - | ^^^^^^^ no rules expected this token in macro call - | -note: while trying to match `async` - --> $DIR/auxiliary/edition-kw-macro-2018.rs:17:6 - | -LL | (async) => (1) - | ^^^^^ - -error: no rules expected the token `async` - --> $DIR/edition-keywords-2018-2018-parsing.rs:21:35 - | -LL | r#async = consumes_async_raw!(async); - | ^^^^^ no rules expected this token in macro call - | -note: while trying to match `r#async` - --> $DIR/auxiliary/edition-kw-macro-2018.rs:22:6 - | -LL | (r#async) => (1) - | ^^^^^^^ - -error: macro expansion ends with an incomplete expression: expected one of `move`, `|`, or `||` - --> $DIR/auxiliary/edition-kw-macro-2018.rs:27:23 - | -LL | ($i: ident) => ($i) - | ^ expected one of `move`, `|`, or `||` - | - ::: $DIR/edition-keywords-2018-2018-parsing.rs:24:8 - | -LL | if passes_ident!(async) == 1 {} - | -------------------- in this macro invocation - -error[E0308]: mismatched types - --> $DIR/edition-keywords-2018-2018-parsing.rs:29:33 - | -LL | let _recovery_witness: () = 0; - | -- ^ expected `()`, found integer - | | - | expected due to this - -error: aborting due to 6 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/issues/issue-66706.stderr b/tests/ui/issues/issue-66706.stderr index 8a30c0cad39..ffdd61e7723 100644 --- a/tests/ui/issues/issue-66706.stderr +++ b/tests/ui/issues/issue-66706.stderr @@ -24,7 +24,9 @@ error: expected identifier, found reserved identifier `_` --> $DIR/issue-66706.rs:18:26 | LL | [0; match [|f @ &ref _| () ] {} ] - | ^ expected identifier, found reserved identifier + | ----- ^ expected identifier, found reserved identifier + | | + | while parsing this `match` expression error[E0282]: type annotations needed --> $DIR/issue-66706.rs:2:11 diff --git a/tests/ui/parser/issues/issue-104088.stderr b/tests/ui/parser/issues/issue-104088.stderr index 8b751759d69..ff24b0057f6 100644 --- a/tests/ui/parser/issues/issue-104088.stderr +++ b/tests/ui/parser/issues/issue-104088.stderr @@ -22,30 +22,6 @@ help: identifiers cannot start with a number LL | let 23name = 123; | ^^ -error: expected identifier, found `2x` - --> $DIR/issue-104088.rs:12:9 - | -LL | let 2x: i32 = 123; - | ^^ expected identifier - | -help: identifiers cannot start with a number - --> $DIR/issue-104088.rs:12:9 - | -LL | let 2x: i32 = 123; - | ^ - -error: expected identifier, found `1x` - --> $DIR/issue-104088.rs:15:9 - | -LL | let 1x = 123; - | ^^ expected identifier - | -help: identifiers cannot start with a number - --> $DIR/issue-104088.rs:15:9 - | -LL | let 1x = 123; - | ^ - error[E0308]: mismatched types --> $DIR/issue-104088.rs:5:12 | @@ -54,6 +30,6 @@ LL | if let 2e1 = 123 { | | | expected integer, found floating-point number -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/parser/mut-patterns.stderr b/tests/ui/parser/mut-patterns.stderr index 66985c9f5e4..d91440d7859 100644 --- a/tests/ui/parser/mut-patterns.stderr +++ b/tests/ui/parser/mut-patterns.stderr @@ -72,43 +72,5 @@ help: escape `become` to use it as an identifier LL | let mut mut yield(r#become, await) = r#yield(0, 0); | ++ -error: expected identifier, found keyword `await` - --> $DIR/mut-patterns.rs:28:31 - | -LL | let mut mut yield(become, await) = r#yield(0, 0); - | ^^^^^ expected identifier, found keyword - | -help: escape `await` to use it as an identifier - | -LL | let mut mut yield(become, r#await) = r#yield(0, 0); - | ++ - -error: `mut` must be attached to each individual binding - --> $DIR/mut-patterns.rs:28:9 - | -LL | let mut mut yield(become, await) = r#yield(0, 0); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `mut` to each binding: `r#yield(mut r#become, mut r#await)` - | - = note: `mut` may be followed by `variable` and `variable @ pattern` - -error: `mut` must be attached to each individual binding - --> $DIR/mut-patterns.rs:37:9 - | -LL | let mut W(mut a, W(b, W(ref c, W(d, B { box f })))) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `mut` to each binding: `W(mut a, W(mut b, W(ref c, W(mut d, B { box mut f }))))` - | - = note: `mut` may be followed by `variable` and `variable @ pattern` - -error: expected identifier, found `x` - --> $DIR/mut-patterns.rs:44:21 - | -LL | let mut $p = 0; - | ^^ expected identifier -... -LL | foo!(x); - | ------- in this macro invocation - | - = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 13 previous errors +error: aborting due to 9 previous errors diff --git a/tests/ui/parser/recover/recover-parens-around-match-arm-head.stderr b/tests/ui/parser/recover/recover-parens-around-match-arm-head.stderr index 6542f440e4b..701e2cc41b6 100644 --- a/tests/ui/parser/recover/recover-parens-around-match-arm-head.stderr +++ b/tests/ui/parser/recover/recover-parens-around-match-arm-head.stderr @@ -1,49 +1,14 @@ -error: expected identifier, found keyword `if` - --> $DIR/recover-parens-around-match-arm-head.rs:4:12 - | -LL | (0 if true) => { - | ^^ expected identifier, found keyword - error: expected one of `)`, `,`, `...`, `..=`, `..`, or `|`, found keyword `if` --> $DIR/recover-parens-around-match-arm-head.rs:4:12 | LL | (0 if true) => { - | -^^ expected one of `)`, `,`, `...`, `..=`, `..`, or `|` - | | - | help: missing `,` + | ^^ expected one of `)`, `,`, `...`, `..=`, `..`, or `|` -error: expected one of `)`, `,`, `@`, or `|`, found keyword `true` - --> $DIR/recover-parens-around-match-arm-head.rs:4:15 +error: expected one of `.`, `=>`, `?`, or an operator, found `)` + --> $DIR/recover-parens-around-match-arm-head.rs:4:19 | LL | (0 if true) => { - | -^^^^ expected one of `)`, `,`, `@`, or `|` - | | - | help: missing `,` + | ^ expected one of `.`, `=>`, `?`, or an operator -error[E0308]: mismatched types - --> $DIR/recover-parens-around-match-arm-head.rs:4:9 - | -LL | let x = match val { - | --- this expression has type `{integer}` -LL | (0 if true) => { - | ^^^^^^^^^^^ expected integer, found `(_, _, _)` - | - = note: expected type `{integer}` - found tuple `(_, _, _)` +error: aborting due to 2 previous errors -error[E0308]: mismatched types - --> $DIR/recover-parens-around-match-arm-head.rs:13:19 - | -LL | let _y: u32 = x; - | --- ^ expected `u32`, found `u8` - | | - | expected due to this - | -help: you can convert a `u8` to a `u32` - | -LL | let _y: u32 = x.into(); - | +++++++ - -error: aborting due to 5 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/self/self_type_keyword.stderr b/tests/ui/self/self_type_keyword.stderr index fed853a7e1f..cdafae381ac 100644 --- a/tests/ui/self/self_type_keyword.stderr +++ b/tests/ui/self/self_type_keyword.stderr @@ -10,26 +10,6 @@ error: expected identifier, found keyword `Self` LL | ref Self => (), | ^^^^ expected identifier, found keyword -error: `mut` must be followed by a named binding - --> $DIR/self_type_keyword.rs:16:9 - | -LL | mut Self => (), - | ^^^^ help: remove the `mut` prefix - | - = note: `mut` may be followed by `variable` and `variable @ pattern` - -error: expected identifier, found keyword `Self` - --> $DIR/self_type_keyword.rs:19:17 - | -LL | ref mut Self => (), - | ^^^^ expected identifier, found keyword - -error: expected identifier, found keyword `Self` - --> $DIR/self_type_keyword.rs:23:15 - | -LL | Foo { Self } => (), - | ^^^^ expected identifier, found keyword - error: expected identifier, found keyword `Self` --> $DIR/self_type_keyword.rs:31:26 | @@ -54,24 +34,6 @@ error: lifetimes cannot use keyword names LL | struct Bar<'Self>; | ^^^^^ -error: cannot find macro `Self` in this scope - --> $DIR/self_type_keyword.rs:21:9 - | -LL | Self!() => (), - | ^^^^ - -error[E0531]: cannot find unit struct, unit variant or constant `Self` in this scope - --> $DIR/self_type_keyword.rs:16:13 - | -LL | mut Self => (), - | ^^^^ not found in this scope - | -note: unit struct `foo::Self` exists but is inaccessible - --> $DIR/self_type_keyword.rs:2:3 - | -LL | struct Self; - | ^^^^^^^^^^^^ not accessible - error[E0392]: parameter `'Self` is never used --> $DIR/self_type_keyword.rs:6:12 | @@ -80,22 +42,6 @@ LL | struct Bar<'Self>; | = help: consider removing `'Self`, referring to it in a field, or using a marker such as `PhantomData` -error[E0308]: mismatched types - --> $DIR/self_type_keyword.rs:23:9 - | -LL | match 15 { - | -- this expression has type `{integer}` -... -LL | Foo { Self } => (), - | ^^^^^^^^^^^^ expected integer, found `Foo` +error: aborting due to 7 previous errors -error[E0026]: struct `Foo` does not have a field named `Self` - --> $DIR/self_type_keyword.rs:23:15 - | -LL | Foo { Self } => (), - | ^^^^ struct `Foo` does not have this field - -error: aborting due to 14 previous errors - -Some errors have detailed explanations: E0026, E0308, E0392, E0531. -For more information about an error, try `rustc --explain E0026`. +For more information about this error, try `rustc --explain E0392`.