提交 c41cf30e 编写于 作者: J Jeffrey Seyfried

Strip unconfigured nodes from decorator-generated AST

上级 83d283b6
...@@ -95,6 +95,16 @@ pub fn expect_impl_item(self) -> ast::ImplItem { ...@@ -95,6 +95,16 @@ pub fn expect_impl_item(self) -> ast::ImplItem {
_ => panic!("expected Item") _ => 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. // A more flexible ItemDecorator.
......
...@@ -839,16 +839,18 @@ fn expand_decorators(a: Annotatable, ...@@ -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(); let mut items: SmallVector<Annotatable> = SmallVector::zero();
dec.expand(fld.cx, dec.expand(fld.cx,
attr.span, attr.span,
&attr.node.value, &attr.node.value,
&a, &a,
&mut |ann| items.push(ann)); &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(); fld.cx.bt_pop();
} }
......
...@@ -136,6 +136,15 @@ pub fn len(&self) -> usize { ...@@ -136,6 +136,15 @@ pub fn len(&self) -> usize {
} }
pub fn is_empty(&self) -> bool { self.len() == 0 } pub fn is_empty(&self) -> bool { self.len() == 0 }
pub fn map<U, F: FnMut(T) -> U>(self, mut f: F) -> SmallVector<U> {
let repr = match self.repr {
Zero => Zero,
One(t) => One(f(t)),
Many(vec) => Many(vec.into_iter().map(f).collect()),
};
SmallVector { repr: repr }
}
} }
impl<T> IntoIterator for SmallVector<T> { impl<T> IntoIterator for SmallVector<T> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册