11//! Functions dealing with attributes and meta items.
22
33use crate :: ast:: {
4- AttrArgs , AttrArgsEq , AttrId , AttrItem , AttrKind , AttrStyle , AttrVec , Attribute , Safety ,
4+ AttrArgs , AttrArgsEq , AttrId , AttrKind , AttrStyle , AttrVec , Attribute , Meta , Safety ,
55} ;
66use crate :: ast:: { DelimArgs , Expr , ExprKind , LitKind , MetaItemLit } ;
77use crate :: ast:: { MetaItem , MetaItemKind , NestedMetaItem , NormalAttr } ;
@@ -53,16 +53,16 @@ impl AttrIdGenerator {
5353}
5454
5555impl Attribute {
56- pub fn get_normal_item ( & self ) -> & AttrItem {
56+ pub fn get_normal_meta ( & self ) -> & Meta {
5757 match & self . kind {
58- AttrKind :: Normal ( normal) => & normal. item ,
58+ AttrKind :: Normal ( normal) => & normal. meta ,
5959 AttrKind :: DocComment ( ..) => panic ! ( "unexpected doc comment" ) ,
6060 }
6161 }
6262
63- pub fn unwrap_normal_item ( self ) -> AttrItem {
63+ pub fn unwrap_normal_meta ( self ) -> Meta {
6464 match self . kind {
65- AttrKind :: Normal ( normal) => normal. into_inner ( ) . item ,
65+ AttrKind :: Normal ( normal) => normal. into_inner ( ) . meta ,
6666 AttrKind :: DocComment ( ..) => panic ! ( "unexpected doc comment" ) ,
6767 }
6868 }
@@ -81,7 +81,7 @@ impl Attribute {
8181 pub fn ident ( & self ) -> Option < Ident > {
8282 match & self . kind {
8383 AttrKind :: Normal ( normal) => {
84- if let [ ident] = & * normal. item . path . segments {
84+ if let [ ident] = & * normal. meta . path . segments {
8585 Some ( ident. ident )
8686 } else {
8787 None
@@ -98,7 +98,7 @@ impl Attribute {
9898 pub fn path ( & self ) -> SmallVec < [ Symbol ; 1 ] > {
9999 match & self . kind {
100100 AttrKind :: Normal ( normal) => {
101- normal. item . path . segments . iter ( ) . map ( |s| s. ident . name ) . collect ( )
101+ normal. meta . path . segments . iter ( ) . map ( |s| s. ident . name ) . collect ( )
102102 }
103103 AttrKind :: DocComment ( ..) => smallvec ! [ sym:: doc] ,
104104 }
@@ -107,17 +107,17 @@ impl Attribute {
107107 #[ inline]
108108 pub fn has_name ( & self , name : Symbol ) -> bool {
109109 match & self . kind {
110- AttrKind :: Normal ( normal) => normal. item . path == name,
110+ AttrKind :: Normal ( normal) => normal. meta . path == name,
111111 AttrKind :: DocComment ( ..) => false ,
112112 }
113113 }
114114
115115 pub fn path_matches ( & self , name : & [ Symbol ] ) -> bool {
116116 match & self . kind {
117117 AttrKind :: Normal ( normal) => {
118- normal. item . path . segments . len ( ) == name. len ( )
118+ normal. meta . path . segments . len ( ) == name. len ( )
119119 && normal
120- . item
120+ . meta
121121 . path
122122 . segments
123123 . iter ( )
@@ -130,22 +130,22 @@ impl Attribute {
130130
131131 pub fn is_word ( & self ) -> bool {
132132 if let AttrKind :: Normal ( normal) = & self . kind {
133- matches ! ( normal. item . args, AttrArgs :: Empty )
133+ matches ! ( normal. meta . args, AttrArgs :: Empty )
134134 } else {
135135 false
136136 }
137137 }
138138
139139 pub fn meta_item_list ( & self ) -> Option < ThinVec < NestedMetaItem > > {
140140 match & self . kind {
141- AttrKind :: Normal ( normal) => normal. item . meta_item_list ( ) ,
141+ AttrKind :: Normal ( normal) => normal. meta . meta_item_list ( ) ,
142142 AttrKind :: DocComment ( ..) => None ,
143143 }
144144 }
145145
146146 pub fn value_str ( & self ) -> Option < Symbol > {
147147 match & self . kind {
148- AttrKind :: Normal ( normal) => normal. item . value_str ( ) ,
148+ AttrKind :: Normal ( normal) => normal. meta . value_str ( ) ,
149149 AttrKind :: DocComment ( ..) => None ,
150150 }
151151 }
@@ -158,8 +158,8 @@ impl Attribute {
158158 pub fn doc_str_and_comment_kind ( & self ) -> Option < ( Symbol , CommentKind ) > {
159159 match & self . kind {
160160 AttrKind :: DocComment ( kind, data) => Some ( ( * data, * kind) ) ,
161- AttrKind :: Normal ( normal) if normal. item . path == sym:: doc => {
162- normal. item . value_str ( ) . map ( |s| ( s, CommentKind :: Line ) )
161+ AttrKind :: Normal ( normal) if normal. meta . path == sym:: doc => {
162+ normal. meta . value_str ( ) . map ( |s| ( s, CommentKind :: Line ) )
163163 }
164164 _ => None ,
165165 }
@@ -172,7 +172,7 @@ impl Attribute {
172172 pub fn doc_str ( & self ) -> Option < Symbol > {
173173 match & self . kind {
174174 AttrKind :: DocComment ( .., data) => Some ( * data) ,
175- AttrKind :: Normal ( normal) if normal. item . path == sym:: doc => normal. item . value_str ( ) ,
175+ AttrKind :: Normal ( normal) if normal. meta . path == sym:: doc => normal. meta . value_str ( ) ,
176176 _ => None ,
177177 }
178178 }
@@ -190,14 +190,14 @@ impl Attribute {
190190 /// Extracts the MetaItem from inside this Attribute.
191191 pub fn meta ( & self ) -> Option < MetaItem > {
192192 match & self . kind {
193- AttrKind :: Normal ( normal) => normal. item . meta ( self . span ) ,
193+ AttrKind :: Normal ( normal) => normal. meta . meta ( self . span ) ,
194194 AttrKind :: DocComment ( ..) => None ,
195195 }
196196 }
197197
198198 pub fn meta_kind ( & self ) -> Option < MetaItemKind > {
199199 match & self . kind {
200- AttrKind :: Normal ( normal) => normal. item . meta_kind ( ) ,
200+ AttrKind :: Normal ( normal) => normal. meta . meta_kind ( ) ,
201201 AttrKind :: DocComment ( ..) => None ,
202202 }
203203 }
@@ -220,7 +220,7 @@ impl Attribute {
220220 }
221221}
222222
223- impl AttrItem {
223+ impl Meta {
224224 pub fn span ( & self ) -> Span {
225225 self . args . span ( ) . map_or ( self . path . span , |args_span| self . path . span . to ( args_span) )
226226 }
@@ -579,18 +579,18 @@ pub fn mk_attr(
579579 args : AttrArgs ,
580580 span : Span ,
581581) -> Attribute {
582- mk_attr_from_item ( g, AttrItem { unsafety, path, args, tokens : None } , None , style, span)
582+ mk_attr_from_meta ( g, Meta { unsafety, path, args, tokens : None } , None , style, span)
583583}
584584
585- pub fn mk_attr_from_item (
585+ pub fn mk_attr_from_meta (
586586 g : & AttrIdGenerator ,
587- item : AttrItem ,
587+ meta : Meta ,
588588 tokens : Option < LazyAttrTokenStream > ,
589589 style : AttrStyle ,
590590 span : Span ,
591591) -> Attribute {
592592 Attribute {
593- kind : AttrKind :: Normal ( P ( NormalAttr { item , tokens } ) ) ,
593+ kind : AttrKind :: Normal ( P ( NormalAttr { meta , tokens } ) ) ,
594594 id : g. mk_attr_id ( ) ,
595595 style,
596596 span,
0 commit comments