diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2017-07-26 18:59:07 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2017-07-26 18:59:07 +0300 |
| commit | dda30f690206870ed6f8fc14216e92cdc1f2687a (patch) | |
| tree | 2848e2502c4f6f195be82c9ea9079a283a9288d4 /src/libsyntax/parse | |
| parent | bad58f27916e7e233cc2916dcc9167708077e792 (diff) | |
| download | rust-dda30f690206870ed6f8fc14216e92cdc1f2687a.tar.gz rust-dda30f690206870ed6f8fc14216e92cdc1f2687a.zip | |
Better diagnostics and recovery for `mut ref` in patterns
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d6a57c2874f..a48d2dcf1c1 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3523,8 +3523,18 @@ impl<'a> Parser<'a> { } // At this point, token != _, &, &&, (, [ _ => if self.eat_keyword(keywords::Mut) { - // Parse mut ident @ pat - pat = self.parse_pat_ident(BindingMode::ByValue(Mutability::Mutable))?; + // Parse mut ident @ pat / mut ref ident @ pat + let mutref_span = self.prev_span.to(self.span); + let binding_mode = if self.eat_keyword(keywords::Ref) { + self.diagnostic() + .struct_span_err(mutref_span, "the order of `mut` and `ref` is incorrect") + .span_suggestion(mutref_span, "try switching the order", "ref mut".into()) + .emit(); + BindingMode::ByRef(Mutability::Mutable) + } else { + BindingMode::ByValue(Mutability::Mutable) + }; + pat = self.parse_pat_ident(binding_mode)?; } else if self.eat_keyword(keywords::Ref) { // Parse ref ident @ pat / ref mut ident @ pat let mutbl = self.parse_mutability(); |
