summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2023-03-27 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2023-04-27 00:33:52 +0200
commit4adb8fbda002dc9b31b56b242094c16788586b3c (patch)
tree3d50d4ca6bd86047c83fb3e6a48cc3b49793cd10
parentbc41973e35e60fe01cb6f464240a2f1db9afb4bd (diff)
downloadrust-4adb8fbda002dc9b31b56b242094c16788586b3c.tar.gz
rust-4adb8fbda002dc9b31b56b242094c16788586b3c.zip
Remove workaround for CastKind::Transmute from const prop
Since constants are no longer validated before propagation the
workaround is obsolete. Remove it.
-rw-r--r--compiler/rustc_mir_transform/src/const_prop.rs10
-rw-r--r--tests/mir-opt/const_prop/transmute.invalid_bool.ConstProp.diff3
-rw-r--r--tests/mir-opt/const_prop/transmute.invalid_char.ConstProp.diff3
-rw-r--r--tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.diff6
-rw-r--r--tests/mir-opt/const_prop/transmute.unreachable_mut.ConstProp.diff6
-rw-r--r--tests/mir-opt/const_prop/transmute.unreachable_ref.ConstProp.diff6
6 files changed, 19 insertions, 15 deletions
diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs
index c4e715ccca8..7ac8ffb4955 100644
--- a/compiler/rustc_mir_transform/src/const_prop.rs
+++ b/compiler/rustc_mir_transform/src/const_prop.rs
@@ -501,16 +501,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
 
                 return None;
             }
-            // Do not try creating references, nor any types with potentially-complex
-            // invariants. This avoids an issue where checking validity would do a
-            // bunch of work generating a nice message about the invariant violation,
-            // only to not show it to anyone (since this isn't the lint).
-            Rvalue::Cast(CastKind::Transmute, op, dst_ty) if !dst_ty.is_primitive() => {
-                trace!("skipping Transmute of {:?} to {:?}", op, dst_ty);
-
-                return None;
-            }
-
             // There's no other checking to do at this time.
             Rvalue::Aggregate(..)
             | Rvalue::Use(..)
