@@ -30,6 +30,8 @@ use std::collections::HashMap;
3030use std:: rc:: Rc ;
3131use std:: default:: Default ;
3232
33+ #[ unstable( feature = "rustc_private" ) ]
34+ #[ deprecated( since = "1.0.0" , reason = "replaced by MultiItemDecorator" ) ]
3335pub trait ItemDecorator {
3436 fn expand ( & self ,
3537 ecx : & mut ExtCtxt ,
@@ -39,6 +41,9 @@ pub trait ItemDecorator {
3941 push : & mut FnMut ( P < ast:: Item > ) ) ;
4042}
4143
44+ #[ allow( deprecated) ]
45+ #[ unstable( feature = "rustc_private" ) ]
46+ #[ deprecated( since = "1.0.0" , reason = "replaced by MultiItemDecorator" ) ]
4247impl < F > ItemDecorator for F
4348 where F : Fn ( & mut ExtCtxt , Span , & ast:: MetaItem , & ast:: Item , & mut FnMut ( P < ast:: Item > ) )
4449{
@@ -52,6 +57,8 @@ impl<F> ItemDecorator for F
5257 }
5358}
5459
60+ #[ unstable( feature = "rustc_private" ) ]
61+ #[ deprecated( since = "1.0.0" , reason = "replaced by MultiItemModifier" ) ]
5562pub trait ItemModifier {
5663 fn expand ( & self ,
5764 ecx : & mut ExtCtxt ,
@@ -61,9 +68,13 @@ pub trait ItemModifier {
6168 -> P < ast:: Item > ;
6269}
6370
71+ #[ allow( deprecated) ]
72+ #[ unstable( feature = "rustc_private" ) ]
73+ #[ deprecated( since = "1.0.0" , reason = "replaced by MultiItemModifier" ) ]
6474impl < F > ItemModifier for F
6575 where F : Fn ( & mut ExtCtxt , Span , & ast:: MetaItem , P < ast:: Item > ) -> P < ast:: Item >
6676{
77+
6778 fn expand ( & self ,
6879 ecx : & mut ExtCtxt ,
6980 span : Span ,
@@ -112,6 +123,16 @@ impl Annotatable {
112123 }
113124 }
114125
126+ pub fn map_item_or < F , G > ( self , mut f : F , mut or : G ) -> Annotatable
127+ where F : FnMut ( P < ast:: Item > ) -> P < ast:: Item > ,
128+ G : FnMut ( Annotatable ) -> Annotatable
129+ {
130+ match self {
131+ Annotatable :: Item ( i) => Annotatable :: Item ( f ( i) ) ,
132+ _ => or ( self )
133+ }
134+ }
135+
115136 pub fn expect_trait_item ( self ) -> P < ast:: TraitItem > {
116137 match self {
117138 Annotatable :: TraitItem ( i) => i,
@@ -127,6 +148,29 @@ impl Annotatable {
127148 }
128149}
129150
151+ // A more flexible ItemDecorator.
152+ pub trait MultiItemDecorator {
153+ fn expand ( & self ,
154+ ecx : & mut ExtCtxt ,
155+ sp : Span ,
156+ meta_item : & ast:: MetaItem ,
157+ item : Annotatable ,
158+ push : & mut FnMut ( Annotatable ) ) ;
159+ }
160+
161+ impl < F > MultiItemDecorator for F
162+ where F : Fn ( & mut ExtCtxt , Span , & ast:: MetaItem , Annotatable , & mut FnMut ( Annotatable ) )
163+ {
164+ fn expand ( & self ,
165+ ecx : & mut ExtCtxt ,
166+ sp : Span ,
167+ meta_item : & ast:: MetaItem ,
168+ item : Annotatable ,
169+ push : & mut FnMut ( Annotatable ) ) {
170+ ( * self ) ( ecx, sp, meta_item, item, push)
171+ }
172+ }
173+
130174// A more flexible ItemModifier (ItemModifier should go away, eventually, FIXME).
131175// meta_item is the annotation, item is the item being modified, parent_item
132176// is the impl or trait item is declared in if item is part of such a thing.
@@ -397,12 +441,22 @@ impl MacResult for DummyResult {
397441pub enum SyntaxExtension {
398442 /// A syntax extension that is attached to an item and creates new items
399443 /// based upon it.
400- ///
401- /// `#[derive(...)]` is an `ItemDecorator`.
444+ #[ unstable( feature = "rustc_private" ) ]
445+ #[ deprecated( since = "1.0.0" , reason = "replaced by MultiDecorator" ) ]
446+ #[ allow( deprecated) ]
402447 Decorator ( Box < ItemDecorator + ' static > ) ,
403448
449+ /// A syntax extension that is attached to an item and creates new items
450+ /// based upon it.
451+ ///
452+ /// `#[derive(...)]` is a `MultiItemDecorator`.
453+ MultiDecorator ( Box < MultiItemDecorator + ' static > ) ,
454+
404455 /// A syntax extension that is attached to an item and modifies it
405456 /// in-place.
457+ #[ unstable( feature = "rustc_private" ) ]
458+ #[ deprecated( since = "1.0.0" , reason = "replaced by MultiModifier" ) ]
459+ #[ allow( deprecated) ]
406460 Modifier ( Box < ItemModifier + ' static > ) ,
407461
408462 /// A syntax extension that is attached to an item and modifies it
0 commit comments