@@ -213,7 +213,9 @@ impl<'a> State<'a> {
213
213
214
214
fn print_expr_call ( & mut self , func : & ast:: Expr , args : & [ P < ast:: Expr > ] , fixup : FixupContext ) {
215
215
let needs_paren = match func. kind {
216
- ast:: ExprKind :: Field ( ..) => true ,
216
+ // In order to call a named field, needs parens: `(self.fun)()`
217
+ // But not for an unnamed field: `self.0()`
218
+ ast:: ExprKind :: Field ( _, name) => !name. is_numeric ( ) ,
217
219
_ => func. precedence ( ) < ExprPrecedence :: Unambiguous ,
218
220
} ;
219
221
@@ -245,19 +247,21 @@ impl<'a> State<'a> {
245
247
base_args : & [ P < ast:: Expr > ] ,
246
248
fixup : FixupContext ,
247
249
) {
248
- // Unlike in `print_expr_call`, no change to fixup here because
250
+ // The fixup here is different than in `print_expr_call` because
249
251
// statement boundaries never occur in front of a `.` (or `?`) token.
250
252
//
251
- // match () { _ => f }.method();
253
+ // Needs parens:
254
+ //
255
+ // (loop { break x; })();
256
+ //
257
+ // Does not need parens:
258
+ //
259
+ // loop { break x; }.method();
252
260
//
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
261
self . print_expr_cond_paren (
258
262
receiver,
259
263
receiver. precedence ( ) < ExprPrecedence :: Unambiguous ,
260
- fixup,
264
+ fixup. leftmost_subexpression_with_dot ( ) ,
261
265
) ;
262
266
263
267
self . word ( "." ) ;
@@ -503,7 +507,7 @@ impl<'a> State<'a> {
503
507
self . print_expr_cond_paren (
504
508
expr,
505
509
expr. precedence ( ) < ExprPrecedence :: Unambiguous ,
506
- fixup,
510
+ fixup. leftmost_subexpression_with_dot ( ) ,
507
511
) ;
508
512
self . word_nbsp ( ".match" ) ;
509
513
}
@@ -567,7 +571,7 @@ impl<'a> State<'a> {
567
571
self . print_expr_cond_paren (
568
572
expr,
569
573
expr. precedence ( ) < ExprPrecedence :: Unambiguous ,
570
- fixup,
574
+ fixup. leftmost_subexpression_with_dot ( ) ,
571
575
) ;
572
576
self . word ( ".await" ) ;
573
577
}
@@ -606,7 +610,7 @@ impl<'a> State<'a> {
606
610
self . print_expr_cond_paren (
607
611
expr,
608
612
expr. precedence ( ) < ExprPrecedence :: Unambiguous ,
609
- fixup,
613
+ fixup. leftmost_subexpression_with_dot ( ) ,
610
614
) ;
611
615
self . word ( "." ) ;
612
616
self . print_ident ( * ident) ;
@@ -763,7 +767,11 @@ impl<'a> State<'a> {
763
767
}
764
768
}
765
769
ast:: ExprKind :: Try ( e) => {
766
- self . print_expr_cond_paren ( e, e. precedence ( ) < ExprPrecedence :: Unambiguous , fixup) ;
770
+ self . print_expr_cond_paren (
771
+ e,
772
+ e. precedence ( ) < ExprPrecedence :: Unambiguous ,
773
+ fixup. leftmost_subexpression_with_dot ( ) ,
774
+ ) ;
767
775
self . word ( "?" )
768
776
}
769
777
ast:: ExprKind :: TryBlock ( blk) => {
0 commit comments