@@ -245,19 +245,21 @@ impl<'a> State<'a> {
245
245
base_args : & [ P < ast:: Expr > ] ,
246
246
fixup : FixupContext ,
247
247
) {
248
- // Unlike in `print_expr_call`, no change to fixup here because
248
+ // The fixup here is different than in `print_expr_call` because
249
249
// statement boundaries never occur in front of a `.` (or `?`) token.
250
250
//
251
- // match () { _ => f }.method();
251
+ // Needs parens:
252
+ //
253
+ // (loop { break x; })();
254
+ //
255
+ // Does not need parens:
256
+ //
257
+ // loop { break x; }.method();
252
258
//
253
- // Parenthesizing only for precedence and not with regard to statement
254
- // boundaries, `$receiver.method()` can be parsed back as a statement
255
- // containing an expression if and only if `$receiver` can be parsed as
256
- // a statement containing an expression.
257
259
self . print_expr_cond_paren (
258
260
receiver,
259
261
receiver. precedence ( ) < ExprPrecedence :: Unambiguous ,
260
- fixup,
262
+ fixup. leftmost_subexpression_with_dot ( ) ,
261
263
) ;
262
264
263
265
self . word ( "." ) ;
@@ -503,7 +505,7 @@ impl<'a> State<'a> {
503
505
self . print_expr_cond_paren (
504
506
expr,
505
507
expr. precedence ( ) < ExprPrecedence :: Unambiguous ,
506
- fixup,
508
+ fixup. leftmost_subexpression_with_dot ( ) ,
507
509
) ;
508
510
self . word_nbsp ( ".match" ) ;
509
511
}
@@ -567,7 +569,7 @@ impl<'a> State<'a> {
567
569
self . print_expr_cond_paren (
568
570
expr,
569
571
expr. precedence ( ) < ExprPrecedence :: Unambiguous ,
570
- fixup,
572
+ fixup. leftmost_subexpression_with_dot ( ) ,
571
573
) ;
572
574
self . word ( ".await" ) ;
573
575
}
@@ -606,7 +608,7 @@ impl<'a> State<'a> {
606
608
self . print_expr_cond_paren (
607
609
expr,
608
610
expr. precedence ( ) < ExprPrecedence :: Unambiguous ,
609
- fixup,
611
+ fixup. leftmost_subexpression_with_dot ( ) ,
610
612
) ;
611
613
self . word ( "." ) ;
612
614
self . print_ident ( * ident) ;
@@ -763,7 +765,11 @@ impl<'a> State<'a> {
763
765
}
764
766
}
765
767
ast:: ExprKind :: Try ( e) => {
766
- self . print_expr_cond_paren ( e, e. precedence ( ) < ExprPrecedence :: Unambiguous , fixup) ;
768
+ self . print_expr_cond_paren (
769
+ e,
770
+ e. precedence ( ) < ExprPrecedence :: Unambiguous ,
771
+ fixup. leftmost_subexpression_with_dot ( ) ,
772
+ ) ;
767
773
self . word ( "?" )
768
774
}
769
775
ast:: ExprKind :: TryBlock ( blk) => {
0 commit comments