about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2024-12-02 17:17:37 -0800
committerDavid Tolnay <dtolnay@gmail.com>2024-12-02 17:33:20 -0800
commit193d82797cfa88eb49d53c16745423de6bc54851 (patch)
tree8663314918ce629b24063006f1143ed716f4cd4a
parentf3ac64ac342fca3040e067a9e3c3c8aba9186860 (diff)
downloadrust-193d82797cfa88eb49d53c16745423de6bc54851.tar.gz
rust-193d82797cfa88eb49d53c16745423de6bc54851.zip
Squash closures and jumps into a single precedence level
-rw-r--r--compiler/rustc_ast/src/ast.rs3
-rw-r--r--compiler/rustc_ast/src/util/parser.rs3
-rw-r--r--compiler/rustc_hir/src/hir.rs3
-rw-r--r--tests/ui-fulldeps/pprust-parenthesis-insertion.rs2
4 files changed, 4 insertions, 7 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index 14205f66491..2c9e55e007f 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -1317,9 +1317,8 @@ impl Expr {
 
     pub fn precedence(&self) -> ExprPrecedence {
         match self.kind {
-            ExprKind::Closure(..) => ExprPrecedence::Closure,
-
             ExprKind::Break(..)
+            | ExprKind::Closure(..)
             | ExprKind::Continue(..)
             | ExprKind::Ret(..)
             | ExprKind::Yield(..)
diff --git a/compiler/rustc_ast/src/util/parser.rs b/compiler/rustc_ast/src/util/parser.rs
index e88bf27021a..a4f152b4687 100644
--- a/compiler/rustc_ast/src/util/parser.rs
+++ b/compiler/rustc_ast/src/util/parser.rs
@@ -231,8 +231,7 @@ impl AssocOp {
 
 #[derive(Clone, Copy, PartialEq, PartialOrd)]
 pub enum ExprPrecedence {
-    Closure,
-    // return, break, yield
+    // return, break, yield, closures
     Jump,
     // = += -= *= /= %= &= |= ^= <<= >>=
     Assign,
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index a9696627f11..4524e1cbdf1 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -1697,9 +1697,8 @@ pub struct Expr<'hir> {
 impl Expr<'_> {
     pub fn precedence(&self) -> ExprPrecedence {
         match self.kind {
-            ExprKind::Closure { .. } => ExprPrecedence::Closure,
-
             ExprKind::Break(..)
+            | ExprKind::Closure { .. }
             | ExprKind::Continue(..)
             | ExprKind::Ret(..)
             | ExprKind::Yield(..)
diff --git a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs
index d545c017fda..f535db06879 100644
--- a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs
+++ b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs
@@ -72,7 +72,7 @@ static EXPRS: &[&str] = &[
     "(return) - 2",
     // Closures and jumps have equal precedence.
     "|| return break 2",
-    "return break (|| 2)", // FIXME: no parenthesis needed.
+    "return break || 2",
     // These mean different things.
     "if let _ = true && false {}",
     "if let _ = (true && false) {}",