@@ -18,6 +18,8 @@ use rustc::mir::{ProjectionElem, BorrowKind};
18
18
use rustc:: ty:: TyCtxt ;
19
19
use rustc_data_structures:: graph:: dominators:: Dominators ;
20
20
21
+ use super :: place_ext:: PlaceExt ;
22
+
21
23
/// Returns true if the borrow represented by `kind` is
22
24
/// allowed to be split into separate Reservation and
23
25
/// Activation phases.
@@ -38,37 +40,40 @@ pub(super) enum Control {
38
40
}
39
41
40
42
/// Encapsulates the idea of iterating over every borrow that involves a particular path
41
- pub ( super ) fn each_borrow_involving_path < ' a , ' tcx , ' gcx : ' tcx , F , I , S > (
43
+ pub ( super ) fn each_borrow_involving_path < ' a , ' tcx , ' gcx : ' tcx , S > (
42
44
s : & mut S ,
43
45
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
44
46
mir : & Mir < ' tcx > ,
45
47
_context : Context ,
46
48
access_place : ( ShallowOrDeep , & Place < ' tcx > ) ,
47
49
borrow_set : & BorrowSet < ' tcx > ,
48
- candidates : I ,
49
- mut op : F ,
50
- ) where
51
- F : FnMut ( & mut S , BorrowIndex , & BorrowData < ' tcx > ) -> Control ,
52
- I : Iterator < Item =BorrowIndex >
53
- {
50
+ is_borrow_in_scope : impl Fn ( BorrowIndex ) -> bool ,
51
+ mut op : impl FnMut ( & mut S , BorrowIndex , & BorrowData < ' tcx > ) -> Control ,
52
+ ) {
54
53
let ( access, place) = access_place;
55
54
56
55
// FIXME: analogous code in check_loans first maps `place` to
57
56
// its base_path.
58
57
59
58
// check for loan restricting path P being used. Accounts for
60
59
// borrows of P, P.a.b, etc.
61
- for i in candidates {
62
- let borrowed = & borrow_set[ i] ;
60
+ if let Some ( ref local) = place. root_local ( ) {
61
+ if let Some ( borrow_indices) = borrow_set. local_map . get ( local) {
62
+ for i in borrow_indices. iter ( ) {
63
+ let borrowed = & borrow_set[ * i] ;
63
64
64
- if places_conflict:: places_conflict ( tcx, mir, & borrowed. borrowed_place , place, access) {
65
- debug ! (
66
- "each_borrow_involving_path: {:?} @ {:?} vs. {:?}/{:?}" ,
67
- i, borrowed, place, access
68
- ) ;
69
- let ctrl = op ( s, i, borrowed) ;
70
- if ctrl == Control :: Break {
71
- return ;
65
+ if is_borrow_in_scope ( * i) &&
66
+ places_conflict:: places_conflict (
67
+ tcx, mir, & borrowed. borrowed_place , place, access) {
68
+ debug ! (
69
+ "each_borrow_involving_path: {:?} @ {:?} vs. {:?}/{:?}" ,
70
+ i, borrowed, place, access
71
+ ) ;
72
+ let ctrl = op ( s, * i, borrowed) ;
73
+ if ctrl == Control :: Break {
74
+ return ;
75
+ }
76
+ }
72
77
}
73
78
}
74
79
}
0 commit comments