Skip to content

Commit b41f227

Browse files
MonoItem collector: Cleanup start fn root collection.
1 parent a4af6f0 commit b41f227

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/librustc_mir/monomorphize/collector.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)