Skip to content

Commit d95a610

Browse files
committed
Don't fail validation for pointers to param T.
1 parent 27a9371 commit d95a610

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/librustc_mir/interpret/validity.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -475,15 +475,25 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M
475475
Ok(true)
476476
}
477477
ty::RawPtr(..) => {
478-
// We are conservative with undef for integers, but try to
479-
// actually enforce our current rules for raw pointers.
480-
let place = try_validation!(
481-
self.ecx.ref_to_mplace(self.ecx.read_immediate(value)?),
482-
"undefined pointer",
483-
self.path
484-
);
485-
if place.layout.is_unsized() {
486-
self.check_wide_ptr_meta(place.meta, place.layout)?;
478+
let imm = self.ecx.read_immediate(value)?;
479+
let pointee_kind = &imm.layout.ty.builtin_deref(true).unwrap().ty.kind;
480+
match pointee_kind {
481+
ty::Param(_) => {
482+
// Creating pointers to T is valid. We only reach this case for unused
483+
// associated consts.
484+
}
485+
_ => {
486+
// We are conservative with undef for integers, but try to
487+
// actually enforce our current rules for raw pointers.
488+
let place = try_validation!(
489+
self.ecx.ref_to_mplace(imm),
490+
"undefined pointer",
491+
self.path
492+
);
493+
if place.layout.is_unsized() {
494+
self.check_wide_ptr_meta(place.meta, place.layout)?;
495+
}
496+
}
487497
}
488498
Ok(true)
489499
}

0 commit comments

Comments
 (0)