From 6e458a5fcadc9fe4c63eb1552e5010e0df689134 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 14 Apr 2026 19:48:17 +0000 Subject: [PATCH] simplify `make_stmts_default!` --- compiler/rustc_expand/src/base.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 427eee1a3c46..cf7e706cf9fd 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -409,17 +409,10 @@ pub trait GlobDelegationExpander { fn expand(&self, ecx: &mut ExtCtxt<'_>) -> ExpandResult)>, ()>; } -// Use a macro because forwarding to a simple function has type system issues -macro_rules! make_stmts_default { - ($me:expr) => { - $me.make_expr().map(|e| { - smallvec![ast::Stmt { - id: ast::DUMMY_NODE_ID, - span: e.span, - kind: ast::StmtKind::Expr(e), - }] - }) - }; +fn make_stmts_default(expr: Option>) -> Option> { + expr.map(|e| { + smallvec![ast::Stmt { id: ast::DUMMY_NODE_ID, span: e.span, kind: ast::StmtKind::Expr(e) }] + }) } /// The result of a macro expansion. The return values of the various @@ -465,7 +458,7 @@ fn make_pat(self: Box) -> Option> { /// By default this attempts to create an expression statement, /// returning None if that fails. fn make_stmts(self: Box) -> Option> { - make_stmts_default!(self) + make_stmts_default(self.make_expr()) } fn make_ty(self: Box) -> Option> { @@ -571,9 +564,10 @@ fn make_expr(self: Box) -> Option> { } fn make_stmts(self: Box) -> Option> { - match self.stmts.as_ref().map_or(0, |s| s.len()) { - 0 => make_stmts_default!(self), - _ => self.stmts, + if self.stmts.as_ref().is_none_or(|s| s.is_empty()) { + make_stmts_default(self.make_expr()) + } else { + self.stmts } }