about summary refs log tree commit diff
path: root/compiler/rustc_const_eval
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-10-04 16:11:02 +0530
committerGitHub <noreply@github.com>2022-10-04 16:11:02 +0530
commit32dde232d8a67cd305748d951b2112585886e321 (patch)
treef5d079436f5c1177d57296df560a1addbc8c6fcf /compiler/rustc_const_eval
parentd89d21412bcb2f01b83ed8d2fe5199b6bf1011f5 (diff)
parentc7d1ec009c56546268a84525d1cb0797d68997c1 (diff)
downloadrust-32dde232d8a67cd305748d951b2112585886e321.tar.gz
rust-32dde232d8a67cd305748d951b2112585886e321.zip
Rollup merge of #102559 - compiler-errors:issue-102553, r=oli-obk
Don't ICE when trying to copy unsized value in const prop

When we have a trivially false where-clause predicate like `Self: Sized` where `Self = dyn Trait`, we sometimes don't throw an error during typeck for an illegal operation such as copying an unsized type.

This, unfortunately, cannot be made into an error (at least not without some migration -- see #95611 for example), but we should at least not ICE, since this function will never actually be reachable from main, for example.

r? `@RalfJung` since I think you added these assertions? but feel free to reassign.

Fixes #102553
Diffstat (limited to 'compiler/rustc_const_eval')
-rw-r--r--compiler/rustc_const_eval/src/interpret/place.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs
index 7a01b85381a..eeeb7d6d3e5 100644
--- a/compiler/rustc_const_eval/src/interpret/place.rs
+++ b/compiler/rustc_const_eval/src/interpret/place.rs
@@ -640,11 +640,17 @@ where
         // avoid force_allocation.
         let src = match self.read_immediate_raw(src)? {
             Ok(src_val) => {
-                assert!(!src.layout.is_unsized(), "cannot copy unsized immediates");
-                assert!(
-                    !dest.layout.is_unsized(),
-                    "the src is sized, so the dest must also be sized"
-                );
+                // FIXME(const_prop): Const-prop can possibly evaluate an
+                // unsized copy operation when it thinks that the type is
+                // actually sized, due to a trivially false where-clause
+                // predicate like `where Self: Sized` with `Self = dyn Trait`.
+                // See #102553 for an example of such a predicate.
+                if src.layout.is_unsized() {
+                    throw_inval!(SizeOfUnsizedType(src.layout.ty));
+                }
+                if dest.layout.is_unsized() {
+                    throw_inval!(SizeOfUnsizedType(dest.layout.ty));
+                }
                 assert_eq!(src.layout.size, dest.layout.size);
                 // Yay, we got a value that we can write directly.
                 return if layout_compat {