@@ -2605,9 +2605,34 @@ pub enum Rvalue<'tcx> {
2605
2605
static_assert_size ! ( Rvalue <' _>, 40 ) ;
2606
2606
2607
2607
impl < ' tcx > Rvalue < ' tcx > {
2608
+ /// Returns true if rvalue can be safely removed when the result is unused.
2608
2609
#[ inline]
2609
- pub fn is_pointer_int_cast ( & self ) -> bool {
2610
- matches ! ( self , Rvalue :: Cast ( CastKind :: PointerExposeAddress , _, _) )
2610
+ pub fn is_safe_to_remove ( & self ) -> bool {
2611
+ match self {
2612
+ // Pointer to int casts may be side-effects due to exposing the provenance.
2613
+ // While the model is undecided, we should be conservative. See
2614
+ // <https://www.ralfj.de/blog/2022/04/11/provenance-exposed.html>
2615
+ Rvalue :: Cast ( CastKind :: PointerExposeAddress , _, _) => false ,
2616
+
2617
+ Rvalue :: Use ( _)
2618
+ | Rvalue :: Repeat ( _, _)
2619
+ | Rvalue :: Ref ( _, _, _)
2620
+ | Rvalue :: ThreadLocalRef ( _)
2621
+ | Rvalue :: AddressOf ( _, _)
2622
+ | Rvalue :: Len ( _)
2623
+ | Rvalue :: Cast (
2624
+ CastKind :: Misc | CastKind :: Pointer ( _) | CastKind :: PointerFromExposedAddress ,
2625
+ _,
2626
+ _,
2627
+ )
2628
+ | Rvalue :: BinaryOp ( _, _)
2629
+ | Rvalue :: CheckedBinaryOp ( _, _)
2630
+ | Rvalue :: NullaryOp ( _, _)
2631
+ | Rvalue :: UnaryOp ( _, _)
2632
+ | Rvalue :: Discriminant ( _)
2633
+ | Rvalue :: Aggregate ( _, _)
2634
+ | Rvalue :: ShallowInitBox ( _, _) => true ,
2635
+ }
2611
2636
}
2612
2637
}
2613
2638
0 commit comments