@@ -51,15 +51,17 @@ struct UnneededDerefVisitor<'a, 'tcx> {
51
51
refs : FxHashMap < Local , Place < ' tcx > > ,
52
52
optimizations : & ' a mut FxHashMap < ( Location , Place < ' tcx > ) , Place < ' tcx > > ,
53
53
results : & ' a Results < ' tcx , AvailableLocals > ,
54
- state : Option < Dual < BitSet < LocalWithLocationIndex > > > ,
54
+ state : * const Dual < BitSet < LocalWithLocationIndex > > ,
55
55
}
56
56
57
57
impl < ' a , ' tcx > Visitor < ' tcx > for UnneededDerefVisitor < ' a , ' tcx > {
58
58
fn visit_place ( & mut self , place : & Place < ' tcx > , context : PlaceContext , location : Location ) {
59
59
let analysis = & self . results . analysis ;
60
60
let _: Option < _ > = try {
61
61
debug ! ( "Visiting place {:?}" , place) ;
62
- let state = self . state . as_ref ( ) ?;
62
+ // SAFETY: We only use self.state here which is always called from statement_before_primary_effect,
63
+ // which guarantees that self.state is still alive.
64
+ let state = unsafe { self . state . as_ref ( ) . unwrap ( ) } ;
63
65
64
66
match place. as_ref ( ) {
65
67
PlaceRef { projection : [ ProjectionElem :: Deref ] , .. } => {
@@ -112,7 +114,7 @@ impl<'a, 'tcx> UnneededDerefVisitor<'a, 'tcx> {
112
114
refs,
113
115
optimizations : & mut optimizations,
114
116
results : & results,
115
- state : None ,
117
+ state : std :: ptr :: null ( ) ,
116
118
} ;
117
119
118
120
results. visit_reachable_with ( body, & mut _self) ;
@@ -129,7 +131,7 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx> for UnneededDerefVisitor<'a, 'tcx> {
129
131
stmt : & ' mir Statement < ' tcx > ,
130
132
location : Location ,
131
133
) {
132
- self . state = Some ( state. clone ( ) ) ;
134
+ self . state = state;
133
135
let analysis = & self . results . analysis ;
134
136
debug ! ( "state: {:?} before statement {:?}" , analysis. debug_state( state) , stmt) ;
135
137
let _: Option < _ > = try {
0 commit comments