@@ -74,11 +74,10 @@ use rustc_hir::def::{DefKind, Res};
74
74
use rustc_hir:: def_id:: { CrateNum , DefId , LocalDefId , CRATE_DEF_ID } ;
75
75
use rustc_hir:: hir_id:: { HirIdMap , HirIdSet } ;
76
76
use rustc_hir:: intravisit:: { walk_expr, FnKind , Visitor } ;
77
- use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
78
77
use rustc_hir:: LangItem :: { OptionNone , ResultErr , ResultOk } ;
79
78
use rustc_hir:: {
80
79
def, Arm , ArrayLen , BindingAnnotation , Block , BlockCheckMode , Body , Constness , Destination , Expr , ExprKind , FnDecl ,
81
- ForeignItem , HirId , Impl , ImplItem , ImplItemKind , IsAsync , Item , ItemKind , LangItem , Local , MatchSource ,
80
+ HirId , Impl , ImplItem , ImplItemKind , IsAsync , Item , ItemKind , LangItem , Local , MatchSource ,
82
81
Mutability , Node , Param , Pat , PatKind , Path , PathSegment , PrimTy , QPath , Stmt , StmtKind , TraitItem , TraitItemKind ,
83
82
TraitRef , TyKind , UnOp ,
84
83
} ;
@@ -2068,35 +2067,6 @@ pub fn is_hir_ty_cfg_dependant(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
2068
2067
false
2069
2068
}
2070
2069
2071
- struct TestItemNamesVisitor < ' tcx > {
2072
- tcx : TyCtxt < ' tcx > ,
2073
- names : Vec < Symbol > ,
2074
- }
2075
-
2076
- impl < ' hir > ItemLikeVisitor < ' hir > for TestItemNamesVisitor < ' hir > {
2077
- fn visit_item ( & mut self , item : & Item < ' _ > ) {
2078
- if let ItemKind :: Const ( ty, _body) = item. kind {
2079
- if let TyKind :: Path ( QPath :: Resolved ( _, path) ) = ty. kind {
2080
- // We could also check for the type name `test::TestDescAndFn`
2081
- if let Res :: Def ( DefKind :: Struct , _) = path. res {
2082
- let has_test_marker = self
2083
- . tcx
2084
- . hir ( )
2085
- . attrs ( item. hir_id ( ) )
2086
- . iter ( )
2087
- . any ( |a| a. has_name ( sym:: rustc_test_marker) ) ;
2088
- if has_test_marker {
2089
- self . names . push ( item. ident . name ) ;
2090
- }
2091
- }
2092
- }
2093
- }
2094
- }
2095
- fn visit_trait_item ( & mut self , _: & TraitItem < ' _ > ) { }
2096
- fn visit_impl_item ( & mut self , _: & ImplItem < ' _ > ) { }
2097
- fn visit_foreign_item ( & mut self , _: & ForeignItem < ' _ > ) { }
2098
- }
2099
-
2100
2070
static TEST_ITEM_NAMES_CACHE : SyncOnceCell < Mutex < FxHashMap < LocalDefId , Vec < Symbol > > > > = SyncOnceCell :: new ( ) ;
2101
2071
2102
2072
fn with_test_item_names < ' tcx > ( tcx : TyCtxt < ' tcx > , module : LocalDefId , f : impl Fn ( & [ Symbol ] ) -> bool ) -> bool {
@@ -2105,10 +2075,28 @@ fn with_test_item_names<'tcx>(tcx: TyCtxt<'tcx>, module: LocalDefId, f: impl Fn(
2105
2075
match map. entry ( module) {
2106
2076
Entry :: Occupied ( entry) => f ( entry. get ( ) ) ,
2107
2077
Entry :: Vacant ( entry) => {
2108
- let mut visitor = TestItemNamesVisitor { tcx, names : Vec :: new ( ) } ;
2109
- tcx. hir ( ) . visit_item_likes_in_module ( module, & mut visitor) ;
2110
- visitor. names . sort_unstable ( ) ;
2111
- f ( & * entry. insert ( visitor. names ) )
2078
+ let mut names = Vec :: new ( ) ;
2079
+ for id in tcx. hir ( ) . module_items ( module) {
2080
+ if matches ! ( tcx. def_kind( id. def_id) , DefKind :: Const )
2081
+ && let item = tcx. hir ( ) . item ( id)
2082
+ && let ItemKind :: Const ( ty, _body) = item. kind {
2083
+ if let TyKind :: Path ( QPath :: Resolved ( _, path) ) = ty. kind {
2084
+ // We could also check for the type name `test::TestDescAndFn`
2085
+ if let Res :: Def ( DefKind :: Struct , _) = path. res {
2086
+ let has_test_marker = tcx
2087
+ . hir ( )
2088
+ . attrs ( item. hir_id ( ) )
2089
+ . iter ( )
2090
+ . any ( |a| a. has_name ( sym:: rustc_test_marker) ) ;
2091
+ if has_test_marker {
2092
+ names. push ( item. ident . name ) ;
2093
+ }
2094
+ }
2095
+ }
2096
+ }
2097
+ }
2098
+ names. sort_unstable ( ) ;
2099
+ f ( & * entry. insert ( names) )
2112
2100
} ,
2113
2101
}
2114
2102
}
0 commit comments