Skip to content

Commit 4adb8fb

Browse files
committed
Remove workaround for CastKind::Transmute from const prop
Since constants are no longer validated before propagation the workaround is obsolete. Remove it.
1 parent bc41973 commit 4adb8fb

6 files changed

+19
-15
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -501,16 +501,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
501501

502502
return None;
503503
}
504-
// Do not try creating references, nor any types with potentially-complex
505-
// invariants. This avoids an issue where checking validity would do a
506-
// bunch of work generating a nice message about the invariant violation,
507-
// only to not show it to anyone (since this isn't the lint).
508-
Rvalue::Cast(CastKind::Transmute, op, dst_ty) if !dst_ty.is_primitive() => {
509-
trace!("skipping Transmute of {:?} to {:?}", op, dst_ty);
510-
511-
return None;
512-
}
513-
514504
// There's no other checking to do at this time.
515505
Rvalue::Aggregate(..)
516506
| Rvalue::Use(..)

tests/mir-opt/const_prop/transmute.invalid_bool.ConstProp.diff

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
}
88

99
bb0: {
10-
_0 = const -1_i8 as bool (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:30
10+
- _0 = const -1_i8 as bool (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:30
11+
+ _0 = const {transmute(0xff): bool}; // scope 1 at $DIR/transmute.rs:+1:14: +1:30
1112
return; // scope 0 at $DIR/transmute.rs:+2:2: +2:2
1213
}
1314
}

tests/mir-opt/const_prop/transmute.invalid_char.ConstProp.diff

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
}
88

99
bb0: {
10-
_0 = const _ as char (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:33
10+
- _0 = const _ as char (Transmute); // scope 1 at $DIR/transmute.rs:+1:14: +1:33
11+
+ _0 = const {transmute(0x7fffffff): char}; // scope 1 at $DIR/transmute.rs:+1:14: +1:33
1112
return; // scope 0 at $DIR/transmute.rs:+2:2: +2:2
1213
}
1314
}

tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.diff

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
bb0: {
1616
StorageLive(_1); // scope 0 at $DIR/transmute.rs:+0:38: +3:2
1717
StorageLive(_2); // scope 0 at $DIR/transmute.rs:+1:9: +1:10
18-
_2 = const 1_usize as std::boxed::Box<Never> (Transmute); // scope 2 at $DIR/transmute.rs:+1:34: +1:52
18+
- _2 = const 1_usize as std::boxed::Box<Never> (Transmute); // scope 2 at $DIR/transmute.rs:+1:34: +1:52
19+
+ _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
20+
+ // mir::Constant
21+
+ // + span: no-location
22+
+ // + literal: Const { ty: Box<Never>, val: Value(Scalar(0x0000000000000001)) }
1923
StorageLive(_3); // scope 1 at $DIR/transmute.rs:+2:5: +2:16
2024
unreachable; // scope 1 at $DIR/transmute.rs:+2:11: +2:13
2125
}

tests/mir-opt/const_prop/transmute.unreachable_mut.ConstProp.diff

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
StorageLive(_1); // scope 0 at $DIR/transmute.rs:+0:38: +3:2
1818
StorageLive(_2); // scope 0 at $DIR/transmute.rs:+1:9: +1:10
1919
StorageLive(_3); // scope 0 at $DIR/transmute.rs:+1:34: +1:52
20-
_3 = const 1_usize as &mut Never (Transmute); // scope 2 at $DIR/transmute.rs:+1:34: +1:52
20+
- _3 = const 1_usize as &mut Never (Transmute); // scope 2 at $DIR/transmute.rs:+1:34: +1:52
21+
+ _3 = const {0x1 as &mut Never}; // scope 2 at $DIR/transmute.rs:+1:34: +1:52
22+
+ // mir::Constant
23+
+ // + span: no-location
24+
+ // + literal: Const { ty: &mut Never, val: Value(Scalar(0x0000000000000001)) }
2125
_2 = &mut (*_3); // scope 0 at $DIR/transmute.rs:+1:34: +1:52
2226
StorageDead(_3); // scope 0 at $DIR/transmute.rs:+1:54: +1:55
2327
StorageLive(_4); // scope 1 at $DIR/transmute.rs:+2:5: +2:16

tests/mir-opt/const_prop/transmute.unreachable_ref.ConstProp.diff

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
bb0: {
1616
StorageLive(_1); // scope 0 at $DIR/transmute.rs:+0:38: +3:2
1717
StorageLive(_2); // scope 0 at $DIR/transmute.rs:+1:9: +1:10
18-
_2 = const 1_usize as &Never (Transmute); // scope 2 at $DIR/transmute.rs:+1:30: +1:48
18+
- _2 = const 1_usize as &Never (Transmute); // scope 2 at $DIR/transmute.rs:+1:30: +1:48
19+
+ _2 = const {0x1 as &Never}; // scope 2 at $DIR/transmute.rs:+1:30: +1:48
20+
+ // mir::Constant
21+
+ // + span: no-location
22+
+ // + literal: Const { ty: &Never, val: Value(Scalar(0x0000000000000001)) }
1923
StorageLive(_3); // scope 1 at $DIR/transmute.rs:+2:5: +2:16
2024
unreachable; // scope 1 at $DIR/transmute.rs:+2:11: +2:13
2125
}

0 commit comments

Comments
 (0)