@@ -83,7 +83,7 @@ impl TokenTree {
83
83
}
84
84
85
85
pub fn joint ( self ) -> TokenStream {
86
- TokenStream :: new ( vec ! [ ( self , Joint ) ] )
86
+ TokenStream :: new ( vec ! [ ( self , Spacing :: Joint ) ] )
87
87
}
88
88
89
89
pub fn token ( kind : TokenKind , span : Span ) -> TokenTree {
@@ -125,22 +125,20 @@ where
125
125
/// instead of a representation of the abstract syntax tree.
126
126
/// Today's `TokenTree`s can still contain AST via `token::Interpolated` for back-compat.
127
127
#[ derive( Clone , Debug , Default , Encodable , Decodable ) ]
128
- pub struct TokenStream ( pub Lrc < Vec < TreeAndJoint > > ) ;
128
+ pub struct TokenStream ( pub Lrc < Vec < TreeAndSpacing > > ) ;
129
129
130
- pub type TreeAndJoint = ( TokenTree , IsJoint ) ;
130
+ pub type TreeAndSpacing = ( TokenTree , Spacing ) ;
131
131
132
132
// `TokenStream` is used a lot. Make sure it doesn't unintentionally get bigger.
133
133
#[ cfg( target_arch = "x86_64" ) ]
134
134
rustc_data_structures:: static_assert_size!( TokenStream , 8 ) ;
135
135
136
136
#[ derive( Clone , Copy , Debug , PartialEq , Encodable , Decodable ) ]
137
- pub enum IsJoint {
137
+ pub enum Spacing {
138
+ Alone ,
138
139
Joint ,
139
- NonJoint ,
140
140
}
141
141
142
- use IsJoint :: * ;
143
-
144
142
impl TokenStream {
145
143
/// Given a `TokenStream` with a `Stream` of only two arguments, return a new `TokenStream`
146
144
/// separating the two arguments with a comma for diagnostic suggestions.
@@ -153,7 +151,7 @@ impl TokenStream {
153
151
let sp = match ( & ts, & next) {
154
152
( _, ( TokenTree :: Token ( Token { kind : token:: Comma , .. } ) , _) ) => continue ,
155
153
(
156
- ( TokenTree :: Token ( token_left) , NonJoint ) ,
154
+ ( TokenTree :: Token ( token_left) , Spacing :: Alone ) ,
157
155
( TokenTree :: Token ( token_right) , _) ,
158
156
) if ( ( token_left. is_ident ( ) && !token_left. is_reserved_ident ( ) )
159
157
|| token_left. is_lit ( ) )
@@ -162,11 +160,11 @@ impl TokenStream {
162
160
{
163
161
token_left. span
164
162
}
165
- ( ( TokenTree :: Delimited ( sp, ..) , NonJoint ) , _) => sp. entire ( ) ,
163
+ ( ( TokenTree :: Delimited ( sp, ..) , Spacing :: Alone ) , _) => sp. entire ( ) ,
166
164
_ => continue ,
167
165
} ;
168
166
let sp = sp. shrink_to_hi ( ) ;
169
- let comma = ( TokenTree :: token ( token:: Comma , sp) , NonJoint ) ;
167
+ let comma = ( TokenTree :: token ( token:: Comma , sp) , Spacing :: Alone ) ;
170
168
suggestion = Some ( ( pos, comma, sp) ) ;
171
169
}
172
170
}
@@ -184,19 +182,19 @@ impl TokenStream {
184
182
185
183
impl From < TokenTree > for TokenStream {
186
184
fn from ( tree : TokenTree ) -> TokenStream {
187
- TokenStream :: new ( vec ! [ ( tree, NonJoint ) ] )
185
+ TokenStream :: new ( vec ! [ ( tree, Spacing :: Alone ) ] )
188
186
}
189
187
}
190
188
191
- impl From < TokenTree > for TreeAndJoint {
192
- fn from ( tree : TokenTree ) -> TreeAndJoint {
193
- ( tree, NonJoint )
189
+ impl From < TokenTree > for TreeAndSpacing {
190
+ fn from ( tree : TokenTree ) -> TreeAndSpacing {
191
+ ( tree, Spacing :: Alone )
194
192
}
195
193
}
196
194
197
195
impl iter:: FromIterator < TokenTree > for TokenStream {
198
196
fn from_iter < I : IntoIterator < Item = TokenTree > > ( iter : I ) -> Self {
199
- TokenStream :: new ( iter. into_iter ( ) . map ( Into :: into) . collect :: < Vec < TreeAndJoint > > ( ) )
197
+ TokenStream :: new ( iter. into_iter ( ) . map ( Into :: into) . collect :: < Vec < TreeAndSpacing > > ( ) )
200
198
}
201
199
}
202
200
@@ -209,7 +207,7 @@ impl PartialEq<TokenStream> for TokenStream {
209
207
}
210
208
211
209
impl TokenStream {
212
- pub fn new ( streams : Vec < TreeAndJoint > ) -> TokenStream {
210
+ pub fn new ( streams : Vec < TreeAndSpacing > ) -> TokenStream {
213
211
TokenStream ( Lrc :: new ( streams) )
214
212
}
215
213
@@ -320,11 +318,11 @@ impl TokenStreamBuilder {
320
318
// If `self` is not empty and the last tree within the last stream is a
321
319
// token tree marked with `Joint`...
322
320
if let Some ( TokenStream ( ref mut last_stream_lrc) ) = self . 0 . last_mut ( ) {
323
- if let Some ( ( TokenTree :: Token ( last_token) , Joint ) ) = last_stream_lrc. last ( ) {
321
+ if let Some ( ( TokenTree :: Token ( last_token) , Spacing :: Joint ) ) = last_stream_lrc. last ( ) {
324
322
// ...and `stream` is not empty and the first tree within it is
325
323
// a token tree...
326
324
let TokenStream ( ref mut stream_lrc) = stream;
327
- if let Some ( ( TokenTree :: Token ( token) , is_joint ) ) = stream_lrc. first ( ) {
325
+ if let Some ( ( TokenTree :: Token ( token) , spacing ) ) = stream_lrc. first ( ) {
328
326
// ...and the two tokens can be glued together...
329
327
if let Some ( glued_tok) = last_token. glue ( & token) {
330
328
// ...then do so, by overwriting the last token
@@ -337,8 +335,7 @@ impl TokenStreamBuilder {
337
335
// Overwrite the last token tree with the merged
338
336
// token.
339
337
let last_vec_mut = Lrc :: make_mut ( last_stream_lrc) ;
340
- * last_vec_mut. last_mut ( ) . unwrap ( ) =
341
- ( TokenTree :: Token ( glued_tok) , * is_joint) ;
338
+ * last_vec_mut. last_mut ( ) . unwrap ( ) = ( TokenTree :: Token ( glued_tok) , * spacing) ;
342
339
343
340
// Remove the first token tree from `stream`. (This
344
341
// is almost always the only tree in `stream`.)
@@ -375,7 +372,7 @@ impl Iterator for Cursor {
375
372
type Item = TokenTree ;
376
373
377
374
fn next ( & mut self ) -> Option < TokenTree > {
378
- self . next_with_joint ( ) . map ( |( tree, _) | tree)
375
+ self . next_with_spacing ( ) . map ( |( tree, _) | tree)
379
376
}
380
377
}
381
378
@@ -384,7 +381,7 @@ impl Cursor {
384
381
Cursor { stream, index : 0 }
385
382
}
386
383
387
- pub fn next_with_joint ( & mut self ) -> Option < TreeAndJoint > {
384
+ pub fn next_with_spacing ( & mut self ) -> Option < TreeAndSpacing > {
388
385
if self . index < self . stream . len ( ) {
389
386
self . index += 1 ;
390
387
Some ( self . stream . 0 [ self . index - 1 ] . clone ( ) )
0 commit comments