diff --git a/tests/mir-opt/const_prop/transmute.invalid_bool.ConstProp.diff b/tests/mir-opt/const_prop/transmute.invalid_bool.ConstProp.diff
index f3474855f02..4a31194de6e 100644
--- a/tests/mir-opt/const_prop/transmute.invalid_bool.ConstProp.diff
+++ b/tests/mir-opt/const_prop/transmute.invalid_bool.ConstProp.diff
@@ -7,7 +7,8 @@
       }
   
       bb0: {
-          _0 = const -1_i8 as bool (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:30
+-         _0 = const -1_i8 as bool (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:30
++         _0 = const {transmute(0xff): bool}; // scope 1 at $DIR/transmute.rs:+1:14: +1:30
           return;                          // scope 0 at $DIR/transmute.rs:+2:2: +2:2
       }
   }
diff --git a/tests/mir-opt/const_prop/transmute.invalid_char.ConstProp.diff b/tests/mir-opt/const_prop/transmute.invalid_char.ConstProp.diff
index ba087e226c9..2c541f2f6a0 100644
--- a/tests/mir-opt/const_prop/transmute.invalid_char.ConstProp.diff
+++ b/tests/mir-opt/const_prop/transmute.invalid_char.ConstProp.diff
@@ -7,7 +7,8 @@
       }
   
       bb0: {
-          _0 = const _ as char (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:33
+-         _0 = const _ as char (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:33
++         _0 = const {transmute(0x7fffffff): char}; // scope 1 at $DIR/transmute.rs:+1:14: +1:33
           return;                          // scope 0 at $DIR/transmute.rs:+2:2: +2:2
       }
   }
diff --git a/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.diff b/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.diff
index 8bf97996a67..c4376e6e17a 100644
--- a/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.diff
+++ b/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.diff
@@ -15,7 +15,11 @@
       bb0: {
           StorageLive(_1);                 // scope 0 at $DIR/transmute.rs:+0:38: +3:2
           StorageLive(_2);                 // scope 0 at $DIR/transmute.rs:+1:9: +1:10
-          _2 = const 1_usize as std::boxed::Box<Never> (Transmute); // scope 2 at $DIR/transmute.rs:+1:34: +1:52
+-         _2 = const 1_usize as std::boxed::Box<Never> (Transmute); // scope 2 at $DIR/transmute.rs:+1:34: +1:52
++         _2 = const Box::<Never>(Unique::<Never> {{ pointer: NonNull::<Never> {{ pointer: {0x1 as *const Never} }}, _marker: PhantomData::<Never> }}, std::alloc::Global); // scope 2 at $DIR/transmute.rs:+1:34: +1:52
++                                          // mir::Constant
++                                          // + span: no-location
++                                          // + literal: Const { ty: Box<Never>, val: Value(Scalar(0x0000000000000001)) }
           StorageLive(_3);                 // scope 1 at $DIR/transmute.rs:+2:5: +2:16
           unreachable;                     // scope 1 at $DIR/transmute.rs:+2:11: +2:13
       }
diff --git a/tests/mir-opt/const_prop/transmute.unreachable_mut.ConstProp.diff b/tests/mir-opt/const_prop/transmute.unreachable_mut.ConstProp.diff
index 34f7aea8ed2..62300d2e313 100644
--- a/tests/mir-opt/const_prop/transmute.unreachable_mut.ConstProp.diff
+++ b/tests/mir-opt/const_prop/transmute.unreachable_mut.ConstProp.diff
@@ -17,7 +17,11 @@
           StorageLive(_1);                 // scope 0 at $DIR/transmute.rs:+0:38: +3:2
           StorageLive(_2);                 // scope 0 at $DIR/transmute.rs:+1:9: +1:10
           StorageLive(_3);                 // scope 0 at $DIR/transmute.rs:+1:34: +1:52
-          _3 = const 1_usize as &mut Never (Transmute); // scope 2 at $DIR/transmute.rs:+1:34: +1:52
+-         _3 = const 1_usize as &mut Never (Transmute); // scope 2 at $DIR/transmute.rs:+1:34: +1:52
++         _3 = const {0x1 as &mut Never};  // scope 2 at $DIR/transmute.rs:+1:34: +1:52
++                                          // mir::Constant
++                                          // + span: no-location
++                                          // + literal: Const { ty: &mut Never, val: Value(Scalar(0x0000000000000001)) }
           _2 = &mut (*_3);                 // scope 0 at $DIR/transmute.rs:+1:34: +1:52
           StorageDead(_3);                 // scope 0 at $DIR/transmute.rs:+1:54: +1:55
           StorageLive(_4);                 // scope 1 at $DIR/transmute.rs:+2:5: +2:16
diff --git a/tests/mir-opt/const_prop/transmute.unreachable_ref.ConstProp.diff b/tests/mir-opt/const_prop/transmute.unreachable_ref.ConstProp.diff
index ff95f2a0b94..8b11cea9365 100644
--- a/tests/mir-opt/const_prop/transmute.unreachable_ref.ConstProp.diff
+++ b/tests/mir-opt/const_prop/transmute.unreachable_ref.ConstProp.diff
@@ -15,7 +15,11 @@
       bb0: {
           StorageLive(_1);                 // scope 0 at $DIR/transmute.rs:+0:38: +3:2
           StorageLive(_2);                 // scope 0 at $DIR/transmute.rs:+1:9: +1:10
-          _2 = const 1_usize as &Never (Transmute); // scope 2 at $DIR/transmute.rs:+1:30: +1:48
+-         _2 = const 1_usize as &Never (Transmute); // scope 2 at $DIR/transmute.rs:+1:30: +1:48
++         _2 = const {0x1 as &Never};      // scope 2 at $DIR/transmute.rs:+1:30: +1:48
++                                          // mir::Constant
++                                          // + span: no-location
++                                          // + literal: Const { ty: &Never, val: Value(Scalar(0x0000000000000001)) }
           StorageLive(_3);                 // scope 1 at $DIR/transmute.rs:+2:5: +2:16
           unreachable;                     // scope 1 at $DIR/transmute.rs:+2:11: +2:13
       }