Skip to content

Commit 9307418

Browse files
authored
Rollup merge of #40696 - cramertj:remove-unused-adt-def-code, r=petrochenkov
Remove unused adt-def insertion by constructor DefIndex It looks to me like ADT definitions weren't being looked up by constructor id, and a test run supports my theory. In any case, I'm not sure it would have worked in its current configuration. If I understand correctly, the `adt_def` map entry from constructor id -> adt def would only be present after a successful call to `queries::adt_def::get` with the proper ADT `DefIndex`. Trying to look up an adt_def by the constructor index prior to a successful lookup by ADT index would fail since `item.kind` would be `EntryKind::Fn` (for the constructor function) and so would trigger the `bug!`. r? @nikomatsakis
2 parents 39e4a27 + 873248d commit 9307418

File tree

2 files changed

+2
-16
lines changed

2 files changed

+2
-16
lines changed

src/librustc_metadata/decoder.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,6 @@ impl<'a, 'tcx> CrateMetadata {
558558
EntryKind::Union(_, _) => ty::AdtKind::Union,
559559
_ => bug!("get_adt_def called on a non-ADT {:?}", did),
560560
};
561-
let mut ctor_index = None;
562561
let variants = if let ty::AdtKind::Enum = kind {
563562
item.children
564563
.decode(self)
@@ -570,8 +569,7 @@ impl<'a, 'tcx> CrateMetadata {
570569
})
571570
.collect()
572571
} else {
573-
let (variant, struct_ctor) = self.get_variant(&item, item_id, tcx);
574-
ctor_index = struct_ctor;
572+
let (variant, _struct_ctor) = self.get_variant(&item, item_id, tcx);
575573
vec![variant]
576574
};
577575
let (kind, repr) = match item.kind {
@@ -581,13 +579,7 @@ impl<'a, 'tcx> CrateMetadata {
581579
_ => bug!("get_adt_def called on a non-ADT {:?}", did),
582580
};
583581

584-
let adt = tcx.alloc_adt_def(did, kind, variants, repr);
585-
if let Some(ctor_index) = ctor_index {
586-
// Make adt definition available through constructor id as well.
587-
tcx.maps.adt_def.borrow_mut().insert(self.local_def_id(ctor_index), adt);
588-
}
589-
590-
adt
582+
tcx.alloc_adt_def(did, kind, variants, repr)
591583
}
592584

593585
pub fn get_predicates(&self,

src/librustc_typeck/collect.rs

-6
Original file line numberDiff line numberDiff line change
@@ -689,12 +689,6 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
689689
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
690690
let item = match tcx.hir.get(node_id) {
691691
NodeItem(item) => item,
692-
693-
// Make adt definition available through constructor id as well.
694-
NodeStructCtor(_) => {
695-
return tcx.lookup_adt_def(tcx.hir.get_parent_did(node_id));
696-
}
697-
698692
_ => bug!()
699693
};
700694

0 commit comments

Comments
 (0)