@@ -13,14 +13,11 @@ use borrow_check::location::LocationTable;
13
13
use borrow_check:: nll:: ToRegionVid ;
14
14
use borrow_check:: nll:: facts:: AllFacts ;
15
15
use borrow_check:: nll:: region_infer:: RegionInferenceContext ;
16
- use borrow_check:: nll:: type_check:: AtLocation ;
17
- use rustc:: hir;
18
16
use rustc:: infer:: InferCtxt ;
19
17
use rustc:: mir:: visit:: TyContext ;
20
18
use rustc:: mir:: visit:: Visitor ;
21
- use rustc:: mir:: Place :: Projection ;
22
19
use rustc:: mir:: { BasicBlock , BasicBlockData , Location , Mir , Place , Rvalue } ;
23
- use rustc:: mir:: { Local , PlaceProjection , ProjectionElem , Statement , Terminator } ;
20
+ use rustc:: mir:: { Local , Statement , Terminator } ;
24
21
use rustc:: ty:: fold:: TypeFoldable ;
25
22
use rustc:: ty:: subst:: Substs ;
26
23
use rustc:: ty:: { self , CanonicalTy , ClosureSubsts , GeneratorSubsts } ;
@@ -41,7 +38,6 @@ pub(super) fn generate_constraints<'cx, 'gcx, 'tcx>(
41
38
regioncx,
42
39
location_table,
43
40
all_facts,
44
- mir,
45
41
} ;
46
42
47
43
cg. add_region_liveness_constraints_from_type_check ( liveness_set_from_typeck) ;
@@ -57,7 +53,6 @@ struct ConstraintGeneration<'cg, 'cx: 'cg, 'gcx: 'tcx, 'tcx: 'cx> {
57
53
all_facts : & ' cg mut Option < AllFacts > ,
58
54
location_table : & ' cg LocationTable ,
59
55
regioncx : & ' cg mut RegionInferenceContext < ' tcx > ,
60
- mir : & ' cg Mir < ' tcx > ,
61
56
borrow_set : & ' cg BorrowSet < ' tcx > ,
62
57
}
63
58
@@ -184,41 +179,6 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx
184
179
self . super_terminator ( block, terminator, location) ;
185
180
}
186
181
187
- fn visit_rvalue ( & mut self , rvalue : & Rvalue < ' tcx > , location : Location ) {
188
- debug ! ( "visit_rvalue(rvalue={:?}, location={:?})" , rvalue, location) ;
189
-
190
- match rvalue {
191
- Rvalue :: Ref ( region, _borrow_kind, borrowed_place) => {
192
- // In some cases, e.g. when borrowing from an unsafe
193
- // place, we don't bother to create a loan, since
194
- // there are no conditions to validate.
195
- if let Some ( all_facts) = self . all_facts {
196
- if let Some ( borrow_index) = self . borrow_set . location_map . get ( & location) {
197
- let region_vid = region. to_region_vid ( ) ;
198
- all_facts. borrow_region . push ( (
199
- region_vid,
200
- * borrow_index,
201
- self . location_table . mid_index ( location) ,
202
- ) ) ;
203
- }
204
- }
205
-
206
- // Look for an rvalue like:
207
- //
208
- // & L
209
- //
210
- // where L is the path that is borrowed. In that case, we have
211
- // to add the reborrow constraints (which don't fall out
212
- // naturally from the type-checker).
213
- self . add_reborrow_constraint ( location, region, borrowed_place) ;
214
- }
215
-
216
- _ => { }
217
- }
218
-
219
- self . super_rvalue ( rvalue, location) ;
220
- }
221
-
222
182
fn visit_user_assert_ty (
223
183
& mut self ,
224
184
_c_ty : & CanonicalTy < ' tcx > ,
@@ -285,100 +245,4 @@ impl<'cx, 'cg, 'gcx, 'tcx> ConstraintGeneration<'cx, 'cg, 'gcx, 'tcx> {
285
245
self . regioncx . add_live_point ( vid, location) ;
286
246
} ) ;
287
247
}
288
-
289
- // Add the reborrow constraint at `location` so that `borrowed_place`
290
- // is valid for `borrow_region`.
291
- fn add_reborrow_constraint (
292
- & mut self ,
293
- location : Location ,
294
- borrow_region : ty:: Region < ' tcx > ,
295
- borrowed_place : & Place < ' tcx > ,
296
- ) {
297
- let mut borrowed_place = borrowed_place;
298
-
299
- debug ! (
300
- "add_reborrow_constraint({:?}, {:?}, {:?})" ,
301
- location, borrow_region, borrowed_place
302
- ) ;
303
- while let Projection ( box PlaceProjection { base, elem } ) = borrowed_place {
304
- debug ! ( "add_reborrow_constraint - iteration {:?}" , borrowed_place) ;
305
-
306
- match * elem {
307
- ProjectionElem :: Deref => {
308
- let tcx = self . infcx . tcx ;
309
- let base_ty = base. ty ( self . mir , tcx) . to_ty ( tcx) ;
310
-
311
- debug ! ( "add_reborrow_constraint - base_ty = {:?}" , base_ty) ;
312
- match base_ty. sty {
313
- ty:: TyRef ( ref_region, _, mutbl) => {
314
- self . regioncx . add_outlives (
315
- location. boring ( ) ,
316
- ref_region. to_region_vid ( ) ,
317
- borrow_region. to_region_vid ( ) ,
318
- ) ;
319
-
320
- if let Some ( all_facts) = self . all_facts {
321
- all_facts. outlives . push ( (
322
- ref_region. to_region_vid ( ) ,
323
- borrow_region. to_region_vid ( ) ,
324
- self . location_table . mid_index ( location) ,
325
- ) ) ;
326
- }
327
-
328
- match mutbl {
329
- hir:: Mutability :: MutImmutable => {
330
- // Immutable reference. We don't need the base
331
- // to be valid for the entire lifetime of
332
- // the borrow.
333
- break ;
334
- }
335
- hir:: Mutability :: MutMutable => {
336
- // Mutable reference. We *do* need the base
337
- // to be valid, because after the base becomes
338
- // invalid, someone else can use our mutable deref.
339
-
340
- // This is in order to make the following function
341
- // illegal:
342
- // ```
343
- // fn unsafe_deref<'a, 'b>(x: &'a &'b mut T) -> &'b mut T {
344
- // &mut *x
345
- // }
346
- // ```
347
- //
348
- // As otherwise you could clone `&mut T` using the
349
- // following function:
350
- // ```
351
- // fn bad(x: &mut T) -> (&mut T, &mut T) {
352
- // let my_clone = unsafe_deref(&'a x);
353
- // ENDREGION 'a;
354
- // (my_clone, x)
355
- // }
356
- // ```
357
- }
358
- }
359
- }
360
- ty:: TyRawPtr ( ..) => {
361
- // deref of raw pointer, guaranteed to be valid
362
- break ;
363
- }
364
- ty:: TyAdt ( def, _) if def. is_box ( ) => {
365
- // deref of `Box`, need the base to be valid - propagate
366
- }
367
- _ => bug ! ( "unexpected deref ty {:?} in {:?}" , base_ty, borrowed_place) ,
368
- }
369
- }
370
- ProjectionElem :: Field ( ..)
371
- | ProjectionElem :: Downcast ( ..)
372
- | ProjectionElem :: Index ( ..)
373
- | ProjectionElem :: ConstantIndex { .. }
374
- | ProjectionElem :: Subslice { .. } => {
375
- // other field access
376
- }
377
- }
378
-
379
- // The "propagate" case. We need to check that our base is valid
380
- // for the borrow's lifetime.
381
- borrowed_place = base;
382
- }
383
- }
384
248
}
0 commit comments