about summary refs log tree commit diff
path: root/compiler/rustc_transmute/src/lib.rs
diff options
context:
space:
mode:
authorBryan Garza <1396101+bryangarza@users.noreply.github.com>2023-07-13 16:32:36 -0700
committerBryan Garza <1396101+bryangarza@users.noreply.github.com>2023-07-17 09:43:35 -0700
commitef50e204f35ba2952f7ffd0e7560b136f1ace0aa (patch)
tree6824c95fb64273695c5c2fa1f8df985cfd6afcbf /compiler/rustc_transmute/src/lib.rs
parent8ca44ef9caa4049d584fbbce218c219cdca33a2f (diff)
downloadrust-ef50e204f35ba2952f7ffd0e7560b136f1ace0aa.tar.gz
rust-ef50e204f35ba2952f7ffd0e7560b136f1ace0aa.zip
Safe Transmute: Fix ICE (due to UnevaluatedConst)
This patch updates the code that looks at the `Assume` type when evaluating if
transmutation is possible. An ICE was being triggered in the case that the
`Assume` parameter contained an unevaluated const (in this test case, due to a
function with missing parameter names).

Fixes #110892
Diffstat (limited to 'compiler/rustc_transmute/src/lib.rs')
-rw-r--r--compiler/rustc_transmute/src/lib.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/compiler/rustc_transmute/src/lib.rs b/compiler/rustc_transmute/src/lib.rs
index 34ad6bd8c69..05ad4a4a12a 100644
--- a/compiler/rustc_transmute/src/lib.rs
+++ b/compiler/rustc_transmute/src/lib.rs
@@ -78,6 +78,7 @@ mod rustc {
     use rustc_middle::ty::ParamEnv;
     use rustc_middle::ty::Ty;
     use rustc_middle::ty::TyCtxt;
+    use rustc_middle::ty::ValTree;
 
     /// The source and destination types of a transmutation.
     #[derive(TypeVisitable, Debug, Clone, Copy)]
@@ -148,7 +149,17 @@ mod rustc {
             );
 
             let variant = adt_def.non_enum_variant();
-            let fields = c.to_valtree().unwrap_branch();
+            let fields = match c.try_to_valtree() {
+                Some(ValTree::Branch(branch)) => branch,
+                _ => {
+                    return Some(Self {
+                        alignment: true,
+                        lifetimes: true,
+                        safety: true,
+                        validity: true,
+                    });
+                }
+            };
 
             let get_field = |name| {
                 let (field_idx, _) = variant