Recover from mutable variable declaration where mut
is placed before let
This commit is contained in:
parent
9ee22ff7e8
commit
ea2df3a798
1 changed files with 13 additions and 0 deletions
|
@ -55,6 +55,19 @@ impl<'a> Parser<'a> {
|
|||
return Ok(Some(stmt.into_inner()));
|
||||
}
|
||||
|
||||
if self.token.is_keyword(kw::Mut) && self.is_keyword_ahead(1, &[kw::Let]) {
|
||||
self.bump();
|
||||
let mut_let_span = lo.to(self.token.span);
|
||||
self.struct_span_err(mut_let_span, "invalid variable declaration")
|
||||
.span_suggestion(
|
||||
mut_let_span,
|
||||
"switch the order of `mut` and `let`",
|
||||
"let mut",
|
||||
Applicability::MaybeIncorrect,
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
|
||||
Ok(Some(if self.token.is_keyword(kw::Let) {
|
||||
self.parse_local_mk(lo, attrs, capture_semi, force_collect)?
|
||||
} else if self.is_kw_followed_by_ident(kw::Mut) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue