Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 3, 2019
1 parent dfdc369 commit f1499a8
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions src/libsyntax/parse/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,11 @@ impl<'a> Parser<'a> {
"check_no_chained_comparison: {:?} is not comparison",
outer_op,
);

let mk_err_expr = |this: &Self, span| {
Ok(Some(this.mk_expr(span, ExprKind::Err, ThinVec::new())))
};

match lhs.kind {
ExprKind::Binary(op, _, _) if op.node.is_comparison() => {
// Respan to include both operators.
Expand Down Expand Up @@ -601,7 +606,7 @@ impl<'a> Parser<'a> {
(token::Gt, -1),
(token::BinOp(token::Shr), -2),
];
self.consume_tts(1, &modifiers[..], &[]);
self.consume_tts(1, &modifiers[..]);

if !&[
token::OpenDelim(token::Paren),
Expand All @@ -612,7 +617,7 @@ impl<'a> Parser<'a> {
mem::replace(self, snapshot.clone());
}
}
if token::ModSep == self.token.kind {
return if token::ModSep == self.token.kind {
// We have some certainty that this was a bad turbofish at this point.
// `foo< bar >::`
suggest(&mut err);
Expand All @@ -628,18 +633,14 @@ impl<'a> Parser<'a> {
// FIXME: actually check that the two expressions in the binop are
// paths and resynthesize new fn call expression instead of using
// `ExprKind::Err` placeholder.
return Ok(Some(self.mk_expr(
lhs.span.to(self.prev_span),
ExprKind::Err,
ThinVec::new(),
)));
mk_err_expr(self, lhs.span.to(self.prev_span))
}
Err(mut expr_err) => {
expr_err.cancel();
// Not entirely sure now, but we bubble the error up with the
// suggestion.
mem::replace(self, snapshot);
return Err(err);
Err(err)
}
}
} else if token::OpenDelim(token::Paren) == self.token.kind {
Expand All @@ -655,9 +656,9 @@ impl<'a> Parser<'a> {
(token::OpenDelim(token::Paren), 1),
(token::CloseDelim(token::Paren), -1),
];
self.consume_tts(1, &modifiers[..], &[]);
self.consume_tts(1, &modifiers[..]);

return if self.token.kind == token::Eof {
if self.token.kind == token::Eof {
// Not entirely sure now, but we bubble the error up with the
// suggestion.
mem::replace(self, snapshot);
Expand All @@ -668,20 +669,16 @@ impl<'a> Parser<'a> {
// FIXME: actually check that the two expressions in the binop are
// paths and resynthesize new fn call expression instead of using
// `ExprKind::Err` placeholder.
Ok(Some(self.mk_expr(
lhs.span.to(self.prev_span),
ExprKind::Err,
ThinVec::new(),
)))
mk_err_expr(self, lhs.span.to(self.prev_span))
}
} else {
// All we know is that this is `foo < bar >` and *nothing* else. Try to
// be helpful, but don't attempt to recover.
err.help(TURBOFISH);
err.help("or use `(...)` if you meant to specify fn arguments");
// These cases cause too many knock-down errors, bail out (#61329).
}
return Err(err);
Err(err)
};
}
err.emit();
}
Expand Down Expand Up @@ -1467,14 +1464,14 @@ impl<'a> Parser<'a> {
fn consume_tts(
&mut self,
mut acc: i64, // `i64` because malformed code can have more closing delims than opening.
modifier: &[(token::TokenKind, i64)], // Not using `FxHashMap` and `FxHashSet` due to
early_return: &[token::TokenKind], // `token::TokenKind: !Eq + !Hash`.
// Not using `FxHashMap` due to `token::TokenKind: !Eq + !Hash`.
modifier: &[(token::TokenKind, i64)],
) {
while acc > 0 {
if let Some((_, val)) = modifier.iter().find(|(t, _)| *t == self.token.kind) {
acc += *val;
}
if self.token.kind == token::Eof || early_return.contains(&self.token.kind) {
if self.token.kind == token::Eof {
break;
}
self.bump();
Expand Down

0 comments on commit f1499a8

Please sign in to comment.