Check pointer metadata rather than pointee size
This commit is contained in:
parent
d00928aa69
commit
3f2ce0624d
1 changed files with 14 additions and 10 deletions
|
@ -1718,19 +1718,23 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
|
||||||
);
|
);
|
||||||
|
|
||||||
match in_elem.kind() {
|
match in_elem.kind() {
|
||||||
ty::RawPtr(p) => require!(
|
ty::RawPtr(p) => {
|
||||||
p.ty.is_sized(bx.tcx.at(span), ty::ParamEnv::reveal_all()),
|
let (metadata, check_sized) = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
|
||||||
"cannot cast pointer to unsized type `{}`",
|
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
|
||||||
in_elem
|
});
|
||||||
),
|
assert!(!check_sized); // we are in codegen, so we shouldn't see these types
|
||||||
|
require!(metadata.is_unit(), "cannot cast fat pointer `{}`", in_elem)
|
||||||
|
}
|
||||||
_ => return_error!("expected pointer, got `{}`", in_elem),
|
_ => return_error!("expected pointer, got `{}`", in_elem),
|
||||||
}
|
}
|
||||||
match out_elem.kind() {
|
match out_elem.kind() {
|
||||||
ty::RawPtr(p) => require!(
|
ty::RawPtr(p) => {
|
||||||
p.ty.is_sized(bx.tcx.at(span), ty::ParamEnv::reveal_all()),
|
let (metadata, check_sized) = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
|
||||||
"cannot cast to pointer to unsized type `{}`",
|
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
|
||||||
out_elem
|
});
|
||||||
),
|
assert!(!check_sized); // we are in codegen, so we shouldn't see these types
|
||||||
|
require!(metadata.is_unit(), "cannot cast to fat pointer `{}`", out_elem)
|
||||||
|
}
|
||||||
_ => return_error!("expected pointer, got `{}`", out_elem),
|
_ => return_error!("expected pointer, got `{}`", out_elem),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue