Skip to content

Commit f97cff9

Browse files
committed
Add MultiDecorator variant to SyntaxExtension enum
1 parent 77d5921 commit f97cff9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/libsyntax/ext/base.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,15 @@ impl MacResult for DummyResult {
418418

419419
/// An enum representing the different kinds of syntax extensions.
420420
pub enum SyntaxExtension {
421+
/// A syntax extension that is attached to an item and creates new items
422+
/// based upon it.
423+
Decorator(Box<ItemDecorator + 'static>),
424+
421425
/// A syntax extension that is attached to an item and creates new items
422426
/// based upon it.
423427
///
424428
/// `#[derive(...)]` is an `ItemDecorator`.
425-
Decorator(Box<ItemDecorator + 'static>),
429+
MultiDecorator(Box<MultiItemDecorator + 'static>),
426430

427431
/// A syntax extension that is attached to an item and modifies it
428432
/// in-place.

src/libsyntax/ext/expand.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,28 @@ fn expand_annotatable(a: Annotatable,
10961096

10971097
fld.cx.bt_pop();
10981098
}
1099+
MultiDecorator(ref dec) => {
1100+
attr::mark_used(attr);
1101+
1102+
fld.cx.bt_push(ExpnInfo {
1103+
call_site: attr.span,
1104+
callee: NameAndSpan {
1105+
name: mname.get().to_string(),
1106+
format: MacroAttribute,
1107+
span: None
1108+
}
1109+
});
1110+
1111+
// we'd ideally decorator_items.push_all(expand_item(item, fld)),
1112+
// but that double-mut-borrows fld
1113+
let mut items: SmallVector<P<ast::Item>> = SmallVector::zero();
1114+
dec.expand(fld.cx, attr.span, &*attr.node.value, a,
1115+
box |&mut: item| items.push(item));
1116+
decorator_items.extend(items.into_iter()
1117+
.flat_map(|item| expand_item(item, fld).into_iter()));
1118+
1119+
fld.cx.bt_pop();
1120+
}
10991121
_ => new_attrs.push((*attr).clone()),
11001122
},
11011123
_ => new_attrs.push((*attr).clone()),

0 commit comments

Comments
 (0)