Erase type lifetime before writing type ID
This commit is contained in:
parent
b410cb01fe
commit
a575fe168f
3 changed files with 11 additions and 3 deletions
|
|
@ -273,7 +273,10 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
|
|||
let ptr = self.mplace_to_ref(&name_place)?;
|
||||
self.write_immediate(*ptr, &field_place)?
|
||||
}
|
||||
sym::ty => self.write_type_id(field_ty, &field_place)?,
|
||||
sym::ty => {
|
||||
let field_ty = self.tcx.erase_and_anonymize_regions(field_ty);
|
||||
self.write_type_id(field_ty, &field_place)?
|
||||
}
|
||||
sym::offset => {
|
||||
let offset = layout.fields.offset(idx as usize);
|
||||
self.write_scalar(
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use rustc_infer::infer::TyCtxtInferExt;
|
|||
use rustc_middle::mir::interpret::{CTFE_ALLOC_SALT, read_target_uint, write_target_uint};
|
||||
use rustc_middle::mir::{self, BinOp, ConstValue, NonDivergingIntrinsic};
|
||||
use rustc_middle::ty::layout::TyAndLayout;
|
||||
use rustc_middle::ty::{FloatTy, PolyExistentialPredicate, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{FloatTy, PolyExistentialPredicate, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_middle::{bug, span_bug, ty};
|
||||
use rustc_span::{Symbol, sym};
|
||||
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
|
||||
|
|
@ -73,6 +73,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
ty: Ty<'tcx>,
|
||||
dest: &impl Writeable<'tcx, M::Provenance>,
|
||||
) -> InterpResult<'tcx, ()> {
|
||||
debug_assert!(
|
||||
!ty.has_erasable_regions(),
|
||||
"type {ty:?} has regions that need erasing before writing a TypeId",
|
||||
);
|
||||
|
||||
let tcx = self.tcx;
|
||||
let type_id_hash = tcx.type_id_hash(ty).as_u128();
|
||||
let op = self.const_val_to_op(
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ fn test_structs() {
|
|||
assert!(ty.fields[1].ty == TypeId::of::<u16>());
|
||||
assert!(ty.fields[1].offset == offset_of!(TestStruct, second));
|
||||
assert!(ty.fields[2].name == "reference");
|
||||
assert!(ty.fields[2].ty != TypeId::of::<&'static u16>()); // FIXME(type_info): should be ==
|
||||
assert!(ty.fields[2].ty == TypeId::of::<&'static u16>());
|
||||
assert!(ty.fields[2].offset == offset_of!(TestStruct, reference));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue