@@ -54,9 +54,10 @@ pub mod rt {
5454 }
5555 }
5656
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)
6061 }
6162 }
6263
@@ -67,6 +68,15 @@ pub mod rt {
6768 }
6869 }
6970
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+
7080 /* Should be (when bugs in default methods are fixed):
7181
7282 trait ToSource : ToTokens {
@@ -133,11 +143,18 @@ pub mod rt {
133143 impl_to_source ! ( ast:: Arg , arg_to_string)
134144 impl_to_source ! ( Generics , generics_to_string)
135145 impl_to_source ! ( Gc <ast:: Item >, item_to_string)
146+ impl_to_source ! ( Gc <ast:: Method >, method_to_string)
136147 impl_to_source ! ( Gc <ast:: Expr >, expr_to_string)
137148 impl_to_source ! ( Gc <ast:: Pat >, pat_to_string)
138149 impl_to_source_slice ! ( ast:: Ty , ", " )
139150 impl_to_source_slice ! ( Gc <ast:: Item >, "\n \n " )
140151
152+ impl ToSource for ast:: Attribute_ {
153+ fn to_source ( & self ) -> String {
154+ pprust:: attribute_to_string ( & dummy_spanned ( * self ) )
155+ }
156+ }
157+
141158 impl < ' a > ToSource for & ' a str {
142159 fn to_source ( & self ) -> String {
143160 let lit = dummy_spanned ( ast:: LitStr (
@@ -222,13 +239,15 @@ pub mod rt {
222239 impl_to_tokens ! ( ast:: Ident )
223240 impl_to_tokens ! ( Gc <ast:: Item >)
224241 impl_to_tokens ! ( Gc <ast:: Pat >)
242+ impl_to_tokens ! ( Gc <ast:: Method >)
225243 impl_to_tokens_lifetime ! ( & ' a [ Gc <ast:: Item >] )
226244 impl_to_tokens ! ( ast:: Ty )
227245 impl_to_tokens_lifetime ! ( & ' a [ ast:: Ty ] )
228246 impl_to_tokens ! ( Generics )
229247 impl_to_tokens ! ( Gc <ast:: Expr >)
230248 impl_to_tokens ! ( ast:: Block )
231249 impl_to_tokens ! ( ast:: Arg )
250+ impl_to_tokens ! ( ast:: Attribute_ )
232251 impl_to_tokens_lifetime ! ( & ' a str )
233252 impl_to_tokens ! ( ( ) )
234253 impl_to_tokens ! ( char )
@@ -336,6 +355,16 @@ pub fn expand_quote_ty(cx: &mut ExtCtxt,
336355 base:: MacExpr :: new ( expanded)
337356}
338357
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+
339368pub fn expand_quote_stmt ( cx : & mut ExtCtxt ,
340369 sp : Span ,
341370 tts : & [ ast:: TokenTree ] )
0 commit comments