Skip to content

Commit 9cd0bf2

Browse files
committed
Only scan each definition once.
1 parent 18eeac0 commit 9cd0bf2

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,
@@ -323,18 +322,8 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
323322

324323
fn mark_live_symbols(&mut self) {
325324
while let Some(work) = self.worklist.pop() {
326-
if !self.scanned.insert(work) {
327-
continue;
328-
}
329-
330325
let (mut id, comes_from_allow_expect) = work;
331326

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

0 commit comments

Comments
 (0)