about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorCaleb Zulawski <caleb.zulawski@gmail.com>2022-08-27 13:35:18 +0000
committerCaleb Zulawski <caleb.zulawski@gmail.com>2022-08-27 13:35:18 +0000
commit3f2ce0624dfed866f758521b225e26c00b3250d8 (patch)
treec1bb5f279f97b977cb1a5b78b5dbc82628be84fe /compiler/rustc_codegen_llvm/src
parentd00928aa69512c02490fcb228a70ad5c3f865613 (diff)
downloadrust-3f2ce0624dfed866f758521b225e26c00b3250d8.tar.gz
rust-3f2ce0624dfed866f758521b225e26c00b3250d8.zip
Check pointer metadata rather than pointee size
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
-rw-r--r--compiler/rustc_codegen_llvm/src/intrinsic.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs
index 45463f96b8b..82d34ce9d14 100644
--- a/compiler/rustc_codegen_llvm/src/intrinsic.rs
+++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs
@@ -1718,19 +1718,23 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
         );
 
         match in_elem.kind() {
-            ty::RawPtr(p) => require!(
-                p.ty.is_sized(bx.tcx.at(span), ty::ParamEnv::reveal_all()),
-                "cannot cast pointer to unsized type `{}`",
-                in_elem
-            ),
+            ty::RawPtr(p) => {
+                let (metadata, check_sized) = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
+                    bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
+                });
+                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),
         }
         match out_elem.kind() {
-            ty::RawPtr(p) => require!(
-                p.ty.is_sized(bx.tcx.at(span), ty::ParamEnv::reveal_all()),
-                "cannot cast to pointer to unsized type `{}`",
-                out_elem
-            ),
+            ty::RawPtr(p) => {
+                let (metadata, check_sized) = p.ty.ptr_metadata_ty(bx.tcx, |ty| {
+                    bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
+                });
+                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),
         }