@@ -341,6 +341,8 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
341341 } ;
342342
343343 tcx. hir . krate ( ) . visit_all_item_likes ( & mut visitor) ;
344+
345+ visitor. push_extra_entry_roots ( ) ;
344346 }
345347
346348 // We can only translate items that are instantiable - items all of
@@ -998,8 +1000,6 @@ impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> {
9981000
9991001 let instance = Instance :: mono ( self . tcx , def_id) ;
10001002 self . output . push ( create_fn_mono_item ( instance) ) ;
1001-
1002- self . push_extra_entry_roots ( def_id) ;
10031003 }
10041004 }
10051005
@@ -1008,20 +1008,22 @@ impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> {
10081008 /// monomorphized copy of the start lang item based on
10091009 /// the return type of `main`. This is not needed when
10101010 /// 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 ) {
10161012 if self . tcx . sess . entry_type . get ( ) != Some ( config:: EntryMain ) {
1017- return ;
1013+ return
10181014 }
10191015
1016+ let main_def_id = if let Some ( def_id) = self . entry_fn {
1017+ def_id
1018+ } else {
1019+ return
1020+ } ;
1021+
10201022 let start_def_id = match self . tcx . lang_items ( ) . require ( StartFnLangItem ) {
10211023 Ok ( s) => s,
10221024 Err ( err) => self . tcx . sess . fatal ( & err) ,
10231025 } ;
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 ( ) ;
10251027
10261028 // Given that `main()` has no arguments,
10271029 // then its return type cannot have
@@ -1066,7 +1068,6 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10661068 def_id_to_string( tcx, impl_def_id) ) ;
10671069
10681070 if let Some ( trait_ref) = tcx. impl_trait_ref ( impl_def_id) {
1069- let callee_substs = tcx. erase_regions ( & trait_ref. substs ) ;
10701071 let overridden_methods: FxHashSet < _ > =
10711072 impl_item_refs. iter ( )
10721073 . map ( |iiref| iiref. name )
@@ -1080,10 +1081,15 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10801081 continue ;
10811082 }
10821083
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+
10831089 let instance = ty:: Instance :: resolve ( tcx,
10841090 ty:: ParamEnv :: reveal_all ( ) ,
10851091 method. def_id ,
1086- callee_substs ) . unwrap ( ) ;
1092+ substs ) . unwrap ( ) ;
10871093
10881094 let mono_item = create_fn_mono_item ( instance) ;
10891095 if mono_item. is_instantiable ( tcx)
0 commit comments