@@ -74,11 +74,10 @@ use rustc_hir::def::{DefKind, Res};
7474use rustc_hir:: def_id:: { CrateNum , DefId , LocalDefId , CRATE_DEF_ID } ;
7575use rustc_hir:: hir_id:: { HirIdMap , HirIdSet } ;
7676use rustc_hir:: intravisit:: { walk_expr, FnKind , Visitor } ;
77- use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
7877use rustc_hir:: LangItem :: { OptionNone , ResultErr , ResultOk } ;
7978use rustc_hir:: {
8079 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 ,
8281 Mutability , Node , Param , Pat , PatKind , Path , PathSegment , PrimTy , QPath , Stmt , StmtKind , TraitItem , TraitItemKind ,
8382 TraitRef , TyKind , UnOp ,
8483} ;
@@ -2068,35 +2067,6 @@ pub fn is_hir_ty_cfg_dependant(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
20682067 false
20692068}
20702069
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-
21002070static TEST_ITEM_NAMES_CACHE : SyncOnceCell < Mutex < FxHashMap < LocalDefId , Vec < Symbol > > > > = SyncOnceCell :: new ( ) ;
21012071
21022072fn 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(
21052075 match map. entry ( module) {
21062076 Entry :: Occupied ( entry) => f ( entry. get ( ) ) ,
21072077 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) )
21122100 } ,
21132101 }
21142102}
0 commit comments