summaryrefslogtreecommitdiffstats
path: root/src/librustc_mir/borrow_check/mod.rs
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2018-04-06 17:03:14 -0400
committerNiko Matsakis <niko@alum.mit.edu>2018-04-15 07:06:29 -0400
commit8e783da2228ec256d15bb6af0f7e1053fc1e040e (patch)
tree24bf5d9cd23cea3882a8b4c3ca13d52200860e42 /src/librustc_mir/borrow_check/mod.rs
parentconstruct the `BorrowSet` outside of `borrows` (diff)
downloadgrust-8e783da2228ec256d15bb6af0f7e1053fc1e040e.tar.gz
grust-8e783da2228ec256d15bb6af0f7e1053fc1e040e.tar.bz2
grust-8e783da2228ec256d15bb6af0f7e1053fc1e040e.tar.xz
encapsulate ReserveOrActivateIndex into the borrows dataflow
Diffstat (limited to 'src/librustc_mir/borrow_check/mod.rs')
-rw-r--r--src/librustc_mir/borrow_check/mod.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs
index 3cc79d947d..e4a4360a80 100644
--- a/src/librustc_mir/borrow_check/mod.rs
+++ b/src/librustc_mir/borrow_check/mod.rs
@@ -37,7 +37,7 @@ use dataflow::MoveDataParamEnv;
37use dataflow::{DataflowResultsConsumer}; 37use dataflow::{DataflowResultsConsumer};
38use dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces}; 38use dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces};
39use dataflow::{EverInitializedPlaces, MovingOutStatements}; 39use dataflow::{EverInitializedPlaces, MovingOutStatements};
40use dataflow::{Borrows, ReserveOrActivateIndex}; 40use dataflow::Borrows;
41use dataflow::indexes::BorrowIndex; 41use dataflow::indexes::BorrowIndex;
42use dataflow::move_paths::{IllegalMoveOriginKind, MoveError}; 42use dataflow::move_paths::{IllegalMoveOriginKind, MoveError};
43use dataflow::move_paths::{HasMoveData, LookupResult, MoveData, MovePathIndex}; 43use dataflow::move_paths::{HasMoveData, LookupResult, MoveData, MovePathIndex};
@@ -66,6 +66,8 @@ pub fn provide(providers: &mut Providers) {
66 }; 66 };
67} 67}
68 68
69struct IsActive(bool);
70
69fn mir_borrowck<'a, 'tcx>( 71fn mir_borrowck<'a, 'tcx>(
70 tcx: TyCtxt<'a, 'tcx, 'tcx>, 72 tcx: TyCtxt<'a, 'tcx, 'tcx>,
71 def_id: DefId, 73 def_id: DefId,
@@ -846,22 +848,21 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
846 context, 848 context,
847 (sd, place_span.0), 849 (sd, place_span.0),
848 flow_state, 850 flow_state,
849 |this, index, borrow| match (rw, borrow.kind) { 851 |this, borrow_index, is_active, borrow| match (rw, borrow.kind) {
850 // Obviously an activation is compatible with its own 852 // Obviously an activation is compatible with its own
851 // reservation (or even prior activating uses of same 853 // reservation (or even prior activating uses of same
852 // borrow); so don't check if they interfere. 854 // borrow); so don't check if they interfere.
853 // 855 //
854 // NOTE: *reservations* do conflict with themselves; 856 // NOTE: *reservations* do conflict with themselves;
855 // thus aren't injecting unsoundenss w/ this check.) 857 // thus aren't injecting unsoundenss w/ this check.)
856 (Activation(_, activating), _) if activating == index.borrow_index() => { 858 (Activation(_, activating), _) if activating == borrow_index => {
857 debug!( 859 debug!(
858 "check_access_for_conflict place_span: {:?} sd: {:?} rw: {:?} \ 860 "check_access_for_conflict place_span: {:?} sd: {:?} rw: {:?} \
859 skipping {:?} b/c activation of same borrow_index: {:?}", 861 skipping {:?} b/c activation of same borrow_index",
860 place_span, 862 place_span,
861 sd, 863 sd,
862 rw, 864 rw,
863 (index, borrow), 865 (borrow_index, borrow),
864 index.borrow_index()
865 ); 866 );
866 Control::Continue 867 Control::Continue
867 } 868 }
@@ -872,7 +873,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
872 873
873 (Read(kind), BorrowKind::Unique) | (Read(kind), BorrowKind::Mut { .. }) => { 874 (Read(kind), BorrowKind::Unique) | (Read(kind), BorrowKind::Mut { .. }) => {
874 // Reading from mere reservations of mutable-borrows is OK. 875 // Reading from mere reservations of mutable-borrows is OK.
875 if this.allow_two_phase_borrow(borrow.kind) && index.is_reservation() { 876 if this.allow_two_phase_borrow(borrow.kind) && !is_active.0 {
876 return Control::Continue; 877 return Control::Continue;
877 } 878 }
878 879
@@ -2216,10 +2217,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
2216 /// "Current borrow" here means a borrow that reaches the point in 2217 /// "Current borrow" here means a borrow that reaches the point in
2217 /// the control-flow where the access occurs. 2218 /// the control-flow where the access occurs.
2218 /// 2219 ///
2219 /// The borrow's phase is represented by the ReserveOrActivateIndex 2220 /// The borrow's phase is represented by the IsActive parameter
2220 /// passed to the callback: one can call `is_reservation()` and 2221 /// passed to the callback.
2221 /// `is_activation()` to determine what phase the borrow is
2222 /// currently in, when such distinction matters.
2223 fn each_borrow_involving_path<F>( 2222 fn each_borrow_involving_path<F>(
2224 &mut self, 2223 &mut self,
2225 _context: Context, 2224 _context: Context,
@@ -2227,7 +2226,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
2227 flow_state: &Flows<'cx, 'gcx, 'tcx>, 2226 flow_state: &Flows<'cx, 'gcx, 'tcx>,
2228 mut op: F, 2227 mut op: F,
2229 ) where 2228 ) where
2230 F: FnMut(&mut Self, ReserveOrActivateIndex, &BorrowData<'tcx>) -> Control, 2229 F: FnMut(&mut Self, BorrowIndex, IsActive, &BorrowData<'tcx>) -> Control,
2231 { 2230 {
2232 let (access, place) = access_place; 2231 let (access, place) = access_place;
2233 2232
@@ -2247,7 +2246,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
2247 "each_borrow_involving_path: {:?} @ {:?} vs. {:?}/{:?}", 2246 "each_borrow_involving_path: {:?} @ {:?} vs. {:?}/{:?}",
2248 i, borrowed, place, access 2247 i, borrowed, place, access
2249 ); 2248 );
2250 let ctrl = op(self, i, borrowed); 2249 let is_active = IsActive(i.is_activation());
2250 let ctrl = op(self, i.borrow_index(), is_active, borrowed);
2251 if ctrl == Control::Break { 2251 if ctrl == Control::Break {
2252 return; 2252 return;
2253 } 2253 }