@@ -5,7 +5,7 @@ use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
5
5
use rustc_middle:: mir:: * ;
6
6
7
7
use super :: MaybeBorrowedLocals ;
8
- use crate :: { Analysis , GenKill , ResultsCursor } ;
8
+ use crate :: { Analysis , GenKill , Results , ResultsCursor } ;
9
9
10
10
pub struct MaybeStorageLive < ' a > {
11
11
always_live_locals : Cow < ' a , BitSet < Local > > ,
@@ -96,17 +96,19 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeStorageDead<'a> {
96
96
}
97
97
}
98
98
99
- type BorrowedLocalsResults < ' mir , ' tcx > = ResultsCursor < ' mir , ' tcx , MaybeBorrowedLocals > ;
100
-
101
99
/// Dataflow analysis that determines whether each local requires storage at a
102
100
/// given location; i.e. whether its storage can go away without being observed.
103
101
pub struct MaybeRequiresStorage < ' mir , ' tcx > {
104
- borrowed_locals : BorrowedLocalsResults < ' mir , ' tcx > ,
102
+ body : & ' mir Body < ' tcx > ,
103
+ borrowed_locals : Results < ' tcx , MaybeBorrowedLocals > ,
105
104
}
106
105
107
106
impl < ' mir , ' tcx > MaybeRequiresStorage < ' mir , ' tcx > {
108
- pub fn new ( borrowed_locals : BorrowedLocalsResults < ' mir , ' tcx > ) -> Self {
109
- MaybeRequiresStorage { borrowed_locals }
107
+ pub fn new (
108
+ body : & ' mir Body < ' tcx > ,
109
+ borrowed_locals : Results < ' tcx , MaybeBorrowedLocals > ,
110
+ ) -> Self {
111
+ MaybeRequiresStorage { body, borrowed_locals }
110
112
}
111
113
}
112
114
@@ -135,7 +137,7 @@ impl<'tcx> Analysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
135
137
loc : Location ,
136
138
) {
137
139
// If a place is borrowed in a statement, it needs storage for that statement.
138
- self . borrowed_locals . mut_analysis ( ) . apply_statement_effect ( trans, stmt, loc) ;
140
+ self . borrowed_locals . analysis . apply_statement_effect ( trans, stmt, loc) ;
139
141
140
142
match & stmt. kind {
141
143
StatementKind :: StorageDead ( l) => trans. kill ( * l) ,
@@ -179,10 +181,7 @@ impl<'tcx> Analysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
179
181
loc : Location ,
180
182
) {
181
183
// If a place is borrowed in a terminator, it needs storage for that terminator.
182
- self . borrowed_locals
183
- . mut_analysis ( )
184
- . transfer_function ( trans)
185
- . visit_terminator ( terminator, loc) ;
184
+ self . borrowed_locals . analysis . transfer_function ( trans) . visit_terminator ( terminator, loc) ;
186
185
187
186
match & terminator. kind {
188
187
TerminatorKind :: Call { destination, .. } => {
@@ -283,15 +282,15 @@ impl<'tcx> Analysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
283
282
284
283
impl < ' tcx > MaybeRequiresStorage < ' _ , ' tcx > {
285
284
/// Kill locals that are fully moved and have not been borrowed.
286
- fn check_for_move ( & mut self , trans : & mut <Self as Analysis < ' tcx > >:: Domain , loc : Location ) {
287
- let body = self . borrowed_locals . body ( ) ;
288
- let mut visitor = MoveVisitor { trans, borrowed_locals : & mut self . borrowed_locals } ;
289
- visitor. visit_location ( body, loc) ;
285
+ fn check_for_move ( & self , trans : & mut <Self as Analysis < ' tcx > >:: Domain , loc : Location ) {
286
+ let borrowed_locals = self . borrowed_locals . clone ( ) . into_results_cursor ( self . body ) ;
287
+ let mut visitor = MoveVisitor { trans, borrowed_locals } ;
288
+ visitor. visit_location ( self . body , loc) ;
290
289
}
291
290
}
292
291
293
292
struct MoveVisitor < ' a , ' mir , ' tcx > {
294
- borrowed_locals : & ' a mut BorrowedLocalsResults < ' mir , ' tcx > ,
293
+ borrowed_locals : ResultsCursor < ' mir , ' tcx , MaybeBorrowedLocals > ,
295
294
trans : & ' a mut BitSet < Local > ,
296
295
}
297
296
0 commit comments