about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev+love@gmail.com>2022-11-01 12:03:42 +0900
committerGitHub <noreply@github.com>2022-11-01 12:03:42 +0900
commitff89ceca1f6abee64f80c265eabe5ce1df6d3628 (patch)
tree0cb4ec2e614634c98f7c66b5effbe781ef5f1cee
parent5bf9d617cb28ac857b9495fdc0df7031ad906eaf (diff)
parent55568419acfc312ac0d4200ed3334040f2034c4b (diff)
downloadrust-ff89ceca1f6abee64f80c265eabe5ce1df6d3628.tar.gz
rust-ff89ceca1f6abee64f80c265eabe5ce1df6d3628.zip
Rollup merge of #103788 - chenyukang:yukang/fix-ice-103783, r=compiler-errors
Fix ICE in checking transmutability of NaughtyLenArray

Fixes #103783
-rw-r--r--compiler/rustc_transmute/src/layout/tree.rs3
-rw-r--r--src/test/ui/transmutability/arrays/issue-103783-array-length.rs24
-rw-r--r--src/test/ui/transmutability/arrays/issue-103783-array-length.stderr9
3 files changed, 35 insertions, 1 deletions
diff --git a/compiler/rustc_transmute/src/layout/tree.rs b/compiler/rustc_transmute/src/layout/tree.rs
index acd4fa63d78..2bc6bc1fc23 100644
--- a/compiler/rustc_transmute/src/layout/tree.rs
+++ b/compiler/rustc_transmute/src/layout/tree.rs
@@ -284,7 +284,8 @@ pub(crate) mod rustc {
                 }
 
                 ty::Array(ty, len) => {
-                    let len = len.try_eval_usize(tcx, ParamEnv::reveal_all()).unwrap();
+                    let len =
+                        len.try_eval_usize(tcx, ParamEnv::reveal_all()).ok_or(Err::Unspecified)?;
                     let elt = Tree::from_ty(*ty, tcx)?;
                     Ok(std::iter::repeat(elt)
                         .take(len as usize)
diff --git a/src/test/ui/transmutability/arrays/issue-103783-array-length.rs b/src/test/ui/transmutability/arrays/issue-103783-array-length.rs
new file mode 100644
index 00000000000..cb36e539ed1
--- /dev/null
+++ b/src/test/ui/transmutability/arrays/issue-103783-array-length.rs
@@ -0,0 +1,24 @@
+#![crate_type = "lib"]
+#![feature(transmutability)]
+#![allow(dead_code)]
+
+mod assert {
+    use std::mem::{Assume, BikeshedIntrinsicFrom};
+    pub struct Context;
+
+    pub fn is_maybe_transmutable<Src, Dst>()
+    where
+        Dst: BikeshedIntrinsicFrom<
+            Src,
+            Context,
+            { Assume { alignment: true, lifetimes: true, safety: true, validity: true } },
+        >,
+    {
+    }
+}
+
+fn test() {
+    type NaughtyLenArray = [u32; 3.14159]; //~ ERROR mismatched types
+    type JustUnit = ();
+    assert::is_maybe_transmutable::<JustUnit, NaughtyLenArray>();
+}
diff --git a/src/test/ui/transmutability/arrays/issue-103783-array-length.stderr b/src/test/ui/transmutability/arrays/issue-103783-array-length.stderr
new file mode 100644
index 00000000000..37774c59e6c
--- /dev/null
+++ b/src/test/ui/transmutability/arrays/issue-103783-array-length.stderr
@@ -0,0 +1,9 @@
+error[E0308]: mismatched types
+  --> $DIR/issue-103783-array-length.rs:21:34
+   |
+LL |     type NaughtyLenArray = [u32; 3.14159];
+   |                                  ^^^^^^^ expected `usize`, found floating-point number
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.