about summary refs log tree commit diff
path: root/compiler/rustc_ast/src/ast.rs
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2024-12-22 09:27:52 -0800
committerDavid Tolnay <dtolnay@gmail.com>2025-05-03 23:27:29 -0700
commit6cca4ca82b03f86df63b022a122377c5e95c9a2b (patch)
tree4df04af646c7a83c16c3b9c6036e4b336337fe76 /compiler/rustc_ast/src/ast.rs
parent1bea580f364c65bd5f7380a1056e150df7b8a1a6 (diff)
downloadrust-6cca4ca82b03f86df63b022a122377c5e95c9a2b.tar.gz
rust-6cca4ca82b03f86df63b022a122377c5e95c9a2b.zip
Implement asymmetrical precedence for closures and jumps
Diffstat (limited to 'compiler/rustc_ast/src/ast.rs')
-rw-r--r--compiler/rustc_ast/src/ast.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index 114b9835b98..7b1b609a084 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -1447,11 +1447,15 @@ impl Expr {
                 }
             }
 
-            ExprKind::Break(..)
-            | ExprKind::Ret(..)
-            | ExprKind::Yield(..)
-            | ExprKind::Yeet(..)
-            | ExprKind::Become(..) => ExprPrecedence::Jump,
+            ExprKind::Break(_ /*label*/, value)
+            | ExprKind::Ret(value)
+            | ExprKind::Yield(YieldKind::Prefix(value))
+            | ExprKind::Yeet(value) => match value {
+                Some(_) => ExprPrecedence::Jump,
+                None => ExprPrecedence::Unambiguous,
+            },
+
+            ExprKind::Become(_) => ExprPrecedence::Jump,
 
             // `Range` claims to have higher precedence than `Assign`, but `x .. x = x` fails to
             // parse, instead of parsing as `(x .. x) = x`. Giving `Range` a lower precedence
@@ -1508,6 +1512,7 @@ impl Expr {
             | ExprKind::Underscore
             | ExprKind::UnsafeBinderCast(..)
             | ExprKind::While(..)
+            | ExprKind::Yield(YieldKind::Postfix(..))
             | ExprKind::Err(_)
             | ExprKind::Dummy => ExprPrecedence::Unambiguous,
         }