about summary refs log tree commit diff
path: root/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_ast_pretty/src/pprust/state/expr.rs')
-rw-r--r--compiler/rustc_ast_pretty/src/pprust/state/expr.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
index dce76fb1e77..ab1dd46fe33 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
@@ -245,19 +245,21 @@ impl<'a> State<'a> {
         base_args: &[P<ast::Expr>],
         fixup: FixupContext,
     ) {
-        // Unlike in `print_expr_call`, no change to fixup here because
+        // The fixup here is different than in `print_expr_call` because
         // statement boundaries never occur in front of a `.` (or `?`) token.
         //
-        //     match () { _ => f }.method();
+        // Needs parens:
+        //
+        //     (loop { break x; })();
+        //
+        // Does not need parens:
+        //
+        //     loop { break x; }.method();
         //
-        // Parenthesizing only for precedence and not with regard to statement
-        // boundaries, `$receiver.method()` can be parsed back as a statement
-        // containing an expression if and only if `$receiver` can be parsed as
-        // a statement containing an expression.
         self.print_expr_cond_paren(
             receiver,
             receiver.precedence() < ExprPrecedence::Unambiguous,
-            fixup,
+            fixup.leftmost_subexpression_with_dot(),
         );
 
         self.word(".");
@@ -503,7 +505,7 @@ impl<'a> State<'a> {
                         self.print_expr_cond_paren(
                             expr,
                             expr.precedence() < ExprPrecedence::Unambiguous,
-                            fixup,
+                            fixup.leftmost_subexpression_with_dot(),
                         );
                         self.word_nbsp(".match");
                     }
@@ -567,7 +569,7 @@ impl<'a> State<'a> {
                 self.print_expr_cond_paren(
                     expr,
                     expr.precedence() < ExprPrecedence::Unambiguous,
-                    fixup,
+                    fixup.leftmost_subexpression_with_dot(),
                 );
                 self.word(".await");
             }
@@ -606,7 +608,7 @@ impl<'a> State<'a> {
                 self.print_expr_cond_paren(
                     expr,
                     expr.precedence() < ExprPrecedence::Unambiguous,
-                    fixup,
+                    fixup.leftmost_subexpression_with_dot(),
                 );
                 self.word(".");
                 self.print_ident(*ident);
@@ -763,7 +765,11 @@ impl<'a> State<'a> {
                 }
             }
             ast::ExprKind::Try(e) => {
-                self.print_expr_cond_paren(e, e.precedence() < ExprPrecedence::Unambiguous, fixup);
+                self.print_expr_cond_paren(
+                    e,
+                    e.precedence() < ExprPrecedence::Unambiguous,
+                    fixup.leftmost_subexpression_with_dot(),
+                );
                 self.word("?")
             }
             ast::ExprKind::TryBlock(blk) => {