10
10
11
11
// force-host
12
12
13
- #![ feature( plugin_registrar, quote) ]
14
- #![ feature( box_syntax, rustc_private) ]
13
+ #![ feature( plugin_registrar, quote, rustc_private) ]
15
14
16
15
extern crate syntax;
17
16
extern crate rustc;
18
17
19
- use syntax:: ast:: { self , TokenTree , Item , MetaItem , Method , ImplItem , TraitItem } ;
18
+ use syntax:: ast:: { self , TokenTree , Item , MetaItem , ImplItem , TraitItem } ;
20
19
use syntax:: codemap:: Span ;
21
20
use syntax:: ext:: base:: * ;
22
21
use syntax:: parse:: { self , token} ;
@@ -25,7 +24,6 @@ use rustc::plugin::Registry;
25
24
26
25
#[ macro_export]
27
26
macro_rules! exported_macro { ( ) => ( 2 ) }
28
-
29
27
macro_rules! unexported_macro { ( ) => ( 3 ) }
30
28
31
29
#[ plugin_registrar]
@@ -42,7 +40,8 @@ pub fn plugin_registrar(reg: &mut Registry) {
42
40
MultiModifier ( Box :: new ( expand_into_foo_multi) ) ) ;
43
41
reg. register_syntax_extension (
44
42
token:: intern ( "duplicate" ) ,
45
- MultiDecorator ( box expand_duplicate) ) ;
43
+ // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
44
+ MultiDecorator ( Box :: new ( expand_duplicate) ) ) ;
46
45
}
47
46
48
47
fn expand_make_a_1 ( cx : & mut ExtCtxt , sp : Span , tts : & [ TokenTree ] )
@@ -109,13 +108,13 @@ fn expand_into_foo_multi(cx: &mut ExtCtxt,
109
108
fn expand_duplicate ( cx : & mut ExtCtxt ,
110
109
sp : Span ,
111
110
mi : & MetaItem ,
112
- it : & Annotatable ,
113
- mut push : Box < FnMut ( Annotatable ) > )
111
+ it : Annotatable ,
112
+ push : & mut FnMut ( Annotatable ) )
114
113
{
115
114
let copy_name = match mi. node {
116
115
ast:: MetaItem_ :: MetaList ( _, ref xs) => {
117
116
if let ast:: MetaItem_ :: MetaWord ( ref w) = xs[ 0 ] . node {
118
- token:: str_to_ident ( w . get ( ) )
117
+ token:: str_to_ident ( & w )
119
118
} else {
120
119
cx. span_err ( mi. span , "Expected word" ) ;
121
120
return ;
@@ -136,75 +135,18 @@ fn expand_duplicate(cx: &mut ExtCtxt,
136
135
push ( Annotatable :: Item ( P ( new_it) ) ) ;
137
136
}
138
137
Annotatable :: ImplItem ( it) => {
139
- match it {
140
- ImplItem :: MethodImplItem ( m) => {
141
- let mut new_m = ( * m) . clone ( ) ;
142
- new_m. attrs . clear ( ) ;
143
- replace_method_name ( & mut new_m. node , copy_name) ;
144
- push ( Annotatable :: ImplItem ( ImplItem :: MethodImplItem ( P ( new_m) ) ) ) ;
145
- }
146
- ImplItem :: TypeImplItem ( t) => {
147
- let mut new_t = ( * t) . clone ( ) ;
148
- new_t. attrs . clear ( ) ;
149
- new_t. ident = copy_name;
150
- push ( Annotatable :: ImplItem ( ImplItem :: TypeImplItem ( P ( new_t) ) ) ) ;
151
- }
152
- }
153
- }
154
- Annotatable :: TraitItem ( it) => {
155
- match it {
156
- TraitItem :: RequiredMethod ( rm) => {
157
- let mut new_rm = rm. clone ( ) ;
158
- new_rm. attrs . clear ( ) ;
159
- new_rm. ident = copy_name;
160
- push ( Annotatable :: TraitItem ( TraitItem :: RequiredMethod ( new_rm) ) ) ;
161
- }
162
- TraitItem :: ProvidedMethod ( pm) => {
163
- let mut new_pm = ( * pm) . clone ( ) ;
164
- new_pm. attrs . clear ( ) ;
165
- replace_method_name ( & mut new_pm. node , copy_name) ;
166
- push ( Annotatable :: TraitItem ( TraitItem :: ProvidedMethod ( P ( new_pm) ) ) ) ;
167
- }
168
- TraitItem :: TypeTraitItem ( t) => {
169
- let mut new_t = ( * t) . clone ( ) ;
170
- new_t. attrs . clear ( ) ;
171
- new_t. ty_param . ident = copy_name;
172
- push ( Annotatable :: TraitItem ( TraitItem :: TypeTraitItem ( P ( new_t) ) ) ) ;
173
- }
174
- }
138
+ let mut new_it = ( * it) . clone ( ) ;
139
+ new_it. attrs . clear ( ) ;
140
+ new_it. ident = copy_name;
141
+ push ( Annotatable :: ImplItem ( P ( new_it) ) ) ;
175
142
}
176
- }
177
-
178
- fn replace_method_name ( m : & mut ast :: Method_ , i : ast :: Ident ) {
179
- if let & mut ast :: Method_ :: MethDecl ( ref mut ident, _ , _ , _ , _ , _ , _ , _ ) = m {
180
- * ident = i
143
+ Annotatable :: TraitItem ( tt ) => {
144
+ let mut new_it = ( * tt ) . clone ( ) ;
145
+ new_it . attrs . clear ( ) ;
146
+ new_it . ident = copy_name ;
147
+ push ( Annotatable :: TraitItem ( P ( new_it ) ) ) ;
181
148
}
182
149
}
183
150
}
184
151
185
- fn expand_forged_ident ( cx : & mut ExtCtxt , sp : Span , tts : & [ TokenTree ] ) -> Box < MacResult +' static > {
186
- use syntax:: ext:: quote:: rt:: * ;
187
-
188
- if !tts. is_empty ( ) {
189
- cx. span_fatal ( sp, "forged_ident takes no arguments" ) ;
190
- }
191
-
192
- // Most of this is modelled after the expansion of the `quote_expr!`
193
- // macro ...
194
- let parse_sess = cx. parse_sess ( ) ;
195
- let cfg = cx. cfg ( ) ;
196
-
197
- // ... except this is where we inject a forged identifier,
198
- // and deliberately do not call `cx.parse_tts_with_hygiene`
199
- // (because we are testing that this will be *rejected*
200
- // by the default parser).
201
-
202
- let expr = {
203
- let tt = cx. parse_tts ( "\x00 name_2,ctxt_0\x00 " . to_string ( ) ) ;
204
- let mut parser = new_parser_from_tts ( parse_sess, cfg, tt) ;
205
- parser. parse_expr ( )
206
- } ;
207
- MacEager :: expr ( expr)
208
- }
209
-
210
152
pub fn foo ( ) { }
0 commit comments