diff options
| author | Reese Williams <reese@reesew.io> | 2021-01-20 21:49:11 -0500 |
|---|---|---|
| committer | Reese Williams <reese@reesew.io> | 2021-01-20 23:06:19 -0500 |
| commit | 8a83c8f64f717f7cf569f589b42c6535591f8854 (patch) | |
| tree | 37017ad48316cd09df1fca14669b834e755cf552 /compiler/rustc_parse/src | |
| parent | 058a71016553f267ae80b90276ef79956457d51a (diff) | |
| download | rust-8a83c8f64f717f7cf569f589b42c6535591f8854.tar.gz rust-8a83c8f64f717f7cf569f589b42c6535591f8854.zip | |
Improve suggestion for tuple struct pattern matching errors.
Currently, when a user uses a struct pattern to pattern match on a tuple struct, the errors we emit generally suggest adding fields using their field names, which are numbers. However, numbers are not valid identifiers, so the suggestions, which use the shorthand notation, are not valid syntax. This commit changes those errors to suggest using the actual tuple struct pattern syntax instead, which is a more actionable suggestion.
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/pat.rs | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 45964b1c988..d8be90cd845 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -932,7 +932,7 @@ impl<'a> Parser<'a> { self.bump(); Ok(Ident::new(symbol, self.prev_token.span)) } else { - self.parse_ident_common(false) + self.parse_ident_common(true) } } diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 456e32680fe..15b67ca9faf 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -999,7 +999,7 @@ impl<'a> Parser<'a> { let boxed_span = self.token.span; let is_ref = self.eat_keyword(kw::Ref); let is_mut = self.eat_keyword(kw::Mut); - let fieldname = self.parse_ident()?; + let fieldname = self.parse_field_name()?; hi = self.prev_token.span; let bind_type = match (is_ref, is_mut) { |
