Skip to content

Commit 3f2ce06

Browse files
committed
Check pointer metadata rather than pointee size
1 parent d00928a commit 3f2ce06

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -1718,19 +1718,23 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
17181718
);
17191719

17201720
match in_elem.kind() {
1721-
ty::RawPtr(p) => require!(
1722-
p.ty.is_sized(bx.tcx.at(span), ty::ParamEnv::reveal_all()),
1723-
"cannot cast pointer to unsized type `{}`",
1724-
in_elem
1725-
),
1721+
ty::RawPtr(p) => {
1722+
let (metadata, check_sized) = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
1723+
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
1724+
});
1725+
assert!(!check_sized); // we are in codegen, so we shouldn't see these types
1726+
require!(metadata.is_unit(), "cannot cast fat pointer `{}`", in_elem)
1727+
}
17261728
_ => return_error!("expected pointer, got `{}`", in_elem),
17271729
}
17281730
match out_elem.kind() {
1729-
ty::RawPtr(p) => require!(
1730-
p.ty.is_sized(bx.tcx.at(span), ty::ParamEnv::reveal_all()),
1731-
"cannot cast to pointer to unsized type `{}`",
1732-
out_elem
1733-
),
1731+
ty::RawPtr(p) => {
1732+
let (metadata, check_sized) = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
1733+
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
1734+
});
1735+
assert!(!check_sized); // we are in codegen, so we shouldn't see these types
1736+
require!(metadata.is_unit(), "cannot cast to fat pointer `{}`", out_elem)
1737+
}
17341738
_ => return_error!("expected pointer, got `{}`", out_elem),
17351739
}
17361740

0 commit comments

Comments
 (0)