Fix transmute_undefined_repr when converting between a fat pointer and a type containing a fat pointer

This commit is contained in:
Jason Newcomb 2022-02-16 14:59:04 -05:00
parent 7c07022c98
commit d28d19d74c
2 changed files with 21 additions and 2 deletions

View file

@ -19,8 +19,16 @@ pub(super) fn check<'tcx>(
while from_ty != to_ty {
match reduce_refs(cx, e.span, from_ty, to_ty) {
ReducedTys::FromFatPtr { unsized_ty, to_ty } => match reduce_ty(cx, to_ty) {
ReducedTys::FromFatPtr {
unsized_ty,
to_ty: to_sub_ty,
} => match reduce_ty(cx, to_sub_ty) {
ReducedTy::IntArray | ReducedTy::TypeErasure => break,
ReducedTy::Ref(to_sub_ty) => {
from_ty = unsized_ty;
to_ty = to_sub_ty;
continue;
},
_ => {
span_lint_and_then(
cx,
@ -36,8 +44,16 @@ pub(super) fn check<'tcx>(
return true;
},
},
ReducedTys::ToFatPtr { unsized_ty, from_ty } => match reduce_ty(cx, from_ty) {
ReducedTys::ToFatPtr {
unsized_ty,
from_ty: from_sub_ty,
} => match reduce_ty(cx, from_sub_ty) {
ReducedTy::IntArray | ReducedTy::TypeErasure => break,
ReducedTy::Ref(from_sub_ty) => {
from_ty = from_sub_ty;
to_ty = unsized_ty;
continue;
},
_ => {
span_lint_and_then(
cx,

View file

@ -84,5 +84,8 @@ fn main() {
let _: [usize; 2] = transmute(value::<&[u8]>()); // Ok, transmute to int array
let _: &[u8] = transmute(value::<[usize; 2]>()); // Ok, transmute from int array
let _: *const [u8] = transmute(value::<Box<[u8]>>()); // Ok
let _: Box<[u8]> = transmute(value::<*mut [u8]>()); // Ok
}
}