@@ -15,7 +15,7 @@ use rustc_data_structures::bit_set::BitSet;
1515use rustc_data_structures:: graph:: dominators:: Dominators ;
1616use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
1717use rustc:: mir:: { self , Location , TerminatorKind } ;
18- use rustc:: mir:: visit:: { Visitor , PlaceContext } ;
18+ use rustc:: mir:: visit:: { Visitor , PlaceContext , MutatingUseContext , NonMutatingUseContext } ;
1919use rustc:: mir:: traversal;
2020use rustc:: ty;
2121use rustc:: ty:: layout:: LayoutOf ;
@@ -116,7 +116,11 @@ impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
116116 self . not_ssa ( index) ;
117117 }
118118 } else {
119- self . visit_place ( place, PlaceContext :: Store , location) ;
119+ self . visit_place (
120+ place,
121+ PlaceContext :: MutatingUse ( MutatingUseContext :: Store ) ,
122+ location
123+ ) ;
120124 }
121125
122126 self . visit_rvalue ( rvalue, location) ;
@@ -142,7 +146,11 @@ impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
142146 // is not guaranteed to be statically dominated by the
143147 // definition of x, so x must always be in an alloca.
144148 if let mir:: Operand :: Move ( ref place) = args[ 0 ] {
145- self . visit_place ( place, PlaceContext :: Drop , location) ;
149+ self . visit_place (
150+ place,
151+ PlaceContext :: MutatingUse ( MutatingUseContext :: Drop ) ,
152+ location
153+ ) ;
146154 }
147155 }
148156 }
@@ -160,7 +168,8 @@ impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
160168 if let mir:: Place :: Projection ( ref proj) = * place {
161169 // Allow uses of projections that are ZSTs or from scalar fields.
162170 let is_consume = match context {
163- PlaceContext :: Copy | PlaceContext :: Move => true ,
171+ PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Copy ) |
172+ PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Move ) => true ,
164173 _ => false
165174 } ;
166175 if is_consume {
@@ -190,7 +199,11 @@ impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
190199
191200 // A deref projection only reads the pointer, never needs the place.
192201 if let mir:: ProjectionElem :: Deref = proj. elem {
193- return self . visit_place ( & proj. base , PlaceContext :: Copy , location) ;
202+ return self . visit_place (
203+ & proj. base ,
204+ PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Copy ) ,
205+ location
206+ ) ;
194207 }
195208 }
196209
@@ -202,16 +215,14 @@ impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
202215 context : PlaceContext < ' tcx > ,
203216 location : Location ) {
204217 match context {
205- PlaceContext :: Call => {
218+ PlaceContext :: MutatingUse ( MutatingUseContext :: Call ) => {
206219 self . assign ( local, location) ;
207220 }
208221
209- PlaceContext :: StorageLive |
210- PlaceContext :: StorageDead |
211- PlaceContext :: Validate => { }
222+ PlaceContext :: NonUse ( _) => { }
212223
213- PlaceContext :: Copy |
214- PlaceContext :: Move => {
224+ PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Copy ) |
225+ PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Move ) => {
215226 // Reads from uninitialized variables (e.g. in dead code, after
216227 // optimizations) require locals to be in (uninitialized) memory.
217228 // NB: there can be uninitialized reads of a local visited after
@@ -227,15 +238,19 @@ impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
227238 }
228239 }
229240
230- PlaceContext :: Inspect |
231- PlaceContext :: Store |
232- PlaceContext :: AsmOutput |
233- PlaceContext :: Borrow { .. } |
234- PlaceContext :: Projection ( ..) => {
241+ PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Inspect ) |
242+ PlaceContext :: MutatingUse ( MutatingUseContext :: Store ) |
243+ PlaceContext :: MutatingUse ( MutatingUseContext :: AsmOutput ) |
244+ PlaceContext :: MutatingUse ( MutatingUseContext :: Borrow ( ..) ) |
245+ PlaceContext :: MutatingUse ( MutatingUseContext :: Projection ) |
246+ PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: SharedBorrow ( ..) ) |
247+ PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: UniqueBorrow ( ..) ) |
248+ PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: ShallowBorrow ( ..) ) |
249+ PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Projection ) => {
235250 self . not_ssa ( local) ;
236251 }
237252
238- PlaceContext :: Drop => {
253+ PlaceContext :: MutatingUse ( MutatingUseContext :: Drop ) => {
239254 let ty = mir:: Place :: Local ( local) . ty ( self . fx . mir , self . fx . cx . tcx ) ;
240255 let ty = self . fx . monomorphize ( & ty. to_ty ( self . fx . cx . tcx ) ) ;
241256
0 commit comments