1
Fork 0

Box the MacCall in various types.

This commit is contained in:
Nicholas Nethercote 2022-08-12 12:20:10 +10:00
parent 5746c752f4
commit eafd0dfd05
12 changed files with 94 additions and 94 deletions

View file

@ -306,7 +306,7 @@ pub struct Invocation {
pub enum InvocationKind {
Bang {
mac: ast::MacCall,
mac: P<ast::MacCall>,
span: Span,
},
Attr {
@ -1017,7 +1017,7 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized {
fn is_mac_call(&self) -> bool {
false
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
unreachable!()
}
fn pre_flat_map_node_collect_attr(_cfg: &StripUnconfigured<'_>, _attr: &ast::Attribute) {}
@ -1046,7 +1046,7 @@ impl InvocationCollectorNode for P<ast::Item> {
fn is_mac_call(&self) -> bool {
matches!(self.kind, ItemKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let node = self.into_inner();
match node.kind {
ItemKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
@ -1154,7 +1154,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag>
fn is_mac_call(&self) -> bool {
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let item = self.wrapped.into_inner();
match item.kind {
AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No),
@ -1179,7 +1179,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag>
fn is_mac_call(&self) -> bool {
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let item = self.wrapped.into_inner();
match item.kind {
AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No),
@ -1202,7 +1202,7 @@ impl InvocationCollectorNode for P<ast::ForeignItem> {
fn is_mac_call(&self) -> bool {
matches!(self.kind, ForeignItemKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let node = self.into_inner();
match node.kind {
ForeignItemKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
@ -1323,7 +1323,7 @@ impl InvocationCollectorNode for ast::Stmt {
StmtKind::Local(..) | StmtKind::Empty => false,
}
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
// We pull macro invocations (both attributes and fn-like macro calls) out of their
// `StmtKind`s and treat them as statement macro invocations, not as items or expressions.
let (add_semicolon, mac, attrs) = match self.kind {
@ -1387,7 +1387,7 @@ impl InvocationCollectorNode for P<ast::Ty> {
fn is_mac_call(&self) -> bool {
matches!(self.kind, ast::TyKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let node = self.into_inner();
match node.kind {
TyKind::MacCall(mac) => (mac, Vec::new(), AddSemicolon::No),
@ -1411,7 +1411,7 @@ impl InvocationCollectorNode for P<ast::Pat> {
fn is_mac_call(&self) -> bool {
matches!(self.kind, PatKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let node = self.into_inner();
match node.kind {
PatKind::MacCall(mac) => (mac, Vec::new(), AddSemicolon::No),
@ -1439,7 +1439,7 @@ impl InvocationCollectorNode for P<ast::Expr> {
fn is_mac_call(&self) -> bool {
matches!(self.kind, ExprKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let node = self.into_inner();
match node.kind {
ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
@ -1466,7 +1466,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::Expr>, OptExprTag> {
fn is_mac_call(&self) -> bool {
matches!(self.wrapped.kind, ast::ExprKind::MacCall(..))
}
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {
let node = self.wrapped.into_inner();
match node.kind {
ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
@ -1512,7 +1512,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
placeholder(fragment_kind, NodeId::placeholder_from_expn_id(expn_id), vis)
}
fn collect_bang(&mut self, mac: ast::MacCall, kind: AstFragmentKind) -> AstFragment {
fn collect_bang(&mut self, mac: P<ast::MacCall>, kind: AstFragmentKind) -> AstFragment {
// cache the macro call span so that it can be
// easily adjusted for incremental compilation
let span = mac.span();

View file

@ -15,12 +15,12 @@ pub fn placeholder(
id: ast::NodeId,
vis: Option<ast::Visibility>,
) -> AstFragment {
fn mac_placeholder() -> ast::MacCall {
ast::MacCall {
fn mac_placeholder() -> P<ast::MacCall> {
P(ast::MacCall {
path: ast::Path { span: DUMMY_SP, segments: Vec::new(), tokens: None },
args: P(ast::MacArgs::Empty),
prior_type_ascription: None,
}
})
}
let ident = Ident::empty();