@@ -117,17 +117,20 @@ impl Attrs {
117
117
}
118
118
119
119
impl Attrs {
120
- pub fn by_key < ' attrs > ( & ' attrs self , key : & ' attrs Symbol ) -> AttrQuery < ' attrs > {
120
+ #[ inline]
121
+ pub fn by_key ( & self , key : Symbol ) -> AttrQuery < ' _ > {
121
122
AttrQuery { attrs : self , key }
122
123
}
123
124
125
+ #[ inline]
124
126
pub fn rust_analyzer_tool ( & self ) -> impl Iterator < Item = & Attr > {
125
127
self . iter ( )
126
128
. filter ( |& attr| attr. path . segments ( ) . first ( ) . is_some_and ( |s| * s == sym:: rust_analyzer) )
127
129
}
128
130
131
+ #[ inline]
129
132
pub fn cfg ( & self ) -> Option < CfgExpr > {
130
- let mut cfgs = self . by_key ( & sym:: cfg) . tt_values ( ) . map ( CfgExpr :: parse) ;
133
+ let mut cfgs = self . by_key ( sym:: cfg) . tt_values ( ) . map ( CfgExpr :: parse) ;
131
134
let first = cfgs. next ( ) ?;
132
135
match cfgs. next ( ) {
133
136
Some ( second) => {
@@ -138,63 +141,76 @@ impl Attrs {
138
141
}
139
142
}
140
143
144
+ #[ inline]
141
145
pub fn cfgs ( & self ) -> impl Iterator < Item = CfgExpr > + ' _ {
142
- self . by_key ( & sym:: cfg) . tt_values ( ) . map ( CfgExpr :: parse)
146
+ self . by_key ( sym:: cfg) . tt_values ( ) . map ( CfgExpr :: parse)
143
147
}
144
148
149
+ #[ inline]
145
150
pub ( crate ) fn is_cfg_enabled ( & self , cfg_options : & CfgOptions ) -> bool {
146
151
match self . cfg ( ) {
147
152
None => true ,
148
153
Some ( cfg) => cfg_options. check ( & cfg) != Some ( false ) ,
149
154
}
150
155
}
151
156
157
+ #[ inline]
152
158
pub fn lang ( & self ) -> Option < & Symbol > {
153
- self . by_key ( & sym:: lang) . string_value ( )
159
+ self . by_key ( sym:: lang) . string_value ( )
154
160
}
155
161
162
+ #[ inline]
156
163
pub fn lang_item ( & self ) -> Option < LangItem > {
157
- self . by_key ( & sym:: lang) . string_value ( ) . and_then ( LangItem :: from_symbol)
164
+ self . by_key ( sym:: lang) . string_value ( ) . and_then ( LangItem :: from_symbol)
158
165
}
159
166
167
+ #[ inline]
160
168
pub fn has_doc_hidden ( & self ) -> bool {
161
- self . by_key ( & sym:: doc) . tt_values ( ) . any ( |tt| {
169
+ self . by_key ( sym:: doc) . tt_values ( ) . any ( |tt| {
162
170
tt. top_subtree ( ) . delimiter . kind == DelimiterKind :: Parenthesis &&
163
171
matches ! ( tt. token_trees( ) . flat_tokens( ) , [ tt:: TokenTree :: Leaf ( tt:: Leaf :: Ident ( ident) ) ] if ident. sym == sym:: hidden)
164
172
} )
165
173
}
166
174
175
+ #[ inline]
167
176
pub fn has_doc_notable_trait ( & self ) -> bool {
168
- self . by_key ( & sym:: doc) . tt_values ( ) . any ( |tt| {
177
+ self . by_key ( sym:: doc) . tt_values ( ) . any ( |tt| {
169
178
tt. top_subtree ( ) . delimiter . kind == DelimiterKind :: Parenthesis &&
170
179
matches ! ( tt. token_trees( ) . flat_tokens( ) , [ tt:: TokenTree :: Leaf ( tt:: Leaf :: Ident ( ident) ) ] if ident. sym == sym:: notable_trait)
171
180
} )
172
181
}
173
182
183
+ #[ inline]
174
184
pub fn doc_exprs ( & self ) -> impl Iterator < Item = DocExpr > + ' _ {
175
- self . by_key ( & sym:: doc) . tt_values ( ) . map ( DocExpr :: parse)
185
+ self . by_key ( sym:: doc) . tt_values ( ) . map ( DocExpr :: parse)
176
186
}
177
187
188
+ #[ inline]
178
189
pub fn doc_aliases ( & self ) -> impl Iterator < Item = Symbol > + ' _ {
179
190
self . doc_exprs ( ) . flat_map ( |doc_expr| doc_expr. aliases ( ) . to_vec ( ) )
180
191
}
181
192
193
+ #[ inline]
182
194
pub fn export_name ( & self ) -> Option < & Symbol > {
183
- self . by_key ( & sym:: export_name) . string_value ( )
195
+ self . by_key ( sym:: export_name) . string_value ( )
184
196
}
185
197
198
+ #[ inline]
186
199
pub fn is_proc_macro ( & self ) -> bool {
187
- self . by_key ( & sym:: proc_macro) . exists ( )
200
+ self . by_key ( sym:: proc_macro) . exists ( )
188
201
}
189
202
203
+ #[ inline]
190
204
pub fn is_proc_macro_attribute ( & self ) -> bool {
191
- self . by_key ( & sym:: proc_macro_attribute) . exists ( )
205
+ self . by_key ( sym:: proc_macro_attribute) . exists ( )
192
206
}
193
207
208
+ #[ inline]
194
209
pub fn is_proc_macro_derive ( & self ) -> bool {
195
- self . by_key ( & sym:: proc_macro_derive) . exists ( )
210
+ self . by_key ( sym:: proc_macro_derive) . exists ( )
196
211
}
197
212
213
+ #[ inline]
198
214
pub fn is_test ( & self ) -> bool {
199
215
self . iter ( ) . any ( |it| {
200
216
it. path ( )
@@ -210,29 +226,34 @@ impl Attrs {
210
226
} )
211
227
}
212
228
229
+ #[ inline]
213
230
pub fn is_ignore ( & self ) -> bool {
214
- self . by_key ( & sym:: ignore) . exists ( )
231
+ self . by_key ( sym:: ignore) . exists ( )
215
232
}
216
233
234
+ #[ inline]
217
235
pub fn is_bench ( & self ) -> bool {
218
- self . by_key ( & sym:: bench) . exists ( )
236
+ self . by_key ( sym:: bench) . exists ( )
219
237
}
220
238
239
+ #[ inline]
221
240
pub fn is_unstable ( & self ) -> bool {
222
- self . by_key ( & sym:: unstable) . exists ( )
241
+ self . by_key ( sym:: unstable) . exists ( )
223
242
}
224
243
244
+ #[ inline]
225
245
pub fn rustc_legacy_const_generics ( & self ) -> Option < Box < Box < [ u32 ] > > > {
226
- self . by_key ( & sym:: rustc_legacy_const_generics)
246
+ self . by_key ( sym:: rustc_legacy_const_generics)
227
247
. tt_values ( )
228
248
. next ( )
229
249
. map ( parse_rustc_legacy_const_generics)
230
250
. filter ( |it| !it. is_empty ( ) )
231
251
. map ( Box :: new)
232
252
}
233
253
254
+ #[ inline]
234
255
pub fn repr ( & self ) -> Option < ReprOptions > {
235
- self . by_key ( & sym:: repr) . tt_values ( ) . filter_map ( parse_repr_tt) . fold ( None , |acc, repr| {
256
+ self . by_key ( sym:: repr) . tt_values ( ) . filter_map ( parse_repr_tt) . fold ( None , |acc, repr| {
236
257
acc. map_or ( Some ( repr) , |mut acc| {
237
258
merge_repr ( & mut acc, repr) ;
238
259
Some ( acc)
@@ -681,36 +702,42 @@ impl AttrSourceMap {
681
702
}
682
703
}
683
704
684
- #[ derive( Debug , Clone , Copy ) ]
705
+ #[ derive( Debug , Clone ) ]
685
706
pub struct AttrQuery < ' attr > {
686
707
attrs : & ' attr Attrs ,
687
- key : & ' attr Symbol ,
708
+ key : Symbol ,
688
709
}
689
710
690
711
impl < ' attr > AttrQuery < ' attr > {
712
+ #[ inline]
691
713
pub fn tt_values ( self ) -> impl Iterator < Item = & ' attr crate :: tt:: TopSubtree > {
692
714
self . attrs ( ) . filter_map ( |attr| attr. token_tree_value ( ) )
693
715
}
694
716
717
+ #[ inline]
695
718
pub fn string_value ( self ) -> Option < & ' attr Symbol > {
696
719
self . attrs ( ) . find_map ( |attr| attr. string_value ( ) )
697
720
}
698
721
722
+ #[ inline]
699
723
pub fn string_value_with_span ( self ) -> Option < ( & ' attr Symbol , span:: Span ) > {
700
724
self . attrs ( ) . find_map ( |attr| attr. string_value_with_span ( ) )
701
725
}
702
726
727
+ #[ inline]
703
728
pub fn string_value_unescape ( self ) -> Option < Cow < ' attr , str > > {
704
729
self . attrs ( ) . find_map ( |attr| attr. string_value_unescape ( ) )
705
730
}
706
731
732
+ #[ inline]
707
733
pub fn exists ( self ) -> bool {
708
734
self . attrs ( ) . next ( ) . is_some ( )
709
735
}
710
736
737
+ #[ inline]
711
738
pub fn attrs ( self ) -> impl Iterator < Item = & ' attr Attr > + Clone {
712
739
let key = self . key ;
713
- self . attrs . iter ( ) . filter ( move |attr| attr. path . as_ident ( ) . is_some_and ( |s| * s == * key) )
740
+ self . attrs . iter ( ) . filter ( move |attr| attr. path . as_ident ( ) . is_some_and ( |s| * s == key) )
714
741
}
715
742
716
743
/// Find string value for a specific key inside token tree
@@ -719,10 +746,11 @@ impl<'attr> AttrQuery<'attr> {
719
746
/// #[doc(html_root_url = "url")]
720
747
/// ^^^^^^^^^^^^^ key
721
748
/// ```
722
- pub fn find_string_value_in_tt ( self , key : & ' attr Symbol ) -> Option < & ' attr str > {
749
+ #[ inline]
750
+ pub fn find_string_value_in_tt ( self , key : Symbol ) -> Option < & ' attr str > {
723
751
self . tt_values ( ) . find_map ( |tt| {
724
752
let name = tt. iter ( )
725
- . skip_while ( |tt| !matches ! ( tt, TtElement :: Leaf ( tt:: Leaf :: Ident ( tt:: Ident { sym, ..} ) ) if * sym == * key) )
753
+ . skip_while ( |tt| !matches ! ( tt, TtElement :: Leaf ( tt:: Leaf :: Ident ( tt:: Ident { sym, ..} ) ) if * sym == key) )
726
754
. nth ( 2 ) ;
727
755
728
756
match name {
0 commit comments