Skip to content

Commit 6697f02

Browse files
committed
Fetch the destructor constness lazily
1 parent ca32447 commit 6697f02

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

compiler/rustc_middle/src/ty/adt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
236236
}
237237

238238
fn destructor(self, tcx: TyCtxt<'tcx>) -> Option<AdtDestructorKind> {
239-
Some(match self.destructor(tcx)?.constness {
239+
Some(match tcx.constness(self.destructor(tcx)?.did) {
240240
hir::Constness::Const => AdtDestructorKind::Const,
241241
hir::Constness::NotConst => AdtDestructorKind::NotConst,
242242
})

compiler/rustc_middle/src/ty/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1119,8 +1119,6 @@ pub struct PseudoCanonicalInput<'tcx, T> {
11191119
pub struct Destructor {
11201120
/// The `DefId` of the destructor method
11211121
pub did: DefId,
1122-
/// The constness of the destructor method
1123-
pub constness: hir::Constness,
11241122
}
11251123

11261124
// FIXME: consider combining this definition with regular `Destructor`

compiler/rustc_middle/src/ty/util.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -414,18 +414,18 @@ impl<'tcx> TyCtxt<'tcx> {
414414
continue;
415415
};
416416

417-
if let Some((old_item_id, _)) = dtor_candidate {
417+
if let Some(old_item_id) = dtor_candidate {
418418
self.dcx()
419419
.struct_span_err(self.def_span(item_id), "multiple drop impls found")
420420
.with_span_note(self.def_span(old_item_id), "other impl here")
421421
.delay_as_bug();
422422
}
423423

424-
dtor_candidate = Some((*item_id, self.impl_trait_header(impl_did).unwrap().constness));
424+
dtor_candidate = Some(*item_id);
425425
}
426426

427-
let (did, constness) = dtor_candidate?;
428-
Some(ty::Destructor { did, constness })
427+
let did = dtor_candidate?;
428+
Some(ty::Destructor { did })
429429
}
430430

431431
/// Calculate the async destructor of a given type.

compiler/rustc_trait_selection/src/traits/effects.rs

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

0 commit comments

Comments
 (0)