@@ -30,6 +30,8 @@ use std::collections::HashMap;
30
30
use std:: rc:: Rc ;
31
31
use std:: default:: Default ;
32
32
33
+ #[ unstable( feature = "rustc_private" ) ]
34
+ #[ deprecated( since = "1.0.0" , reason = "replaced by MultiItemDecorator" ) ]
33
35
pub trait ItemDecorator {
34
36
fn expand ( & self ,
35
37
ecx : & mut ExtCtxt ,
@@ -39,6 +41,9 @@ pub trait ItemDecorator {
39
41
push : & mut FnMut ( P < ast:: Item > ) ) ;
40
42
}
41
43
44
+ #[ allow( deprecated) ]
45
+ #[ unstable( feature = "rustc_private" ) ]
46
+ #[ deprecated( since = "1.0.0" , reason = "replaced by MultiItemDecorator" ) ]
42
47
impl < F > ItemDecorator for F
43
48
where F : Fn ( & mut ExtCtxt , Span , & ast:: MetaItem , & ast:: Item , & mut FnMut ( P < ast:: Item > ) )
44
49
{
@@ -52,6 +57,8 @@ impl<F> ItemDecorator for F
52
57
}
53
58
}
54
59
60
+ #[ unstable( feature = "rustc_private" ) ]
61
+ #[ deprecated( since = "1.0.0" , reason = "replaced by MultiItemModifier" ) ]
55
62
pub trait ItemModifier {
56
63
fn expand ( & self ,
57
64
ecx : & mut ExtCtxt ,
@@ -61,9 +68,13 @@ pub trait ItemModifier {
61
68
-> P < ast:: Item > ;
62
69
}
63
70
71
+ #[ allow( deprecated) ]
72
+ #[ unstable( feature = "rustc_private" ) ]
73
+ #[ deprecated( since = "1.0.0" , reason = "replaced by MultiItemModifier" ) ]
64
74
impl < F > ItemModifier for F
65
75
where F : Fn ( & mut ExtCtxt , Span , & ast:: MetaItem , P < ast:: Item > ) -> P < ast:: Item >
66
76
{
77
+
67
78
fn expand ( & self ,
68
79
ecx : & mut ExtCtxt ,
69
80
span : Span ,
@@ -112,6 +123,16 @@ impl Annotatable {
112
123
}
113
124
}
114
125
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
+
115
136
pub fn expect_trait_item ( self ) -> P < ast:: TraitItem > {
116
137
match self {
117
138
Annotatable :: TraitItem ( i) => i,
@@ -127,6 +148,29 @@ impl Annotatable {
127
148
}
128
149
}
129
150
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
+
130
174
// A more flexible ItemModifier (ItemModifier should go away, eventually, FIXME).
131
175
// meta_item is the annotation, item is the item being modified, parent_item
132
176
// 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 {
397
441
pub enum SyntaxExtension {
398
442
/// A syntax extension that is attached to an item and creates new items
399
443
/// 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) ]
402
447
Decorator ( Box < ItemDecorator + ' static > ) ,
403
448
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
+
404
455
/// A syntax extension that is attached to an item and modifies it
405
456
/// in-place.
457
+ #[ unstable( feature = "rustc_private" ) ]
458
+ #[ deprecated( since = "1.0.0" , reason = "replaced by MultiModifier" ) ]
459
+ #[ allow( deprecated) ]
406
460
Modifier ( Box < ItemModifier + ' static > ) ,
407
461
408
462
/// A syntax extension that is attached to an item and modifies it
0 commit comments