@@ -341,6 +341,8 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
341
341
} ;
342
342
343
343
tcx. hir . krate ( ) . visit_all_item_likes ( & mut visitor) ;
344
+
345
+ visitor. push_extra_entry_roots ( ) ;
344
346
}
345
347
346
348
// We can only translate items that are instantiable - items all of
@@ -998,8 +1000,6 @@ impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> {
998
1000
999
1001
let instance = Instance :: mono ( self . tcx , def_id) ;
1000
1002
self . output . push ( create_fn_mono_item ( instance) ) ;
1001
-
1002
- self . push_extra_entry_roots ( def_id) ;
1003
1003
}
1004
1004
}
1005
1005
@@ -1008,20 +1008,22 @@ impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> {
1008
1008
/// monomorphized copy of the start lang item based on
1009
1009
/// the return type of `main`. This is not needed when
1010
1010
/// the user writes their own `start` manually.
1011
- fn push_extra_entry_roots ( & mut self , def_id : DefId ) {
1012
- if self . entry_fn != Some ( def_id) {
1013
- return ;
1014
- }
1015
-
1011
+ fn push_extra_entry_roots ( & mut self ) {
1016
1012
if self . tcx . sess . entry_type . get ( ) != Some ( config:: EntryMain ) {
1017
- return ;
1013
+ return
1018
1014
}
1019
1015
1016
+ let main_def_id = if let Some ( def_id) = self . entry_fn {
1017
+ def_id
1018
+ } else {
1019
+ return
1020
+ } ;
1021
+
1020
1022
let start_def_id = match self . tcx . lang_items ( ) . require ( StartFnLangItem ) {
1021
1023
Ok ( s) => s,
1022
1024
Err ( err) => self . tcx . sess . fatal ( & err) ,
1023
1025
} ;
1024
- let main_ret_ty = self . tcx . fn_sig ( def_id ) . output ( ) ;
1026
+ let main_ret_ty = self . tcx . fn_sig ( main_def_id ) . output ( ) ;
1025
1027
1026
1028
// Given that `main()` has no arguments,
1027
1029
// then its return type cannot have
0 commit comments