14
14
//! ownership of the original.
15
15
16
16
use crate :: ast:: { AttrStyle , StmtKind } ;
17
- use crate :: ast_traits:: { HasAttrs , HasSpan , HasTokens } ;
17
+ use crate :: ast_traits:: { HasAttrs , HasTokens } ;
18
18
use crate :: token:: { self , Delimiter , Nonterminal , Token , TokenKind } ;
19
19
use crate :: AttrVec ;
20
20
@@ -170,8 +170,8 @@ pub enum AttrTokenTree {
170
170
Delimited ( DelimSpan , DelimSpacing , Delimiter , AttrTokenStream ) ,
171
171
/// Stores the attributes for an attribute target,
172
172
/// along with the tokens for that attribute target.
173
- /// See `AttributesData ` for more information
174
- Attributes ( AttributesData ) ,
173
+ /// See `AttrsTarget ` for more information
174
+ AttrsTarget ( AttrsTarget ) ,
175
175
}
176
176
177
177
impl AttrTokenStream {
@@ -180,7 +180,7 @@ impl AttrTokenStream {
180
180
}
181
181
182
182
/// Converts this `AttrTokenStream` to a plain `Vec<TokenTree>`.
183
- /// During conversion, `AttrTokenTree::Attributes ` get 'flattened'
183
+ /// During conversion, `AttrTokenTree::AttrsTarget ` get 'flattened'
184
184
/// back to a `TokenStream` of the form `outer_attr attr_target`.
185
185
/// If there are inner attributes, they are inserted into the proper
186
186
/// place in the attribute target tokens.
@@ -199,13 +199,13 @@ impl AttrTokenStream {
199
199
TokenStream :: new ( stream. to_token_trees ( ) ) ,
200
200
) )
201
201
}
202
- AttrTokenTree :: Attributes ( data ) => {
203
- let idx = data
202
+ AttrTokenTree :: AttrsTarget ( target ) => {
203
+ let idx = target
204
204
. attrs
205
205
. partition_point ( |attr| matches ! ( attr. style, crate :: AttrStyle :: Outer ) ) ;
206
- let ( outer_attrs, inner_attrs) = data . attrs . split_at ( idx) ;
206
+ let ( outer_attrs, inner_attrs) = target . attrs . split_at ( idx) ;
207
207
208
- let mut target_tokens = data . tokens . to_attr_token_stream ( ) . to_token_trees ( ) ;
208
+ let mut target_tokens = target . tokens . to_attr_token_stream ( ) . to_token_trees ( ) ;
209
209
if !inner_attrs. is_empty ( ) {
210
210
let mut found = false ;
211
211
// Check the last two trees (to account for a trailing semi)
@@ -227,7 +227,7 @@ impl AttrTokenStream {
227
227
228
228
let mut stream = TokenStream :: default ( ) ;
229
229
for inner_attr in inner_attrs {
230
- stream. push_stream ( inner_attr. tokens ( ) ) ;
230
+ stream. push_stream ( inner_attr. get_tokens ( ) ) ;
231
231
}
232
232
stream. push_stream ( delim_tokens. clone ( ) ) ;
233
233
* tree = TokenTree :: Delimited ( * span, * spacing, * delim, stream) ;
@@ -242,7 +242,7 @@ impl AttrTokenStream {
242
242
) ;
243
243
}
244
244
for attr in outer_attrs {
245
- res. extend ( attr. tokens ( ) . 0 . iter ( ) . cloned ( ) ) ;
245
+ res. extend ( attr. get_tokens ( ) . 0 . iter ( ) . cloned ( ) ) ;
246
246
}
247
247
res. extend ( target_tokens) ;
248
248
}
@@ -262,7 +262,7 @@ impl AttrTokenStream {
262
262
/// have an `attrs` field containing the `#[cfg(FALSE)]` attr,
263
263
/// and a `tokens` field storing the (unparsed) tokens `struct Foo {}`
264
264
#[ derive( Clone , Debug , Encodable , Decodable ) ]
265
- pub struct AttributesData {
265
+ pub struct AttrsTarget {
266
266
/// Attributes, both outer and inner.
267
267
/// These are stored in the original order that they were parsed in.
268
268
pub attrs : AttrVec ,
@@ -436,17 +436,17 @@ impl TokenStream {
436
436
TokenStream :: new ( vec ! [ TokenTree :: token_alone( kind, span) ] )
437
437
}
438
438
439
- pub fn from_ast ( node : & ( impl HasAttrs + HasSpan + HasTokens + fmt:: Debug ) ) -> TokenStream {
439
+ pub fn from_ast ( node : & ( impl HasAttrs + HasTokens + fmt:: Debug ) ) -> TokenStream {
440
440
let Some ( tokens) = node. tokens ( ) else {
441
- panic ! ( "missing tokens for node at {:?}: {:?}" , node . span ( ) , node) ;
441
+ panic ! ( "missing tokens for node: {:?}" , node) ;
442
442
} ;
443
443
let attrs = node. attrs ( ) ;
444
444
let attr_stream = if attrs. is_empty ( ) {
445
445
tokens. to_attr_token_stream ( )
446
446
} else {
447
- let attr_data =
448
- AttributesData { attrs : attrs. iter ( ) . cloned ( ) . collect ( ) , tokens : tokens. clone ( ) } ;
449
- AttrTokenStream :: new ( vec ! [ AttrTokenTree :: Attributes ( attr_data ) ] )
447
+ let target =
448
+ AttrsTarget { attrs : attrs. iter ( ) . cloned ( ) . collect ( ) , tokens : tokens. clone ( ) } ;
449
+ AttrTokenStream :: new ( vec ! [ AttrTokenTree :: AttrsTarget ( target ) ] )
450
450
} ;
451
451
TokenStream :: new ( attr_stream. to_token_trees ( ) )
452
452
}
@@ -765,6 +765,7 @@ mod size_asserts {
765
765
static_assert_size ! ( AttrTokenStream , 8 ) ;
766
766
static_assert_size ! ( AttrTokenTree , 32 ) ;
767
767
static_assert_size ! ( LazyAttrTokenStream , 8 ) ;
768
+ static_assert_size ! ( Option <LazyAttrTokenStream >, 8 ) ; // must be small, used in many AST nodes
768
769
static_assert_size ! ( TokenStream , 8 ) ;
769
770
static_assert_size ! ( TokenTree , 32 ) ;
770
771
// tidy-alphabetical-end
0 commit comments