@@ -117,17 +117,20 @@ impl Attrs {
117117}
118118
119119impl 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 < ' _ > {
121122 AttrQuery { attrs : self , key }
122123 }
123124
125+ #[ inline]
124126 pub fn rust_analyzer_tool ( & self ) -> impl Iterator < Item = & Attr > {
125127 self . iter ( )
126128 . filter ( |& attr| attr. path . segments ( ) . first ( ) . is_some_and ( |s| * s == sym:: rust_analyzer) )
127129 }
128130
131+ #[ inline]
129132 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) ;
131134 let first = cfgs. next ( ) ?;
132135 match cfgs. next ( ) {
133136 Some ( second) => {
@@ -138,63 +141,76 @@ impl Attrs {
138141 }
139142 }
140143
144+ #[ inline]
141145 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)
143147 }
144148
149+ #[ inline]
145150 pub ( crate ) fn is_cfg_enabled ( & self , cfg_options : & CfgOptions ) -> bool {
146151 match self . cfg ( ) {
147152 None => true ,
148153 Some ( cfg) => cfg_options. check ( & cfg) != Some ( false ) ,
149154 }
150155 }
151156
157+ #[ inline]
152158 pub fn lang ( & self ) -> Option < & Symbol > {
153- self . by_key ( & sym:: lang) . string_value ( )
159+ self . by_key ( sym:: lang) . string_value ( )
154160 }
155161
162+ #[ inline]
156163 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)
158165 }
159166
167+ #[ inline]
160168 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| {
162170 tt. top_subtree ( ) . delimiter . kind == DelimiterKind :: Parenthesis &&
163171 matches ! ( tt. token_trees( ) . flat_tokens( ) , [ tt:: TokenTree :: Leaf ( tt:: Leaf :: Ident ( ident) ) ] if ident. sym == sym:: hidden)
164172 } )
165173 }
166174
175+ #[ inline]
167176 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| {
169178 tt. top_subtree ( ) . delimiter . kind == DelimiterKind :: Parenthesis &&
170179 matches ! ( tt. token_trees( ) . flat_tokens( ) , [ tt:: TokenTree :: Leaf ( tt:: Leaf :: Ident ( ident) ) ] if ident. sym == sym:: notable_trait)
171180 } )
172181 }
173182
183+ #[ inline]
174184 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)
176186 }
177187
188+ #[ inline]
178189 pub fn doc_aliases ( & self ) -> impl Iterator < Item = Symbol > + ' _ {
179190 self . doc_exprs ( ) . flat_map ( |doc_expr| doc_expr. aliases ( ) . to_vec ( ) )
180191 }
181192
193+ #[ inline]
182194 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 ( )
184196 }
185197
198+ #[ inline]
186199 pub fn is_proc_macro ( & self ) -> bool {
187- self . by_key ( & sym:: proc_macro) . exists ( )
200+ self . by_key ( sym:: proc_macro) . exists ( )
188201 }
189202
203+ #[ inline]
190204 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 ( )
192206 }
193207
208+ #[ inline]
194209 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 ( )
196211 }
197212
213+ #[ inline]
198214 pub fn is_test ( & self ) -> bool {
199215 self . iter ( ) . any ( |it| {
200216 it. path ( )
@@ -210,29 +226,34 @@ impl Attrs {
210226 } )
211227 }
212228
229+ #[ inline]
213230 pub fn is_ignore ( & self ) -> bool {
214- self . by_key ( & sym:: ignore) . exists ( )
231+ self . by_key ( sym:: ignore) . exists ( )
215232 }
216233
234+ #[ inline]
217235 pub fn is_bench ( & self ) -> bool {
218- self . by_key ( & sym:: bench) . exists ( )
236+ self . by_key ( sym:: bench) . exists ( )
219237 }
220238
239+ #[ inline]
221240 pub fn is_unstable ( & self ) -> bool {
222- self . by_key ( & sym:: unstable) . exists ( )
241+ self . by_key ( sym:: unstable) . exists ( )
223242 }
224243
244+ #[ inline]
225245 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)
227247 . tt_values ( )
228248 . next ( )
229249 . map ( parse_rustc_legacy_const_generics)
230250 . filter ( |it| !it. is_empty ( ) )
231251 . map ( Box :: new)
232252 }
233253
254+ #[ inline]
234255 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| {
236257 acc. map_or ( Some ( repr) , |mut acc| {
237258 merge_repr ( & mut acc, repr) ;
238259 Some ( acc)
@@ -681,36 +702,42 @@ impl AttrSourceMap {
681702 }
682703}
683704
684- #[ derive( Debug , Clone , Copy ) ]
705+ #[ derive( Debug , Clone ) ]
685706pub struct AttrQuery < ' attr > {
686707 attrs : & ' attr Attrs ,
687- key : & ' attr Symbol ,
708+ key : Symbol ,
688709}
689710
690711impl < ' attr > AttrQuery < ' attr > {
712+ #[ inline]
691713 pub fn tt_values ( self ) -> impl Iterator < Item = & ' attr crate :: tt:: TopSubtree > {
692714 self . attrs ( ) . filter_map ( |attr| attr. token_tree_value ( ) )
693715 }
694716
717+ #[ inline]
695718 pub fn string_value ( self ) -> Option < & ' attr Symbol > {
696719 self . attrs ( ) . find_map ( |attr| attr. string_value ( ) )
697720 }
698721
722+ #[ inline]
699723 pub fn string_value_with_span ( self ) -> Option < ( & ' attr Symbol , span:: Span ) > {
700724 self . attrs ( ) . find_map ( |attr| attr. string_value_with_span ( ) )
701725 }
702726
727+ #[ inline]
703728 pub fn string_value_unescape ( self ) -> Option < Cow < ' attr , str > > {
704729 self . attrs ( ) . find_map ( |attr| attr. string_value_unescape ( ) )
705730 }
706731
732+ #[ inline]
707733 pub fn exists ( self ) -> bool {
708734 self . attrs ( ) . next ( ) . is_some ( )
709735 }
710736
737+ #[ inline]
711738 pub fn attrs ( self ) -> impl Iterator < Item = & ' attr Attr > + Clone {
712739 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) )
714741 }
715742
716743 /// Find string value for a specific key inside token tree
@@ -719,10 +746,11 @@ impl<'attr> AttrQuery<'attr> {
719746 /// #[doc(html_root_url = "url")]
720747 /// ^^^^^^^^^^^^^ key
721748 /// ```
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 > {
723751 self . tt_values ( ) . find_map ( |tt| {
724752 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) )
726754 . nth ( 2 ) ;
727755
728756 match name {
0 commit comments