Skip to content

Commit 5b6ceb5

Browse files
committed
Auto merge of #145506 - cjgillot:live-or-dead-onescan, r=fee1-dead
Only scan each definition once for dead-code. r? `@ghost`
2 parents 8df154b + 9cd0bf2 commit 5b6ceb5

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

compiler/rustc_passes/src/dead.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::mem;
88
use hir::def_id::{LocalDefIdMap, LocalDefIdSet};
99
use rustc_abi::FieldIdx;
1010
use rustc_data_structures::fx::FxIndexSet;
11-
use rustc_data_structures::unord::UnordSet;
1211
use rustc_errors::MultiSpan;
1312
use rustc_hir::def::{CtorOf, DefKind, Res};
1413
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
@@ -79,7 +78,7 @@ struct MarkSymbolVisitor<'tcx> {
7978
worklist: Vec<(LocalDefId, ComesFromAllowExpect)>,
8079
tcx: TyCtxt<'tcx>,
8180
maybe_typeck_results: Option<&'tcx ty::TypeckResults<'tcx>>,
82-
scanned: UnordSet<(LocalDefId, ComesFromAllowExpect)>,
81+
scanned: LocalDefIdSet,
8382
live_symbols: LocalDefIdSet,
8483
repr_unconditionally_treats_fields_as_live: bool,
8584
repr_has_repr_simd: bool,
@@ -321,18 +320,8 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
321320

322321
fn mark_live_symbols(&mut self) {
323322
while let Some(work) = self.worklist.pop() {
324-
if !self.scanned.insert(work) {
325-
continue;
326-
}
327-
328323
let (mut id, comes_from_allow_expect) = work;
329324

330-
// Avoid accessing the HIR for the synthesized associated type generated for RPITITs.
331-
if self.tcx.is_impl_trait_in_trait(id.to_def_id()) {
332-
self.live_symbols.insert(id);
333-
continue;
334-
}
335-
336325
// in the case of tuple struct constructors we want to check the item,
337326
// not the generated tuple struct constructor function
338327
if let DefKind::Ctor(..) = self.tcx.def_kind(id) {
@@ -360,9 +349,23 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
360349
// this "duplication" is essential as otherwise a function with `#[expect]`
361350
// called from a `pub fn` may be falsely reported as not live, falsely
362351
// triggering the `unfulfilled_lint_expectations` lint.
363-
if comes_from_allow_expect != ComesFromAllowExpect::Yes {
352+
match comes_from_allow_expect {
353+
ComesFromAllowExpect::Yes => {}
354+
ComesFromAllowExpect::No => {
355+
self.live_symbols.insert(id);
356+
}
357+
}
358+
359+
if !self.scanned.insert(id) {
360+
continue;
361+
}
362+
363+
// Avoid accessing the HIR for the synthesized associated type generated for RPITITs.
364+
if self.tcx.is_impl_trait_in_trait(id.to_def_id()) {
364365
self.live_symbols.insert(id);
366+
continue;
365367
}
368+
366369
self.visit_node(self.tcx.hir_node_by_def_id(id));
367370
}
368371
}

0 commit comments

Comments
 (0)