@@ -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
@@ -1066,7 +1068,6 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1066
1068
def_id_to_string( tcx, impl_def_id) ) ;
1067
1069
1068
1070
if let Some ( trait_ref) = tcx. impl_trait_ref ( impl_def_id) {
1069
- let callee_substs = tcx. erase_regions ( & trait_ref. substs ) ;
1070
1071
let overridden_methods: FxHashSet < _ > =
1071
1072
impl_item_refs. iter ( )
1072
1073
. map ( |iiref| iiref. name )
@@ -1080,10 +1081,15 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1080
1081
continue ;
1081
1082
}
1082
1083
1084
+ let substs = Substs :: for_item ( tcx,
1085
+ method. def_id ,
1086
+ |_, _| tcx. types . re_erased ,
1087
+ |def, _| trait_ref. substs . type_for_def ( def) ) ;
1088
+
1083
1089
let instance = ty:: Instance :: resolve ( tcx,
1084
1090
ty:: ParamEnv :: reveal_all ( ) ,
1085
1091
method. def_id ,
1086
- callee_substs ) . unwrap ( ) ;
1092
+ substs ) . unwrap ( ) ;
1087
1093
1088
1094
let mono_item = create_fn_mono_item ( instance) ;
1089
1095
if mono_item. is_instantiable ( tcx)
0 commit comments