diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-17 16:03:07 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-17 16:08:13 +0100 |
| commit | 0b1e08cb557768f168266c7bbcdcb93fcf372a66 (patch) | |
| tree | 6e1f2aa851a0c8531e1562899b25aae4e097120c /src/librustc_parse/parser | |
| parent | 75b98fbe77d472d85d1691bae5b25e7eefb3609c (diff) | |
| download | rust-0b1e08cb557768f168266c7bbcdcb93fcf372a66.tar.gz rust-0b1e08cb557768f168266c7bbcdcb93fcf372a66.zip | |
parse: recover `mut (x @ y)` as `(mut x @ mut y)`.
Diffstat (limited to 'src/librustc_parse/parser')
| -rw-r--r-- | src/librustc_parse/parser/pat.rs | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/librustc_parse/parser/pat.rs b/src/librustc_parse/parser/pat.rs index ec6d4db6102..520d325f16b 100644 --- a/src/librustc_parse/parser/pat.rs +++ b/src/librustc_parse/parser/pat.rs @@ -503,17 +503,18 @@ impl<'a> Parser<'a> { // Parse the pattern we hope to be an identifier. let mut pat = self.parse_pat(Some("identifier"))?; - // Add `mut` to any binding in the parsed pattern. - let changed_any_binding = Self::make_all_value_bindings_mutable(&mut pat); - - // Unwrap; If we don't have `mut $ident`, error. - let pat = pat.into_inner(); - match &pat.kind { - PatKind::Ident(..) => {} - _ => self.ban_mut_general_pat(mut_span, &pat, changed_any_binding), + // If we don't have `mut $ident (@ pat)?`, error. + if let PatKind::Ident(BindingMode::ByValue(m @ Mutability::Not), ..) = &mut pat.kind { + // Don't recurse into the subpattern. + // `mut` on the outer binding doesn't affect the inner bindings. + *m = Mutability::Mut; + } else { + // Add `mut` to any binding in the parsed pattern. + let changed_any_binding = Self::make_all_value_bindings_mutable(&mut pat); + self.ban_mut_general_pat(mut_span, &pat, changed_any_binding); } - Ok(pat.kind) + Ok(pat.into_inner().kind) } /// Recover on `mut ref? ident @ pat` and suggest @@ -542,14 +543,10 @@ impl<'a> Parser<'a> { } fn visit_pat(&mut self, pat: &mut P<Pat>) { - if let PatKind::Ident(ref mut bm, ..) = pat.kind { - if let BindingMode::ByValue(ref mut m @ Mutability::Not) = bm { - *m = Mutability::Mut; - } + if let PatKind::Ident(BindingMode::ByValue(m @ Mutability::Not), ..) = &mut pat.kind + { self.0 = true; - // Don't recurse into the subpattern, mut on the outer - // binding doesn't affect the inner bindings. - return; + *m = Mutability::Mut; } noop_visit_pat(pat, self); } |
