Fix transmute_undefined_repr when converting between a fat pointer and a type containing a fat pointer
This commit is contained in:
@@ -19,8 +19,16 @@ pub(super) fn check<'tcx>(
|
|||||||
|
|
||||||
while from_ty != to_ty {
|
while from_ty != to_ty {
|
||||||
match reduce_refs(cx, e.span, 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::IntArray | ReducedTy::TypeErasure => break,
|
||||||
|
ReducedTy::Ref(to_sub_ty) => {
|
||||||
|
from_ty = unsized_ty;
|
||||||
|
to_ty = to_sub_ty;
|
||||||
|
continue;
|
||||||
|
},
|
||||||
_ => {
|
_ => {
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
@@ -36,8 +44,16 @@ pub(super) fn check<'tcx>(
|
|||||||
return true;
|
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::IntArray | ReducedTy::TypeErasure => break,
|
||||||
|
ReducedTy::Ref(from_sub_ty) => {
|
||||||
|
from_ty = from_sub_ty;
|
||||||
|
to_ty = unsized_ty;
|
||||||
|
continue;
|
||||||
|
},
|
||||||
_ => {
|
_ => {
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
|
|||||||
@@ -84,5 +84,8 @@ fn main() {
|
|||||||
|
|
||||||
let _: [usize; 2] = transmute(value::<&[u8]>()); // Ok, transmute to int array
|
let _: [usize; 2] = transmute(value::<&[u8]>()); // Ok, transmute to int array
|
||||||
let _: &[u8] = transmute(value::<[usize; 2]>()); // Ok, transmute from 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user