1
1
//! Functions dealing with attributes and meta items.
2
2
3
3
use crate :: ast:: {
4
- AttrArgs , AttrArgsEq , AttrId , AttrItem , AttrKind , AttrStyle , AttrVec , Attribute , Safety ,
4
+ AttrArgs , AttrArgsEq , AttrId , AttrKind , AttrStyle , AttrVec , Attribute , Meta , Safety ,
5
5
} ;
6
6
use crate :: ast:: { DelimArgs , Expr , ExprKind , LitKind , MetaItemLit } ;
7
7
use crate :: ast:: { MetaItem , MetaItemKind , NestedMetaItem , NormalAttr } ;
@@ -53,16 +53,16 @@ impl AttrIdGenerator {
53
53
}
54
54
55
55
impl Attribute {
56
- pub fn get_normal_item ( & self ) -> & AttrItem {
56
+ pub fn get_normal_meta ( & self ) -> & Meta {
57
57
match & self . kind {
58
- AttrKind :: Normal ( normal) => & normal. item ,
58
+ AttrKind :: Normal ( normal) => & normal. meta ,
59
59
AttrKind :: DocComment ( ..) => panic ! ( "unexpected doc comment" ) ,
60
60
}
61
61
}
62
62
63
- pub fn unwrap_normal_item ( self ) -> AttrItem {
63
+ pub fn unwrap_normal_meta ( self ) -> Meta {
64
64
match self . kind {
65
- AttrKind :: Normal ( normal) => normal. into_inner ( ) . item ,
65
+ AttrKind :: Normal ( normal) => normal. into_inner ( ) . meta ,
66
66
AttrKind :: DocComment ( ..) => panic ! ( "unexpected doc comment" ) ,
67
67
}
68
68
}
@@ -81,7 +81,7 @@ impl Attribute {
81
81
pub fn ident ( & self ) -> Option < Ident > {
82
82
match & self . kind {
83
83
AttrKind :: Normal ( normal) => {
84
- if let [ ident] = & * normal. item . path . segments {
84
+ if let [ ident] = & * normal. meta . path . segments {
85
85
Some ( ident. ident )
86
86
} else {
87
87
None
@@ -98,7 +98,7 @@ impl Attribute {
98
98
pub fn path ( & self ) -> SmallVec < [ Symbol ; 1 ] > {
99
99
match & self . kind {
100
100
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 ( )
102
102
}
103
103
AttrKind :: DocComment ( ..) => smallvec ! [ sym:: doc] ,
104
104
}
@@ -107,17 +107,17 @@ impl Attribute {
107
107
#[ inline]
108
108
pub fn has_name ( & self , name : Symbol ) -> bool {
109
109
match & self . kind {
110
- AttrKind :: Normal ( normal) => normal. item . path == name,
110
+ AttrKind :: Normal ( normal) => normal. meta . path == name,
111
111
AttrKind :: DocComment ( ..) => false ,
112
112
}
113
113
}
114
114
115
115
pub fn path_matches ( & self , name : & [ Symbol ] ) -> bool {
116
116
match & self . kind {
117
117
AttrKind :: Normal ( normal) => {
118
- normal. item . path . segments . len ( ) == name. len ( )
118
+ normal. meta . path . segments . len ( ) == name. len ( )
119
119
&& normal
120
- . item
120
+ . meta
121
121
. path
122
122
. segments
123
123
. iter ( )
@@ -130,22 +130,22 @@ impl Attribute {
130
130
131
131
pub fn is_word ( & self ) -> bool {
132
132
if let AttrKind :: Normal ( normal) = & self . kind {
133
- matches ! ( normal. item . args, AttrArgs :: Empty )
133
+ matches ! ( normal. meta . args, AttrArgs :: Empty )
134
134
} else {
135
135
false
136
136
}
137
137
}
138
138
139
139
pub fn meta_item_list ( & self ) -> Option < ThinVec < NestedMetaItem > > {
140
140
match & self . kind {
141
- AttrKind :: Normal ( normal) => normal. item . meta_item_list ( ) ,
141
+ AttrKind :: Normal ( normal) => normal. meta . meta_item_list ( ) ,
142
142
AttrKind :: DocComment ( ..) => None ,
143
143
}
144
144
}
145
145
146
146
pub fn value_str ( & self ) -> Option < Symbol > {
147
147
match & self . kind {
148
- AttrKind :: Normal ( normal) => normal. item . value_str ( ) ,
148
+ AttrKind :: Normal ( normal) => normal. meta . value_str ( ) ,
149
149
AttrKind :: DocComment ( ..) => None ,
150
150
}
151
151
}
@@ -158,8 +158,8 @@ impl Attribute {
158
158
pub fn doc_str_and_comment_kind ( & self ) -> Option < ( Symbol , CommentKind ) > {
159
159
match & self . kind {
160
160
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 ) )
163
163
}
164
164
_ => None ,
165
165
}
@@ -172,7 +172,7 @@ impl Attribute {
172
172
pub fn doc_str ( & self ) -> Option < Symbol > {
173
173
match & self . kind {
174
174
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 ( ) ,
176
176
_ => None ,
177
177
}
178
178
}
@@ -190,14 +190,14 @@ impl Attribute {
190
190
/// Extracts the MetaItem from inside this Attribute.
191
191
pub fn meta ( & self ) -> Option < MetaItem > {
192
192
match & self . kind {
193
- AttrKind :: Normal ( normal) => normal. item . meta ( self . span ) ,
193
+ AttrKind :: Normal ( normal) => normal. meta . meta ( self . span ) ,
194
194
AttrKind :: DocComment ( ..) => None ,
195
195
}
196
196
}
197
197
198
198
pub fn meta_kind ( & self ) -> Option < MetaItemKind > {
199
199
match & self . kind {
200
- AttrKind :: Normal ( normal) => normal. item . meta_kind ( ) ,
200
+ AttrKind :: Normal ( normal) => normal. meta . meta_kind ( ) ,
201
201
AttrKind :: DocComment ( ..) => None ,
202
202
}
203
203
}
@@ -220,7 +220,7 @@ impl Attribute {
220
220
}
221
221
}
222
222
223
- impl AttrItem {
223
+ impl Meta {
224
224
pub fn span ( & self ) -> Span {
225
225
self . args . span ( ) . map_or ( self . path . span , |args_span| self . path . span . to ( args_span) )
226
226
}
@@ -579,18 +579,18 @@ pub fn mk_attr(
579
579
args : AttrArgs ,
580
580
span : Span ,
581
581
) -> 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)
583
583
}
584
584
585
- pub fn mk_attr_from_item (
585
+ pub fn mk_attr_from_meta (
586
586
g : & AttrIdGenerator ,
587
- item : AttrItem ,
587
+ meta : Meta ,
588
588
tokens : Option < LazyAttrTokenStream > ,
589
589
style : AttrStyle ,
590
590
span : Span ,
591
591
) -> Attribute {
592
592
Attribute {
593
- kind : AttrKind :: Normal ( P ( NormalAttr { item , tokens } ) ) ,
593
+ kind : AttrKind :: Normal ( P ( NormalAttr { meta , tokens } ) ) ,
594
594
id : g. mk_attr_id ( ) ,
595
595
style,
596
596
span,
0 commit comments