mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
simplify make_stmts_default!
This commit is contained in:
@@ -409,17 +409,10 @@ pub trait GlobDelegationExpander {
|
||||
fn expand(&self, ecx: &mut ExtCtxt<'_>) -> ExpandResult<Vec<(Ident, Option<Ident>)>, ()>;
|
||||
}
|
||||
|
||||
// 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<Box<ast::Expr>>) -> Option<SmallVec<[ast::Stmt; 1]>> {
|
||||
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<Self>) -> Option<Box<ast::Pat>> {
|
||||
/// By default this attempts to create an expression statement,
|
||||
/// returning None if that fails.
|
||||
fn make_stmts(self: Box<Self>) -> Option<SmallVec<[ast::Stmt; 1]>> {
|
||||
make_stmts_default!(self)
|
||||
make_stmts_default(self.make_expr())
|
||||
}
|
||||
|
||||
fn make_ty(self: Box<Self>) -> Option<Box<ast::Ty>> {
|
||||
@@ -571,9 +564,10 @@ fn make_expr(self: Box<Self>) -> Option<Box<ast::Expr>> {
|
||||
}
|
||||
|
||||
fn make_stmts(self: Box<Self>) -> Option<SmallVec<[ast::Stmt; 1]>> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user