Skip to content

Commit d64517d

Browse files
committed
Don't codegen dead code
This is the internal-facing portion of #103356; it should not be user-visible in any way.
1 parent 65a6e22 commit d64517d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

compiler/rustc_monomorphize/src/collector.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,13 @@ struct RootCollector<'a, 'tcx> {
11861186

11871187
impl<'v> RootCollector<'_, 'v> {
11881188
fn process_item(&mut self, id: hir::ItemId) {
1189+
let def_id = id.owner_id.def_id;
1190+
let (live_symbols, _) = self.tcx.live_symbols_and_ignored_derived_traits(());
1191+
if !live_symbols.contains(&def_id) && !self.tcx.sess.link_dead_code() {
1192+
// This is dead code; ignore it.
1193+
return;
1194+
}
1195+
11891196
match self.tcx.def_kind(id.owner_id) {
11901197
DefKind::Enum | DefKind::Struct | DefKind::Union => {
11911198
let item = self.tcx.hir().item(id);

compiler/rustc_passes/src/dead.rs

+5
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,11 @@ fn create_and_seed_worklist<'tcx>(
623623
check_foreign_item(tcx, &mut worklist, id);
624624
}
625625

626+
if let Some(static_) = tcx.proc_macro_decls_static(()) {
627+
// We assume this is always used if present.
628+
worklist.push(static_);
629+
}
630+
626631
(worklist, struct_constructors)
627632
}
628633

0 commit comments

Comments
 (0)