@@ -562,17 +562,23 @@ impl<'a> Parser<'a> {
562
562
563
563
// Note: when adding new unary operators, don't forget to adjust TokenKind::can_begin_expr()
564
564
match this.token.uninterpolate().kind {
565
- token::Not => make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Not)), // `!expr`
566
- token::Tilde => make_it!(this, attrs, |this, _| this.recover_tilde_expr(lo)), // `~expr`
565
+ // `!expr`
566
+ token::Not => make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Not)),
567
+ // `~expr`
568
+ token::Tilde => make_it!(this, attrs, |this, _| this.recover_tilde_expr(lo)),
569
+ // `-expr`
567
570
token::BinOp(token::Minus) => {
568
571
make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Neg))
569
- } // `-expr`
572
+ }
573
+ // `*expr`
570
574
token::BinOp(token::Star) => {
571
575
make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Deref))
572
- } // `*expr`
576
+ }
577
+ // `&expr` and `&&expr`
573
578
token::BinOp(token::And) | token::AndAnd => {
574
579
make_it!(this, attrs, |this, _| this.parse_borrow_expr(lo))
575
580
}
581
+ // `+lit`
576
582
token::BinOp(token::Plus) if this.look_ahead(1, |tok| tok.is_numeric_lit()) => {
577
583
let mut err =
578
584
LeadingPlusNotSupported { span: lo, remove_plus: None, add_parentheses: None };
@@ -587,7 +593,7 @@ impl<'a> Parser<'a> {
587
593
588
594
this.bump();
589
595
this.parse_prefix_expr(None)
590
- } // `+expr`
596
+ }
591
597
// Recover from `++x`:
592
598
token::BinOp(token::Plus)
593
599
if this.look_ahead(1, |t| *t == token::BinOp(token::Plus)) =>
@@ -624,7 +630,7 @@ impl<'a> Parser<'a> {
624
630
Ok((span, self.mk_unary(op, expr)))
625
631
}
626
632
627
- // Recover on `!` suggesting for bitwise negation instead .
633
+ /// Recover on `~expr` in favor of `!expr` .
628
634
fn recover_tilde_expr(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)> {
629
635
self.sess.emit_err(TildeAsUnaryOperator(lo));
630
636
@@ -651,7 +657,6 @@ impl<'a> Parser<'a> {
651
657
652
658
/// Recover on `not expr` in favor of `!expr`.
653
659
fn recover_not_expr(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)> {
654
- // Emit the error...
655
660
let negated_token = self.look_ahead(1, |t| t.clone());
656
661
657
662
let sub_diag = if negated_token.is_numeric_lit() {
@@ -672,7 +677,6 @@ impl<'a> Parser<'a> {
672
677
),
673
678
});
674
679
675
- // ...and recover!
676
680
self.parse_unary_expr(lo, UnOp::Not)
677
681
}
678
682
@@ -1593,7 +1597,7 @@ impl<'a> Parser<'a> {
1593
1597
vis.0
1594
1598
};
1595
1599
1596
- // Suggestion involves adding a (as of time of writing this, unstable) labeled block.
1600
+ // Suggestion involves adding a labeled block.
1597
1601
//
1598
1602
// If there are no breaks that may use this label, suggest removing the label and
1599
1603
// recover to the unmodified expression.
0 commit comments