Skip to content

Commit a575fe1

Browse files
committed
Erase type lifetime before writing type ID
1 parent b410cb0 commit a575fe1

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

compiler/rustc_const_eval/src/const_eval/type_info.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,10 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
273273
let ptr = self.mplace_to_ref(&name_place)?;
274274
self.write_immediate(*ptr, &field_place)?
275275
}
276-
sym::ty => self.write_type_id(field_ty, &field_place)?,
276+
sym::ty => {
277+
let field_ty = self.tcx.erase_and_anonymize_regions(field_ty);
278+
self.write_type_id(field_ty, &field_place)?
279+
}
277280
sym::offset => {
278281
let offset = layout.fields.offset(idx as usize);
279282
self.write_scalar(

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_infer::infer::TyCtxtInferExt;
1313
use rustc_middle::mir::interpret::{CTFE_ALLOC_SALT, read_target_uint, write_target_uint};
1414
use rustc_middle::mir::{self, BinOp, ConstValue, NonDivergingIntrinsic};
1515
use rustc_middle::ty::layout::TyAndLayout;
16-
use rustc_middle::ty::{FloatTy, PolyExistentialPredicate, Ty, TyCtxt};
16+
use rustc_middle::ty::{FloatTy, PolyExistentialPredicate, Ty, TyCtxt, TypeVisitableExt};
1717
use rustc_middle::{bug, span_bug, ty};
1818
use rustc_span::{Symbol, sym};
1919
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
@@ -73,6 +73,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
7373
ty: Ty<'tcx>,
7474
dest: &impl Writeable<'tcx, M::Provenance>,
7575
) -> InterpResult<'tcx, ()> {
76+
debug_assert!(
77+
!ty.has_erasable_regions(),
78+
"type {ty:?} has regions that need erasing before writing a TypeId",
79+
);
80+
7681
let tcx = self.tcx;
7782
let type_id_hash = tcx.type_id_hash(ty).as_u128();
7883
let op = self.const_val_to_op(

library/coretests/tests/mem/type_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn test_structs() {
9191
assert!(ty.fields[1].ty == TypeId::of::<u16>());
9292
assert!(ty.fields[1].offset == offset_of!(TestStruct, second));
9393
assert!(ty.fields[2].name == "reference");
94-
assert!(ty.fields[2].ty != TypeId::of::<&'static u16>()); // FIXME(type_info): should be ==
94+
assert!(ty.fields[2].ty == TypeId::of::<&'static u16>());
9595
assert!(ty.fields[2].offset == offset_of!(TestStruct, reference));
9696
}
9797

0 commit comments

Comments
 (0)