@@ -54,9 +54,10 @@ pub mod rt {
54
54
}
55
55
}
56
56
57
- impl ToTokens for Vec < TokenTree > {
58
- fn to_tokens ( & self , _cx : & ExtCtxt ) -> Vec < TokenTree > {
59
- ( * self ) . clone ( )
57
+ impl < T : ToTokens > ToTokens for Vec < T > {
58
+ fn to_tokens ( & self , cx : & ExtCtxt ) -> Vec < TokenTree > {
59
+ let a = self . iter ( ) . flat_map ( |t| t. to_tokens ( cx) . move_iter ( ) ) ;
60
+ FromIterator :: from_iter ( a)
60
61
}
61
62
}
62
63
@@ -67,6 +68,15 @@ pub mod rt {
67
68
}
68
69
}
69
70
71
+ impl < T : ToTokens > ToTokens for Option < T > {
72
+ fn to_tokens ( & self , cx : & ExtCtxt ) -> Vec < TokenTree > {
73
+ match self {
74
+ & Some ( ref t) => t. to_tokens ( cx) ,
75
+ & None => Vec :: new ( ) ,
76
+ }
77
+ }
78
+ }
79
+
70
80
/* Should be (when bugs in default methods are fixed):
71
81
72
82
trait ToSource : ToTokens {
@@ -133,11 +143,18 @@ pub mod rt {
133
143
impl_to_source ! ( ast:: Arg , arg_to_string)
134
144
impl_to_source ! ( Generics , generics_to_string)
135
145
impl_to_source ! ( Gc <ast:: Item >, item_to_string)
146
+ impl_to_source ! ( Gc <ast:: Method >, method_to_string)
136
147
impl_to_source ! ( Gc <ast:: Expr >, expr_to_string)
137
148
impl_to_source ! ( Gc <ast:: Pat >, pat_to_string)
138
149
impl_to_source_slice ! ( ast:: Ty , ", " )
139
150
impl_to_source_slice ! ( Gc <ast:: Item >, "\n \n " )
140
151
152
+ impl ToSource for ast:: Attribute_ {
153
+ fn to_source ( & self ) -> String {
154
+ pprust:: attribute_to_string ( & dummy_spanned ( * self ) )
155
+ }
156
+ }
157
+
141
158
impl < ' a > ToSource for & ' a str {
142
159
fn to_source ( & self ) -> String {
143
160
let lit = dummy_spanned ( ast:: LitStr (
@@ -222,13 +239,15 @@ pub mod rt {
222
239
impl_to_tokens ! ( ast:: Ident )
223
240
impl_to_tokens ! ( Gc <ast:: Item >)
224
241
impl_to_tokens ! ( Gc <ast:: Pat >)
242
+ impl_to_tokens ! ( Gc <ast:: Method >)
225
243
impl_to_tokens_lifetime ! ( & ' a [ Gc <ast:: Item >] )
226
244
impl_to_tokens ! ( ast:: Ty )
227
245
impl_to_tokens_lifetime ! ( & ' a [ ast:: Ty ] )
228
246
impl_to_tokens ! ( Generics )
229
247
impl_to_tokens ! ( Gc <ast:: Expr >)
230
248
impl_to_tokens ! ( ast:: Block )
231
249
impl_to_tokens ! ( ast:: Arg )
250
+ impl_to_tokens ! ( ast:: Attribute_ )
232
251
impl_to_tokens_lifetime ! ( & ' a str )
233
252
impl_to_tokens ! ( ( ) )
234
253
impl_to_tokens ! ( char )
@@ -336,6 +355,16 @@ pub fn expand_quote_ty(cx: &mut ExtCtxt,
336
355
base:: MacExpr :: new ( expanded)
337
356
}
338
357
358
+ pub fn expand_quote_method ( cx : & mut ExtCtxt ,
359
+ sp : Span ,
360
+ tts : & [ ast:: TokenTree ] )
361
+ -> Box < base:: MacResult > {
362
+ let e_param_colons = cx. expr_none ( sp) ;
363
+ let expanded = expand_parse_call ( cx, sp, "parse_method" ,
364
+ vec ! ( e_param_colons) , tts) ;
365
+ base:: MacExpr :: new ( expanded)
366
+ }
367
+
339
368
pub fn expand_quote_stmt ( cx : & mut ExtCtxt ,
340
369
sp : Span ,
341
370
tts : & [ ast:: TokenTree ] )
0 commit comments