1414//! ownership of the original.
1515
1616use crate :: ast:: { AttrStyle , StmtKind } ;
17- use crate :: ast_traits:: { HasAttrs , HasSpan , HasTokens } ;
17+ use crate :: ast_traits:: { HasAttrs , HasTokens } ;
1818use crate :: token:: { self , Delimiter , Nonterminal , Token , TokenKind } ;
1919use crate :: AttrVec ;
2020
@@ -170,8 +170,8 @@ pub enum AttrTokenTree {
170170 Delimited ( DelimSpan , DelimSpacing , Delimiter , AttrTokenStream ) ,
171171 /// Stores the attributes for an attribute target,
172172 /// 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 ) ,
175175}
176176
177177impl AttrTokenStream {
@@ -180,7 +180,7 @@ impl AttrTokenStream {
180180 }
181181
182182 /// Converts this `AttrTokenStream` to a plain `Vec<TokenTree>`.
183- /// During conversion, `AttrTokenTree::Attributes ` get 'flattened'
183+ /// During conversion, `AttrTokenTree::AttrsTarget ` get 'flattened'
184184 /// back to a `TokenStream` of the form `outer_attr attr_target`.
185185 /// If there are inner attributes, they are inserted into the proper
186186 /// place in the attribute target tokens.
@@ -199,13 +199,13 @@ impl AttrTokenStream {
199199 TokenStream :: new ( stream. to_token_trees ( ) ) ,
200200 ) )
201201 }
202- AttrTokenTree :: Attributes ( data ) => {
203- let idx = data
202+ AttrTokenTree :: AttrsTarget ( target ) => {
203+ let idx = target
204204 . attrs
205205 . 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) ;
207207
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 ( ) ;
209209 if !inner_attrs. is_empty ( ) {
210210 let mut found = false ;
211211 // Check the last two trees (to account for a trailing semi)
@@ -227,7 +227,7 @@ impl AttrTokenStream {
227227
228228 let mut stream = TokenStream :: default ( ) ;
229229 for inner_attr in inner_attrs {
230- stream. push_stream ( inner_attr. tokens ( ) ) ;
230+ stream. push_stream ( inner_attr. get_tokens ( ) ) ;
231231 }
232232 stream. push_stream ( delim_tokens. clone ( ) ) ;
233233 * tree = TokenTree :: Delimited ( * span, * spacing, * delim, stream) ;
@@ -242,7 +242,7 @@ impl AttrTokenStream {
242242 ) ;
243243 }
244244 for attr in outer_attrs {
245- res. extend ( attr. tokens ( ) . 0 . iter ( ) . cloned ( ) ) ;
245+ res. extend ( attr. get_tokens ( ) . 0 . iter ( ) . cloned ( ) ) ;
246246 }
247247 res. extend ( target_tokens) ;
248248 }
@@ -262,7 +262,7 @@ impl AttrTokenStream {
262262/// have an `attrs` field containing the `#[cfg(FALSE)]` attr,
263263/// and a `tokens` field storing the (unparsed) tokens `struct Foo {}`
264264#[ derive( Clone , Debug , Encodable , Decodable ) ]
265- pub struct AttributesData {
265+ pub struct AttrsTarget {
266266 /// Attributes, both outer and inner.
267267 /// These are stored in the original order that they were parsed in.
268268 pub attrs : AttrVec ,
@@ -436,17 +436,17 @@ impl TokenStream {
436436 TokenStream :: new ( vec ! [ TokenTree :: token_alone( kind, span) ] )
437437 }
438438
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 {
440440 let Some ( tokens) = node. tokens ( ) else {
441- panic ! ( "missing tokens for node at {:?}: {:?}" , node . span ( ) , node) ;
441+ panic ! ( "missing tokens for node: {:?}" , node) ;
442442 } ;
443443 let attrs = node. attrs ( ) ;
444444 let attr_stream = if attrs. is_empty ( ) {
445445 tokens. to_attr_token_stream ( )
446446 } 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 ) ] )
450450 } ;
451451 TokenStream :: new ( attr_stream. to_token_trees ( ) )
452452 }
@@ -765,6 +765,7 @@ mod size_asserts {
765765 static_assert_size ! ( AttrTokenStream , 8 ) ;
766766 static_assert_size ! ( AttrTokenTree , 32 ) ;
767767 static_assert_size ! ( LazyAttrTokenStream , 8 ) ;
768+ static_assert_size ! ( Option <LazyAttrTokenStream >, 8 ) ; // must be small, used in many AST nodes
768769 static_assert_size ! ( TokenStream , 8 ) ;
769770 static_assert_size ! ( TokenTree , 32 ) ;
770771 // tidy-alphabetical-end
0 commit comments