about summary refs log tree commit diff
path: root/compiler/rustc_ast
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2024-12-02 17:41:47 -0800
committerDavid Tolnay <dtolnay@gmail.com>2024-12-02 17:48:16 -0800
commit72ac961616f23401c54f08436006250fd1fcdb9e (patch)
tree3e3248e170619d7c813f935b15658f8bc109d2f3 /compiler/rustc_ast
parent4df47a09a42620f018bdaed733fdbc4049a65e78 (diff)
downloadrust-72ac961616f23401c54f08436006250fd1fcdb9e.tar.gz
rust-72ac961616f23401c54f08436006250fd1fcdb9e.zip
Raise precedence of closure that has explicit return type
Diffstat (limited to 'compiler/rustc_ast')
-rw-r--r--compiler/rustc_ast/src/ast.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index 2c9e55e007f..482efa132ab 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -1316,9 +1316,15 @@ impl Expr {
     }
 
     pub fn precedence(&self) -> ExprPrecedence {
-        match self.kind {
+        match &self.kind {
+            ExprKind::Closure(closure) => {
+                match closure.fn_decl.output {
+                    FnRetTy::Default(_) => ExprPrecedence::Jump,
+                    FnRetTy::Ty(_) => ExprPrecedence::Unambiguous,
+                }
+            }
+
             ExprKind::Break(..)
-            | ExprKind::Closure(..)
             | ExprKind::Continue(..)
             | ExprKind::Ret(..)
             | ExprKind::Yield(..)