Skip to content

Commit f1499a8

Browse files
committed
review comments
1 parent dfdc369 commit f1499a8

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

src/libsyntax/parse/diagnostics.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,11 @@ impl<'a> Parser<'a> {
570570
"check_no_chained_comparison: {:?} is not comparison",
571571
outer_op,
572572
);
573+
574+
let mk_err_expr = |this: &Self, span| {
575+
Ok(Some(this.mk_expr(span, ExprKind::Err, ThinVec::new())))
576+
};
577+
573578
match lhs.kind {
574579
ExprKind::Binary(op, _, _) if op.node.is_comparison() => {
575580
// Respan to include both operators.
@@ -601,7 +606,7 @@ impl<'a> Parser<'a> {
601606
(token::Gt, -1),
602607
(token::BinOp(token::Shr), -2),
603608
];
604-
self.consume_tts(1, &modifiers[..], &[]);
609+
self.consume_tts(1, &modifiers[..]);
605610

606611
if !&[
607612
token::OpenDelim(token::Paren),
@@ -612,7 +617,7 @@ impl<'a> Parser<'a> {
612617
mem::replace(self, snapshot.clone());
613618
}
614619
}
615-
if token::ModSep == self.token.kind {
620+
return if token::ModSep == self.token.kind {
616621
// We have some certainty that this was a bad turbofish at this point.
617622
// `foo< bar >::`
618623
suggest(&mut err);
@@ -628,18 +633,14 @@ impl<'a> Parser<'a> {
628633
// FIXME: actually check that the two expressions in the binop are
629634
// paths and resynthesize new fn call expression instead of using
630635
// `ExprKind::Err` placeholder.
631-
return Ok(Some(self.mk_expr(
632-
lhs.span.to(self.prev_span),
633-
ExprKind::Err,
634-
ThinVec::new(),
635-
)));
636+
mk_err_expr(self, lhs.span.to(self.prev_span))
636637
}
637638
Err(mut expr_err) => {
638639
expr_err.cancel();
639640
// Not entirely sure now, but we bubble the error up with the
640641
// suggestion.
641642
mem::replace(self, snapshot);
642-
return Err(err);
643+
Err(err)
643644
}
644645
}
645646
} else if token::OpenDelim(token::Paren) == self.token.kind {
@@ -655,9 +656,9 @@ impl<'a> Parser<'a> {
655656
(token::OpenDelim(token::Paren), 1),
656657
(token::CloseDelim(token::Paren), -1),
657658
];
658-
self.consume_tts(1, &modifiers[..], &[]);
659+
self.consume_tts(1, &modifiers[..]);
659660

660-
return if self.token.kind == token::Eof {
661+
if self.token.kind == token::Eof {
661662
// Not entirely sure now, but we bubble the error up with the
662663
// suggestion.
663664
mem::replace(self, snapshot);
@@ -668,20 +669,16 @@ impl<'a> Parser<'a> {
668669
// FIXME: actually check that the two expressions in the binop are
669670
// paths and resynthesize new fn call expression instead of using
670671
// `ExprKind::Err` placeholder.
671-
Ok(Some(self.mk_expr(
672-
lhs.span.to(self.prev_span),
673-
ExprKind::Err,
674-
ThinVec::new(),
675-
)))
672+
mk_err_expr(self, lhs.span.to(self.prev_span))
676673
}
677674
} else {
678675
// All we know is that this is `foo < bar >` and *nothing* else. Try to
679676
// be helpful, but don't attempt to recover.
680677
err.help(TURBOFISH);
681678
err.help("or use `(...)` if you meant to specify fn arguments");
682679
// These cases cause too many knock-down errors, bail out (#61329).
683-
}
684-
return Err(err);
680+
Err(err)
681+
};
685682
}
686683
err.emit();
687684
}
@@ -1467,14 +1464,14 @@ impl<'a> Parser<'a> {
14671464
fn consume_tts(
14681465
&mut self,
14691466
mut acc: i64, // `i64` because malformed code can have more closing delims than opening.
1470-
modifier: &[(token::TokenKind, i64)], // Not using `FxHashMap` and `FxHashSet` due to
1471-
early_return: &[token::TokenKind], // `token::TokenKind: !Eq + !Hash`.
1467+
// Not using `FxHashMap` due to `token::TokenKind: !Eq + !Hash`.
1468+
modifier: &[(token::TokenKind, i64)],
14721469
) {
14731470
while acc > 0 {
14741471
if let Some((_, val)) = modifier.iter().find(|(t, _)| *t == self.token.kind) {
14751472
acc += *val;
14761473
}
1477-
if self.token.kind == token::Eof || early_return.contains(&self.token.kind) {
1474+
if self.token.kind == token::Eof {
14781475
break;
14791476
}
14801477
self.bump();

0 commit comments

Comments
 (0)