Skip to content

Commit d28d19d

Browse files
committed
Fix transmute_undefined_repr when converting between a fat pointer and a type containing a fat pointer
1 parent 7c07022 commit d28d19d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

clippy_lints/src/transmute/transmute_undefined_repr.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,16 @@ pub(super) fn check<'tcx>(
1919

2020
while from_ty != to_ty {
2121
match reduce_refs(cx, e.span, from_ty, to_ty) {
22-
ReducedTys::FromFatPtr { unsized_ty, to_ty } => match reduce_ty(cx, to_ty) {
22+
ReducedTys::FromFatPtr {
23+
unsized_ty,
24+
to_ty: to_sub_ty,
25+
} => match reduce_ty(cx, to_sub_ty) {
2326
ReducedTy::IntArray | ReducedTy::TypeErasure => break,
27+
ReducedTy::Ref(to_sub_ty) => {
28+
from_ty = unsized_ty;
29+
to_ty = to_sub_ty;
30+
continue;
31+
},
2432
_ => {
2533
span_lint_and_then(
2634
cx,
@@ -36,8 +44,16 @@ pub(super) fn check<'tcx>(
3644
return true;
3745
},
3846
},
39-
ReducedTys::ToFatPtr { unsized_ty, from_ty } => match reduce_ty(cx, from_ty) {
47+
ReducedTys::ToFatPtr {
48+
unsized_ty,
49+
from_ty: from_sub_ty,
50+
} => match reduce_ty(cx, from_sub_ty) {
4051
ReducedTy::IntArray | ReducedTy::TypeErasure => break,
52+
ReducedTy::Ref(from_sub_ty) => {
53+
from_ty = from_sub_ty;
54+
to_ty = unsized_ty;
55+
continue;
56+
},
4157
_ => {
4258
span_lint_and_then(
4359
cx,

tests/ui/transmute_undefined_repr.rs

+3
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,8 @@ fn main() {
8484

8585
let _: [usize; 2] = transmute(value::<&[u8]>()); // Ok, transmute to int array
8686
let _: &[u8] = transmute(value::<[usize; 2]>()); // Ok, transmute from int array
87+
88+
let _: *const [u8] = transmute(value::<Box<[u8]>>()); // Ok
89+
let _: Box<[u8]> = transmute(value::<*mut [u8]>()); // Ok
8790
}
8891
}

0 commit comments

Comments
 (0)