review comment: move logic to new method
This commit is contained in:
parent
c09c73b996
commit
6913194b8e
1 changed files with 103 additions and 88 deletions
|
@ -515,13 +515,37 @@ impl<'a> Parser<'a> {
|
||||||
} else {
|
} else {
|
||||||
stmt.span
|
stmt.span
|
||||||
};
|
};
|
||||||
match (&self.token.kind, &stmt.kind) {
|
self.suggest_fixes_misparsed_for_loop_head(
|
||||||
|
&mut e,
|
||||||
|
prev.between(sp),
|
||||||
|
stmt_span,
|
||||||
|
&stmt.kind,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
self.recover_stmt_(SemiColonMode::Break, BlockMode::Ignore);
|
||||||
|
e.cancel();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
e.span_label(sp, "expected `{`");
|
||||||
|
e
|
||||||
|
}
|
||||||
|
|
||||||
|
fn suggest_fixes_misparsed_for_loop_head(
|
||||||
|
&self,
|
||||||
|
e: &mut Diag<'_>,
|
||||||
|
between: Span,
|
||||||
|
stmt_span: Span,
|
||||||
|
stmt_kind: &StmtKind,
|
||||||
|
) {
|
||||||
|
match (&self.token.kind, &stmt_kind) {
|
||||||
(token::OpenDelim(Delimiter::Brace), StmtKind::Expr(expr))
|
(token::OpenDelim(Delimiter::Brace), StmtKind::Expr(expr))
|
||||||
if let ExprKind::Call(..) = expr.kind =>
|
if let ExprKind::Call(..) = expr.kind =>
|
||||||
{
|
{
|
||||||
// for _ in x y() {}
|
// for _ in x y() {}
|
||||||
e.span_suggestion_verbose(
|
e.span_suggestion_verbose(
|
||||||
prev.between(sp),
|
between,
|
||||||
"you might have meant to write a method call",
|
"you might have meant to write a method call",
|
||||||
".".to_string(),
|
".".to_string(),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
|
@ -532,7 +556,7 @@ impl<'a> Parser<'a> {
|
||||||
{
|
{
|
||||||
// for _ in x y.z {}
|
// for _ in x y.z {}
|
||||||
e.span_suggestion_verbose(
|
e.span_suggestion_verbose(
|
||||||
prev.between(sp),
|
between,
|
||||||
"you might have meant to write a field access",
|
"you might have meant to write a field access",
|
||||||
".".to_string(),
|
".".to_string(),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
|
@ -547,7 +571,7 @@ impl<'a> Parser<'a> {
|
||||||
//
|
//
|
||||||
// for _ in x y {}
|
// for _ in x y {}
|
||||||
e.span_suggestion_verbose(
|
e.span_suggestion_verbose(
|
||||||
prev.between(sp),
|
between,
|
||||||
"you might have meant to write a field access",
|
"you might have meant to write a field access",
|
||||||
".".to_string(),
|
".".to_string(),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
|
@ -561,7 +585,7 @@ impl<'a> Parser<'a> {
|
||||||
// for _ in x 0 {}
|
// for _ in x 0 {}
|
||||||
// for _ in x 0.0 {}
|
// for _ in x 0.0 {}
|
||||||
e.span_suggestion_verbose(
|
e.span_suggestion_verbose(
|
||||||
prev.between(sp),
|
between,
|
||||||
format!("you might have meant to write a field access"),
|
format!("you might have meant to write a field access"),
|
||||||
".".to_string(),
|
".".to_string(),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
|
@ -604,15 +628,6 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
|
||||||
self.recover_stmt_(SemiColonMode::Break, BlockMode::Ignore);
|
|
||||||
e.cancel();
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
e.span_label(sp, "expected `{`");
|
|
||||||
e
|
|
||||||
}
|
|
||||||
|
|
||||||
fn error_block_no_opening_brace<T>(&mut self) -> PResult<'a, T> {
|
fn error_block_no_opening_brace<T>(&mut self) -> PResult<'a, T> {
|
||||||
let tok = super::token_descr(&self.token);
|
let tok = super::token_descr(&self.token);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue