Skip to content

Commit f7850c5

Browse files
committed
Improve comments in parser/expr.rs
1 parent ecb1ad1 commit f7850c5

File tree

1 file changed

+13
-9
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+13
-9
lines changed

compiler/rustc_parse/src/parser/expr.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -562,17 +562,23 @@ impl<'a> Parser<'a> {
562562

563563
// Note: when adding new unary operators, don't forget to adjust TokenKind::can_begin_expr()
564564
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`
567570
token::BinOp(token::Minus) => {
568571
make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Neg))
569-
} // `-expr`
572+
}
573+
// `*expr`
570574
token::BinOp(token::Star) => {
571575
make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Deref))
572-
} // `*expr`
576+
}
577+
// `&expr` and `&&expr`
573578
token::BinOp(token::And) | token::AndAnd => {
574579
make_it!(this, attrs, |this, _| this.parse_borrow_expr(lo))
575580
}
581+
// `+lit`
576582
token::BinOp(token::Plus) if this.look_ahead(1, |tok| tok.is_numeric_lit()) => {
577583
let mut err =
578584
LeadingPlusNotSupported { span: lo, remove_plus: None, add_parentheses: None };
@@ -587,7 +593,7 @@ impl<'a> Parser<'a> {
587593

588594
this.bump();
589595
this.parse_prefix_expr(None)
590-
} // `+expr`
596+
}
591597
// Recover from `++x`:
592598
token::BinOp(token::Plus)
593599
if this.look_ahead(1, |t| *t == token::BinOp(token::Plus)) =>
@@ -624,7 +630,7 @@ impl<'a> Parser<'a> {
624630
Ok((span, self.mk_unary(op, expr)))
625631
}
626632

627-
// Recover on `!` suggesting for bitwise negation instead.
633+
/// Recover on `~expr` in favor of `!expr`.
628634
fn recover_tilde_expr(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)> {
629635
self.sess.emit_err(TildeAsUnaryOperator(lo));
630636

@@ -651,7 +657,6 @@ impl<'a> Parser<'a> {
651657

652658
/// Recover on `not expr` in favor of `!expr`.
653659
fn recover_not_expr(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)> {
654-
// Emit the error...
655660
let negated_token = self.look_ahead(1, |t| t.clone());
656661

657662
let sub_diag = if negated_token.is_numeric_lit() {
@@ -672,7 +677,6 @@ impl<'a> Parser<'a> {
672677
),
673678
});
674679

675-
// ...and recover!
676680
self.parse_unary_expr(lo, UnOp::Not)
677681
}
678682

@@ -1593,7 +1597,7 @@ impl<'a> Parser<'a> {
15931597
vis.0
15941598
};
15951599

1596-
// Suggestion involves adding a (as of time of writing this, unstable) labeled block.
1600+
// Suggestion involves adding a labeled block.
15971601
//
15981602
// If there are no breaks that may use this label, suggest removing the label and
15991603
// recover to the unmodified expression.

0 commit comments

Comments
 (0)