1
1
use rustc_ast:: entry:: EntryPointType ;
2
2
use rustc_errors:: struct_span_err;
3
3
use rustc_hir:: def_id:: { DefId , LocalDefId , CRATE_DEF_ID , LOCAL_CRATE } ;
4
- use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
5
- use rustc_hir:: { ForeignItem , ImplItem , Item , ItemKind , Node , TraitItem , CRATE_HIR_ID } ;
4
+ use rustc_hir:: { Item , ItemKind , Node , CRATE_HIR_ID } ;
6
5
use rustc_middle:: ty:: query:: Providers ;
7
6
use rustc_middle:: ty:: { DefIdTree , TyCtxt } ;
8
7
use rustc_session:: config:: { CrateType , EntryFnType } ;
@@ -25,25 +24,6 @@ struct EntryContext<'tcx> {
25
24
non_main_fns : Vec < Span > ,
26
25
}
27
26
28
- impl < ' tcx > ItemLikeVisitor < ' tcx > for EntryContext < ' tcx > {
29
- fn visit_item ( & mut self , item : & ' tcx Item < ' tcx > ) {
30
- let at_root = self . tcx . opt_local_parent ( item. def_id ) == Some ( CRATE_DEF_ID ) ;
31
- find_item ( item, self , at_root) ;
32
- }
33
-
34
- fn visit_trait_item ( & mut self , _trait_item : & ' tcx TraitItem < ' tcx > ) {
35
- // Entry fn is never a trait item.
36
- }
37
-
38
- fn visit_impl_item ( & mut self , _impl_item : & ' tcx ImplItem < ' tcx > ) {
39
- // Entry fn is never a trait item.
40
- }
41
-
42
- fn visit_foreign_item ( & mut self , _: & ' tcx ForeignItem < ' tcx > ) {
43
- // Entry fn is never a foreign item.
44
- }
45
- }
46
-
47
27
fn entry_fn ( tcx : TyCtxt < ' _ > , ( ) : ( ) ) -> Option < ( DefId , EntryFnType ) > {
48
28
let any_exe = tcx. sess . crate_types ( ) . iter ( ) . any ( |ty| * ty == CrateType :: Executable ) ;
49
29
if !any_exe {
@@ -59,7 +39,10 @@ fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> {
59
39
let mut ctxt =
60
40
EntryContext { tcx, attr_main_fn : None , start_fn : None , non_main_fns : Vec :: new ( ) } ;
61
41
62
- tcx. hir ( ) . visit_all_item_likes ( & mut ctxt) ;
42
+ for id in tcx. hir ( ) . items ( ) {
43
+ let item = tcx. hir ( ) . item ( id) ;
44
+ find_item ( item, & mut ctxt) ;
45
+ }
63
46
64
47
configure_main ( tcx, & ctxt)
65
48
}
@@ -89,7 +72,9 @@ fn throw_attr_err(sess: &Session, span: Span, attr: &str) {
89
72
. emit ( ) ;
90
73
}
91
74
92
- fn find_item ( item : & Item < ' _ > , ctxt : & mut EntryContext < ' _ > , at_root : bool ) {
75
+ fn find_item ( item : & Item < ' _ > , ctxt : & mut EntryContext < ' _ > ) {
76
+ let at_root = ctxt. tcx . opt_local_parent ( item. def_id ) == Some ( CRATE_DEF_ID ) ;
77
+
93
78
match entry_point_type ( ctxt, item, at_root) {
94
79
EntryPointType :: None => ( ) ,
95
80
_ if !matches ! ( item. kind, ItemKind :: Fn ( ..) ) => {
0 commit comments