@@ -17,7 +17,7 @@ use syntax::symbol::Symbol;
17
17
use syntax:: tokenstream:: { self , Delimited , TokenTree , TokenStream } ;
18
18
use syntax_pos:: DUMMY_SP ;
19
19
20
- use std:: rc :: Rc ;
20
+ use std:: iter ;
21
21
22
22
pub fn qquote < ' cx > ( stream : TokenStream ) -> TokenStream {
23
23
stream. quote ( )
@@ -49,10 +49,7 @@ macro_rules! quote_tree {
49
49
}
50
50
51
51
fn delimit ( delim : token:: DelimToken , stream : TokenStream ) -> TokenStream {
52
- TokenTree :: Delimited ( DUMMY_SP , Rc :: new ( Delimited {
53
- delim : delim,
54
- tts : stream. trees ( ) . cloned ( ) . collect ( ) ,
55
- } ) ) . into ( )
52
+ TokenTree :: Delimited ( DUMMY_SP , Delimited { delim : delim, tts : stream. into ( ) } ) . into ( )
56
53
}
57
54
58
55
macro_rules! quote {
@@ -75,9 +72,9 @@ impl Quote for TokenStream {
75
72
return quote ! ( :: syntax:: tokenstream:: TokenStream :: empty( ) ) ;
76
73
}
77
74
78
- struct Quote < ' a > ( tokenstream:: Cursor < ' a > ) ;
75
+ struct Quote ( iter :: Peekable < tokenstream:: Cursor > ) ;
79
76
80
- impl < ' a > Iterator for Quote < ' a > {
77
+ impl Iterator for Quote {
81
78
type Item = TokenStream ;
82
79
83
80
fn next ( & mut self ) -> Option < TokenStream > {
@@ -89,25 +86,18 @@ impl Quote for TokenStream {
89
86
_ => false ,
90
87
} ;
91
88
92
- self . 0 . next ( ) . cloned ( ) . map ( |tree| {
89
+ self . 0 . next ( ) . map ( |tree| {
93
90
let quoted_tree = if is_unquote { tree. into ( ) } else { tree. quote ( ) } ;
94
91
quote ! ( :: syntax:: tokenstream:: TokenStream :: from( ( unquote quoted_tree) ) , )
95
92
} )
96
93
}
97
94
}
98
95
99
- let quoted = Quote ( self . trees ( ) ) . collect :: < TokenStream > ( ) ;
96
+ let quoted = Quote ( self . trees ( ) . peekable ( ) ) . collect :: < TokenStream > ( ) ;
100
97
quote ! ( [ ( unquote quoted) ] . iter( ) . cloned( ) . collect:: <:: syntax:: tokenstream:: TokenStream >( ) )
101
98
}
102
99
}
103
100
104
- impl Quote for Vec < TokenTree > {
105
- fn quote ( & self ) -> TokenStream {
106
- let stream = self . iter ( ) . cloned ( ) . collect :: < TokenStream > ( ) ;
107
- quote ! ( ( quote stream) . trees( ) . cloned( ) . collect:: <:: std:: vec:: Vec <_> >( ) )
108
- }
109
- }
110
-
111
101
impl Quote for TokenTree {
112
102
fn quote ( & self ) -> TokenStream {
113
103
match * self {
@@ -123,12 +113,12 @@ impl Quote for TokenTree {
123
113
}
124
114
}
125
115
126
- impl Quote for Rc < Delimited > {
116
+ impl Quote for Delimited {
127
117
fn quote ( & self ) -> TokenStream {
128
- quote ! ( :: std :: rc :: Rc :: new ( :: syntax:: tokenstream:: Delimited {
118
+ quote ! ( :: syntax:: tokenstream:: Delimited {
129
119
delim: ( quote self . delim) ,
130
- tts: ( quote self . tts ) ,
131
- } ) )
120
+ tts: ( quote self . stream ( ) ) . into ( ) ,
121
+ } )
132
122
}
133
123
}
134
124
0 commit comments