Strip unconfigured nodes from decorator-generated AST
This commit is contained in:
parent
83d283b67b
commit
c41cf30e9d
3 changed files with 25 additions and 4 deletions
|
|
@ -95,6 +95,16 @@ impl Annotatable {
|
|||
_ => panic!("expected Item")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fold_with<F: Folder>(self, folder: &mut F) -> SmallVector<Self> {
|
||||
match self {
|
||||
Annotatable::Item(item) => folder.fold_item(item).map(Annotatable::Item),
|
||||
Annotatable::ImplItem(item) =>
|
||||
folder.fold_impl_item(item.unwrap()).map(|item| Annotatable::ImplItem(P(item))),
|
||||
Annotatable::TraitItem(item) =>
|
||||
folder.fold_trait_item(item.unwrap()).map(|item| Annotatable::TraitItem(P(item))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A more flexible ItemDecorator.
|
||||
|
|
|
|||
|
|
@ -839,16 +839,18 @@ fn expand_decorators(a: Annotatable,
|
|||
}
|
||||
});
|
||||
|
||||
// we'd ideally decorator_items.push_all(expand_annotatable(ann, fld)),
|
||||
// but that double-mut-borrows fld
|
||||
let mut items: SmallVector<Annotatable> = SmallVector::zero();
|
||||
dec.expand(fld.cx,
|
||||
attr.span,
|
||||
&attr.node.value,
|
||||
&a,
|
||||
&mut |ann| items.push(ann));
|
||||
decorator_items.extend(items.into_iter()
|
||||
.flat_map(|ann| expand_annotatable(ann, fld).into_iter()));
|
||||
|
||||
for item in items {
|
||||
for configured_item in item.fold_with(&mut fld.strip_unconfigured()) {
|
||||
decorator_items.extend(expand_annotatable(configured_item, fld));
|
||||
}
|
||||
}
|
||||
|
||||
fld.cx.bt_pop();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue