about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2025-06-10 16:54:50 +0200
committerGitHub <noreply@github.com>2025-06-10 16:54:50 +0200
commite8be230f1ff21e00d54dd45f4f3119ca35ec2196 (patch)
tree998b3f7fe5125aa4e19680723911bcbb637ec16b /compiler/rustc_mir_transform/src
parent590f630ec6affc51dee868ad968743fe4b7251fc (diff)
parentc677dc26b4d9d5e742ff860ace924a270a2266b6 (diff)
downloadrust-e8be230f1ff21e00d54dd45f4f3119ca35ec2196.tar.gz
rust-e8be230f1ff21e00d54dd45f4f3119ca35ec2196.zip
Rollup merge of #142124 - oli-obk:transmute-cast, r=scottmcm
Allow transmute casts in pre-runtime-MIR

r? ``@scottmcm``

cc ``@BoxyUwU``

turns out in https://github.com/rust-lang/rust/pull/138393 I erroneously used transmute casts in https://github.com/rust-lang/rust/blob/fd3da4bebdff63b7529483ff7025986ef16bf463/compiler/rustc_mir_build/src/builder/matches/test.rs#L209

I don't think they have any issues using them before runtime, we just checked for them because we didn't have code exercising those code paths
Diffstat (limited to 'compiler/rustc_mir_transform/src')
-rw-r--r--compiler/rustc_mir_transform/src/validate.rs48
1 files changed, 19 insertions, 29 deletions
diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs
index fd91508cc11..7dcdd7999f2 100644
--- a/compiler/rustc_mir_transform/src/validate.rs
+++ b/compiler/rustc_mir_transform/src/validate.rs
@@ -1308,37 +1308,27 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
                         }
                     }
                     CastKind::Transmute => {
-                        if let MirPhase::Runtime(..) = self.body.phase {
-                            // Unlike `mem::transmute`, a MIR `Transmute` is well-formed
-                            // for any two `Sized` types, just potentially UB to run.
-
-                            if !self
-                                .tcx
-                                .normalize_erasing_regions(self.typing_env, op_ty)
-                                .is_sized(self.tcx, self.typing_env)
-                            {
-                                self.fail(
-                                    location,
-                                    format!("Cannot transmute from non-`Sized` type {op_ty}"),
-                                );
-                            }
-                            if !self
-                                .tcx
-                                .normalize_erasing_regions(self.typing_env, *target_type)
-                                .is_sized(self.tcx, self.typing_env)
-                            {
-                                self.fail(
-                                    location,
-                                    format!("Cannot transmute to non-`Sized` type {target_type:?}"),
-                                );
-                            }
-                        } else {
+                        // Unlike `mem::transmute`, a MIR `Transmute` is well-formed
+                        // for any two `Sized` types, just potentially UB to run.
+
+                        if !self
+                            .tcx
+                            .normalize_erasing_regions(self.typing_env, op_ty)
+                            .is_sized(self.tcx, self.typing_env)
+                        {
                             self.fail(
                                 location,
-                                format!(
-                                    "Transmute is not supported in non-runtime phase {:?}.",
-                                    self.body.phase
-                                ),
+                                format!("Cannot transmute from non-`Sized` type {op_ty}"),
+                            );
+                        }
+                        if !self
+                            .tcx
+                            .normalize_erasing_regions(self.typing_env, *target_type)
+                            .is_sized(self.tcx, self.typing_env)
+                        {
+                            self.fail(
+                                location,
+                                format!("Cannot transmute to non-`Sized` type {target_type:?}"),
                             );
                         }
                     }