@@ -121,6 +121,7 @@ use rustc_middle::ty::{
121121 self as rustc_ty, Binder , BorrowKind , ClosureKind , EarlyBinder , GenericArgKind , GenericArgsRef , IntTy , Ty , TyCtxt ,
122122 TypeFlags , TypeVisitableExt , UintTy , UpvarCapture ,
123123} ;
124+ use rustc_hir:: attrs:: CfgEntry ;
124125use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
125126use rustc_span:: source_map:: SourceMap ;
126127use rustc_span:: symbol:: { Ident , Symbol , kw} ;
@@ -2401,17 +2402,12 @@ pub fn is_test_function(tcx: TyCtxt<'_>, fn_def_id: LocalDefId) -> bool {
24012402/// This only checks directly applied attributes, to see if a node is inside a `#[cfg(test)]` parent
24022403/// use [`is_in_cfg_test`]
24032404pub fn is_cfg_test ( tcx : TyCtxt < ' _ > , id : HirId ) -> bool {
2404- tcx. hir_attrs ( id) . iter ( ) . any ( |attr| {
2405- if attr. has_name ( sym:: cfg_trace)
2406- && let Some ( items) = attr. meta_item_list ( )
2407- && let [ item] = & * items
2408- && item. has_name ( sym:: test)
2409- {
2410- true
2411- } else {
2412- false
2413- }
2414- } )
2405+ if let Some ( cfgs) = find_attr ! ( tcx. hir_attrs( id) , AttributeKind :: CfgTrace ( cfgs) => cfgs)
2406+ && cfgs. iter ( ) . any ( |( cfg, _) | { matches ! ( cfg, CfgEntry :: NameValue { name: sym:: test, ..} ) } ) {
2407+ true
2408+ } else {
2409+ false
2410+ }
24152411}
24162412
24172413/// Checks if any parent node of `HirId` has `#[cfg(test)]` attribute applied
@@ -2426,11 +2422,10 @@ pub fn is_in_test(tcx: TyCtxt<'_>, hir_id: HirId) -> bool {
24262422
24272423/// Checks if the item of any of its parents has `#[cfg(...)]` attribute applied.
24282424pub fn inherits_cfg ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> bool {
2429- tcx. has_attr ( def_id, sym :: cfg_trace )
2430- || tcx
2425+ find_attr ! ( tcx. get_all_attrs ( def_id) , AttributeKind :: CfgTrace ( .. ) )
2426+ || find_attr ! ( tcx
24312427 . hir_parent_iter( tcx. local_def_id_to_hir_id( def_id) )
2432- . flat_map ( |( parent_id, _) | tcx. hir_attrs ( parent_id) )
2433- . any ( |attr| attr. has_name ( sym:: cfg_trace) )
2428+ . flat_map( |( parent_id, _) | tcx. hir_attrs( parent_id) ) , AttributeKind :: CfgTrace ( ..) )
24342429}
24352430
24362431/// Walks up the HIR tree from the given expression in an attempt to find where the value is
0 commit comments