Handle Annotatable::Stmt
in some builtin macros
This is preparation for PR #78296, which will require us to handle statement items in addition to normal items.
This commit is contained in:
parent
25a691003c
commit
e9546bdbaf
3 changed files with 70 additions and 14 deletions
|
@ -54,7 +54,27 @@ impl MultiItemModifier for BuiltinDerive {
|
|||
// so we are doing it here in a centralized way.
|
||||
let span = ecx.with_def_site_ctxt(span);
|
||||
let mut items = Vec::new();
|
||||
(self.0)(ecx, span, meta_item, &item, &mut |a| items.push(a));
|
||||
match item {
|
||||
Annotatable::Stmt(stmt) => {
|
||||
if let ast::StmtKind::Item(item) = stmt.into_inner().kind {
|
||||
(self.0)(ecx, span, meta_item, &Annotatable::Item(item), &mut |a| {
|
||||
// Cannot use 'ecx.stmt_item' here, because we need to pass 'ecx'
|
||||
// to the function
|
||||
items.push(Annotatable::Stmt(P(ast::Stmt {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
kind: ast::StmtKind::Item(a.expect_item()),
|
||||
span,
|
||||
tokens: None,
|
||||
})));
|
||||
});
|
||||
} else {
|
||||
unreachable!("should have already errored on non-item statement")
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
(self.0)(ecx, span, meta_item, &item, &mut |a| items.push(a));
|
||||
}
|
||||
}
|
||||
ExpandResult::Ready(items)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue