diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 7fd2ea265de80..d43da5392ab8e 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -341,6 +341,8 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }; tcx.hir.krate().visit_all_item_likes(&mut visitor); + + visitor.push_extra_entry_roots(); } // We can only translate items that are instantiable - items all of @@ -998,8 +1000,6 @@ impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> { let instance = Instance::mono(self.tcx, def_id); self.output.push(create_fn_mono_item(instance)); - - self.push_extra_entry_roots(def_id); } } @@ -1008,20 +1008,22 @@ impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> { /// monomorphized copy of the start lang item based on /// the return type of `main`. This is not needed when /// the user writes their own `start` manually. - fn push_extra_entry_roots(&mut self, def_id: DefId) { - if self.entry_fn != Some(def_id) { - return; - } - + fn push_extra_entry_roots(&mut self) { if self.tcx.sess.entry_type.get() != Some(config::EntryMain) { - return; + return } + let main_def_id = if let Some(def_id) = self.entry_fn { + def_id + } else { + return + }; + let start_def_id = match self.tcx.lang_items().require(StartFnLangItem) { Ok(s) => s, Err(err) => self.tcx.sess.fatal(&err), }; - let main_ret_ty = self.tcx.fn_sig(def_id).output(); + let main_ret_ty = self.tcx.fn_sig(main_def_id).output(); // Given that `main()` has no arguments, // then its return type cannot have