about summary refs log tree commit diff
path: root/compiler/rustc_ast/src/ast.rs
diff options
context:
space:
mode:
authorBoxy <rust@boxyuwu.dev>2024-09-15 21:21:31 +0100
committerBoxy <rust@boxyuwu.dev>2024-09-21 22:17:18 +0100
commit781ec111b728a4d1ae513ae57d5eecf27680a216 (patch)
tree97284d51e31a3e0fcdc7a9d430d58068d0fb5f63 /compiler/rustc_ast/src/ast.rs
parent1d68e6dd1deef26c5aeb91aee554edbee8b6d5e2 (diff)
downloadrust-781ec111b728a4d1ae513ae57d5eecf27680a216.tar.gz
rust-781ec111b728a4d1ae513ae57d5eecf27680a216.zip
Handle macro calls in anon const def creation take 2
Diffstat (limited to 'compiler/rustc_ast/src/ast.rs')
-rw-r--r--compiler/rustc_ast/src/ast.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index ac65b7b22bc..d49265de202 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -1187,8 +1187,8 @@ impl Expr {
     /// `min_const_generics` as more complex expressions are not supported.
     ///
     /// Does not ensure that the path resolves to a const param, the caller should check this.
-    pub fn is_potential_trivial_const_arg(&self) -> bool {
-        let this = self.maybe_unwrap_block();
+    pub fn is_potential_trivial_const_arg(&self, strip_identity_block: bool) -> bool {
+        let this = if strip_identity_block { self.maybe_unwrap_block().1 } else { self };
 
         if let ExprKind::Path(None, path) = &this.kind
             && path.is_potential_trivial_const_arg()
@@ -1199,14 +1199,15 @@ impl Expr {
         }
     }
 
-    pub fn maybe_unwrap_block(&self) -> &Expr {
+    /// Returns an expression with (when possible) *one* outter brace removed
+    pub fn maybe_unwrap_block(&self) -> (bool, &Expr) {
         if let ExprKind::Block(block, None) = &self.kind
             && let [stmt] = block.stmts.as_slice()
             && let StmtKind::Expr(expr) = &stmt.kind
         {
-            expr
+            (true, expr)
         } else {
-            self
+            (false, self)
         }
     }