Add MultiDecorator variant to SyntaxExtension enum

This commit is contained in:
Adolfo Ochagavía
2015-01-16 23:04:55 +01:00
parent 77d59217a3
commit f97cff9abd
2 changed files with 27 additions and 1 deletions

View File

@@ -418,11 +418,15 @@ impl MacResult for DummyResult {
/// An enum representing the different kinds of syntax extensions. /// An enum representing the different kinds of syntax extensions.
pub enum SyntaxExtension { pub enum SyntaxExtension {
/// A syntax extension that is attached to an item and creates new items
/// based upon it.
Decorator(Box<ItemDecorator + 'static>),
/// A syntax extension that is attached to an item and creates new items /// A syntax extension that is attached to an item and creates new items
/// based upon it. /// based upon it.
/// ///
/// `#[derive(...)]` is an `ItemDecorator`. /// `#[derive(...)]` is an `ItemDecorator`.
Decorator(Box<ItemDecorator + 'static>), MultiDecorator(Box<MultiItemDecorator + 'static>),
/// A syntax extension that is attached to an item and modifies it /// A syntax extension that is attached to an item and modifies it
/// in-place. /// in-place.

View File

@@ -1096,6 +1096,28 @@ fn expand_annotatable(a: Annotatable,
fld.cx.bt_pop(); fld.cx.bt_pop();
} }
MultiDecorator(ref dec) => {
attr::mark_used(attr);
fld.cx.bt_push(ExpnInfo {
call_site: attr.span,
callee: NameAndSpan {
name: mname.get().to_string(),
format: MacroAttribute,
span: None
}
});
// we'd ideally decorator_items.push_all(expand_item(item, fld)),
// but that double-mut-borrows fld
let mut items: SmallVector<P<ast::Item>> = SmallVector::zero();
dec.expand(fld.cx, attr.span, &*attr.node.value, a,
box |&mut: item| items.push(item));
decorator_items.extend(items.into_iter()
.flat_map(|item| expand_item(item, fld).into_iter()));
fld.cx.bt_pop();
}
_ => new_attrs.push((*attr).clone()), _ => new_attrs.push((*attr).clone()),
}, },
_ => new_attrs.push((*attr).clone()), _ => new_attrs.push((*attr).clone()),