@@ -8,7 +8,7 @@ use crate::ast::{Path, PathSegment};
88use crate :: mut_visit:: visit_clobber;
99use crate :: ptr:: P ;
1010use crate :: token:: { self , CommentKind , Token } ;
11- use crate :: tokenstream:: { DelimSpan , TokenStream , TokenTree , TreeAndSpacing } ;
11+ use crate :: tokenstream:: { DelimSpan , LazyTokenStream , TokenStream , TokenTree , TreeAndSpacing } ;
1212
1313use rustc_index:: bit_set:: GrowableBitSet ;
1414use rustc_span:: source_map:: { BytePos , Spanned } ;
@@ -120,15 +120,15 @@ impl NestedMetaItem {
120120impl Attribute {
121121 pub fn has_name ( & self , name : Symbol ) -> bool {
122122 match self . kind {
123- AttrKind :: Normal ( ref item) => item. path == name,
123+ AttrKind :: Normal ( ref item, _ ) => item. path == name,
124124 AttrKind :: DocComment ( ..) => false ,
125125 }
126126 }
127127
128128 /// For a single-segment attribute, returns its name; otherwise, returns `None`.
129129 pub fn ident ( & self ) -> Option < Ident > {
130130 match self . kind {
131- AttrKind :: Normal ( ref item) => {
131+ AttrKind :: Normal ( ref item, _ ) => {
132132 if item. path . segments . len ( ) == 1 {
133133 Some ( item. path . segments [ 0 ] . ident )
134134 } else {
@@ -144,14 +144,14 @@ impl Attribute {
144144
145145 pub fn value_str ( & self ) -> Option < Symbol > {
146146 match self . kind {
147- AttrKind :: Normal ( ref item) => item. meta ( self . span ) . and_then ( |meta| meta. value_str ( ) ) ,
147+ AttrKind :: Normal ( ref item, _ ) => item. meta ( self . span ) . and_then ( |meta| meta. value_str ( ) ) ,
148148 AttrKind :: DocComment ( ..) => None ,
149149 }
150150 }
151151
152152 pub fn meta_item_list ( & self ) -> Option < Vec < NestedMetaItem > > {
153153 match self . kind {
154- AttrKind :: Normal ( ref item) => match item. meta ( self . span ) {
154+ AttrKind :: Normal ( ref item, _ ) => match item. meta ( self . span ) {
155155 Some ( MetaItem { kind : MetaItemKind :: List ( list) , .. } ) => Some ( list) ,
156156 _ => None ,
157157 } ,
@@ -160,7 +160,7 @@ impl Attribute {
160160 }
161161
162162 pub fn is_word ( & self ) -> bool {
163- if let AttrKind :: Normal ( item) = & self . kind {
163+ if let AttrKind :: Normal ( item, _ ) = & self . kind {
164164 matches ! ( item. args, MacArgs :: Empty )
165165 } else {
166166 false
@@ -246,15 +246,15 @@ impl AttrItem {
246246impl Attribute {
247247 pub fn is_doc_comment ( & self ) -> bool {
248248 match self . kind {
249- AttrKind :: Normal ( _ ) => false ,
249+ AttrKind :: Normal ( .. ) => false ,
250250 AttrKind :: DocComment ( ..) => true ,
251251 }
252252 }
253253
254254 pub fn doc_str ( & self ) -> Option < Symbol > {
255255 match self . kind {
256256 AttrKind :: DocComment ( .., data) => Some ( data) ,
257- AttrKind :: Normal ( ref item) if item. path == sym:: doc => {
257+ AttrKind :: Normal ( ref item, _ ) if item. path == sym:: doc => {
258258 item. meta ( self . span ) . and_then ( |meta| meta. value_str ( ) )
259259 }
260260 _ => None ,
@@ -263,25 +263,37 @@ impl Attribute {
263263
264264 pub fn get_normal_item ( & self ) -> & AttrItem {
265265 match self . kind {
266- AttrKind :: Normal ( ref item) => item,
266+ AttrKind :: Normal ( ref item, _ ) => item,
267267 AttrKind :: DocComment ( ..) => panic ! ( "unexpected doc comment" ) ,
268268 }
269269 }
270270
271271 pub fn unwrap_normal_item ( self ) -> AttrItem {
272272 match self . kind {
273- AttrKind :: Normal ( item) => item,
273+ AttrKind :: Normal ( item, _ ) => item,
274274 AttrKind :: DocComment ( ..) => panic ! ( "unexpected doc comment" ) ,
275275 }
276276 }
277277
278278 /// Extracts the MetaItem from inside this Attribute.
279279 pub fn meta ( & self ) -> Option < MetaItem > {
280280 match self . kind {
281- AttrKind :: Normal ( ref item) => item. meta ( self . span ) ,
281+ AttrKind :: Normal ( ref item, _ ) => item. meta ( self . span ) ,
282282 AttrKind :: DocComment ( ..) => None ,
283283 }
284284 }
285+
286+ pub fn tokens ( & self ) -> TokenStream {
287+ match self . kind {
288+ AttrKind :: Normal ( _, ref tokens) => tokens
289+ . as_ref ( )
290+ . unwrap_or_else ( || panic ! ( "attribute is missing tokens: {:?}" , self ) )
291+ . create_token_stream ( ) ,
292+ AttrKind :: DocComment ( comment_kind, data) => TokenStream :: from ( TokenTree :: Token (
293+ Token :: new ( token:: DocComment ( comment_kind, self . style , data) , self . span ) ,
294+ ) ) ,
295+ }
296+ }
285297}
286298
287299/* Constructors */
@@ -321,11 +333,16 @@ crate fn mk_attr_id() -> AttrId {
321333}
322334
323335pub fn mk_attr ( style : AttrStyle , path : Path , args : MacArgs , span : Span ) -> Attribute {
324- mk_attr_from_item ( style , AttrItem { path, args, tokens : None } , span)
336+ mk_attr_from_item ( AttrItem { path, args, tokens : None } , None , style , span)
325337}
326338
327- pub fn mk_attr_from_item ( style : AttrStyle , item : AttrItem , span : Span ) -> Attribute {
328- Attribute { kind : AttrKind :: Normal ( item) , id : mk_attr_id ( ) , style, span, tokens : None }
339+ pub fn mk_attr_from_item (
340+ item : AttrItem ,
341+ tokens : Option < LazyTokenStream > ,
342+ style : AttrStyle ,
343+ span : Span ,
344+ ) -> Attribute {
345+ Attribute { kind : AttrKind :: Normal ( item, tokens) , id : mk_attr_id ( ) , style, span }
329346}
330347
331348/// Returns an inner attribute with the given value and span.
@@ -344,13 +361,7 @@ pub fn mk_doc_comment(
344361 data : Symbol ,
345362 span : Span ,
346363) -> Attribute {
347- Attribute {
348- kind : AttrKind :: DocComment ( comment_kind, data) ,
349- id : mk_attr_id ( ) ,
350- style,
351- span,
352- tokens : None ,
353- }
364+ Attribute { kind : AttrKind :: DocComment ( comment_kind, data) , id : mk_attr_id ( ) , style, span }
354365}
355366
356367pub fn list_contains_name ( items : & [ NestedMetaItem ] , name : Symbol ) -> bool {
0 commit comments