Fetch the destructor constness lazily

This commit is contained in:
Oli Scherer 2025-04-01 09:28:46 +00:00
parent ca32447c0c
commit 6697f02761
4 changed files with 6 additions and 8 deletions

View file

@ -236,7 +236,7 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
} }
fn destructor(self, tcx: TyCtxt<'tcx>) -> Option<AdtDestructorKind> { fn destructor(self, tcx: TyCtxt<'tcx>) -> Option<AdtDestructorKind> {
Some(match self.destructor(tcx)?.constness { Some(match tcx.constness(self.destructor(tcx)?.did) {
hir::Constness::Const => AdtDestructorKind::Const, hir::Constness::Const => AdtDestructorKind::Const,
hir::Constness::NotConst => AdtDestructorKind::NotConst, hir::Constness::NotConst => AdtDestructorKind::NotConst,
}) })

View file

@ -1119,8 +1119,6 @@ pub struct PseudoCanonicalInput<'tcx, T> {
pub struct Destructor { pub struct Destructor {
/// The `DefId` of the destructor method /// The `DefId` of the destructor method
pub did: DefId, pub did: DefId,
/// The constness of the destructor method
pub constness: hir::Constness,
} }
// FIXME: consider combining this definition with regular `Destructor` // FIXME: consider combining this definition with regular `Destructor`

View file

@ -414,18 +414,18 @@ impl<'tcx> TyCtxt<'tcx> {
continue; continue;
}; };
if let Some((old_item_id, _)) = dtor_candidate { if let Some(old_item_id) = dtor_candidate {
self.dcx() self.dcx()
.struct_span_err(self.def_span(item_id), "multiple drop impls found") .struct_span_err(self.def_span(item_id), "multiple drop impls found")
.with_span_note(self.def_span(old_item_id), "other impl here") .with_span_note(self.def_span(old_item_id), "other impl here")
.delay_as_bug(); .delay_as_bug();
} }
dtor_candidate = Some((*item_id, self.impl_trait_header(impl_did).unwrap().constness)); dtor_candidate = Some(*item_id);
} }
let (did, constness) = dtor_candidate?; let did = dtor_candidate?;
Some(ty::Destructor { did, constness }) Some(ty::Destructor { did })
} }
/// Calculate the async destructor of a given type. /// Calculate the async destructor of a given type.

View file

@ -263,7 +263,7 @@ fn evaluate_host_effect_for_destruct_goal<'tcx>(
.all_fields() .all_fields()
.map(|field| ty::TraitRef::new(tcx, destruct_def_id, [field.ty(tcx, args)])) .map(|field| ty::TraitRef::new(tcx, destruct_def_id, [field.ty(tcx, args)]))
.collect(); .collect();
match adt_def.destructor(tcx).map(|dtor| dtor.constness) { match adt_def.destructor(tcx).map(|dtor| tcx.constness(dtor.did)) {
// `Drop` impl exists, but it's not const. Type cannot be `~const Destruct`. // `Drop` impl exists, but it's not const. Type cannot be `~const Destruct`.
Some(hir::Constness::NotConst) => return Err(EvaluationFailure::NoSolution), Some(hir::Constness::NotConst) => return Err(EvaluationFailure::NoSolution),
// `Drop` impl exists, and it's const. Require `Ty: ~const Drop` to hold. // `Drop` impl exists, and it's const. Require `Ty: ~const Drop` to hold.