@@ -21,6 +21,7 @@ use self::UseError::*;
2121use middle:: borrowck:: * ;
2222use middle:: expr_use_visitor as euv;
2323use middle:: mem_categorization as mc;
24+ use middle:: region;
2425use middle:: ty;
2526use syntax:: ast;
2627use syntax:: codemap:: Span ;
@@ -134,7 +135,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {
134135 None => { }
135136 }
136137
137- self . check_for_conflicting_loans ( borrow_id) ;
138+ self . check_for_conflicting_loans ( region :: CodeExtent :: from_node_id ( borrow_id) ) ;
138139 }
139140
140141 fn mutate ( & mut self ,
@@ -215,30 +216,30 @@ fn compatible_borrow_kinds(borrow_kind1: ty::BorrowKind,
215216impl < ' a , ' tcx > CheckLoanCtxt < ' a , ' tcx > {
216217 pub fn tcx ( & self ) -> & ' a ty:: ctxt < ' tcx > { self . bccx . tcx }
217218
218- pub fn each_issued_loan ( & self , scope_id : ast :: NodeId , op: |& Loan | -> bool)
219+ pub fn each_issued_loan ( & self , scope : region :: CodeExtent , op: |& Loan | -> bool)
219220 -> bool {
220221 //! Iterates over each loan that has been issued
221- //! on entrance to `scope_id `, regardless of whether it is
222+ //! on entrance to `scope `, regardless of whether it is
222223 //! actually *in scope* at that point. Sometimes loans
223224 //! are issued for future scopes and thus they may have been
224225 //! *issued* but not yet be in effect.
225226
226- self . dfcx_loans . each_bit_on_entry ( scope_id , |loan_index| {
227+ self . dfcx_loans . each_bit_on_entry ( scope . node_id ( ) , |loan_index| {
227228 let loan = & self . all_loans [ loan_index] ;
228229 op ( loan)
229230 } )
230231 }
231232
232233 pub fn each_in_scope_loan ( & self ,
233- scope_id : ast :: NodeId ,
234+ scope : region :: CodeExtent ,
234235 op: |& Loan | -> bool)
235236 -> bool {
236237 //! Like `each_issued_loan()`, but only considers loans that are
237238 //! currently in scope.
238239
239240 let tcx = self . tcx ( ) ;
240- self . each_issued_loan ( scope_id , |loan| {
241- if tcx. region_maps . is_subscope_of ( scope_id , loan. kill_scope ) {
241+ self . each_issued_loan ( scope , |loan| {
242+ if tcx. region_maps . is_subscope_of ( scope , loan. kill_scope ) {
242243 op ( loan)
243244 } else {
244245 true
@@ -247,7 +248,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
247248 }
248249
249250 fn each_in_scope_loan_affecting_path ( & self ,
250- scope_id : ast :: NodeId ,
251+ scope : region :: CodeExtent ,
251252 loan_path : & LoanPath ,
252253 op: |& Loan | -> bool)
253254 -> bool {
@@ -262,7 +263,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
262263 // let y = a; // Conflicts with restriction
263264
264265 let loan_path = owned_ptr_base_path ( loan_path) ;
265- let cont = self . each_in_scope_loan ( scope_id , |loan| {
266+ let cont = self . each_in_scope_loan ( scope , |loan| {
266267 let mut ret = true ;
267268 for restr_path in loan. restricted_paths . iter ( ) {
268269 if * * restr_path == * loan_path {
@@ -302,7 +303,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
302303 }
303304 }
304305
305- let cont = self . each_in_scope_loan ( scope_id , |loan| {
306+ let cont = self . each_in_scope_loan ( scope , |loan| {
306307 if * loan. loan_path == * loan_path {
307308 op ( loan)
308309 } else {
@@ -318,30 +319,33 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
318319 return true ;
319320 }
320321
321- pub fn loans_generated_by ( & self , scope_id : ast :: NodeId ) -> Vec < uint > {
322+ pub fn loans_generated_by ( & self , scope : region :: CodeExtent ) -> Vec < uint > {
322323 //! Returns a vector of the loans that are generated as
323- //! we encounter `scope_id `.
324+ //! we enter `scope `.
324325
325326 let mut result = Vec :: new ( ) ;
326- self . dfcx_loans . each_gen_bit ( scope_id , |loan_index| {
327+ self . dfcx_loans . each_gen_bit ( scope . node_id ( ) , |loan_index| {
327328 result. push ( loan_index) ;
328329 true
329330 } ) ;
330331 return result;
331332 }
332333
333- pub fn check_for_conflicting_loans ( & self , scope_id : ast :: NodeId ) {
334+ pub fn check_for_conflicting_loans ( & self , scope : region :: CodeExtent ) {
334335 //! Checks to see whether any of the loans that are issued
335- //! by `scope_id ` conflict with loans that have already been
336- //! issued when we enter `scope_id ` (for example, we do not
336+ //! on entrance to `scope ` conflict with loans that have already been
337+ //! issued when we enter `scope ` (for example, we do not
337338 //! permit two `&mut` borrows of the same variable).
339+ //!
340+ //! (Note that some loans can be *issued* without necessarily
341+ //! taking effect yet.)
338342
339- debug ! ( "check_for_conflicting_loans(scope_id ={})" , scope_id ) ;
343+ debug ! ( "check_for_conflicting_loans(scope ={})" , scope ) ;
340344
341- let new_loan_indices = self . loans_generated_by ( scope_id ) ;
345+ let new_loan_indices = self . loans_generated_by ( scope ) ;
342346 debug ! ( "new_loan_indices = {}" , new_loan_indices) ;
343347
344- self . each_issued_loan ( scope_id , |issued_loan| {
348+ self . each_issued_loan ( scope , |issued_loan| {
345349 for & new_loan_index in new_loan_indices. iter ( ) {
346350 let new_loan = & self . all_loans [ new_loan_index] ;
347351 self . report_error_if_loans_conflict ( issued_loan, new_loan) ;
@@ -535,7 +539,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
535539 old_loan. span ,
536540 format ! ( "{}; {}" , borrow_summary, rule_summary) . as_slice ( ) ) ;
537541
538- let old_loan_span = self . tcx ( ) . map . span ( old_loan. kill_scope ) ;
542+ let old_loan_span = self . tcx ( ) . map . span ( old_loan. kill_scope . node_id ( ) ) ;
539543 self . bccx . span_end_note ( old_loan_span,
540544 "previous borrow ends here" ) ;
541545
@@ -657,7 +661,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
657661
658662 let mut ret = UseOk ;
659663
660- self . each_in_scope_loan_affecting_path ( expr_id, use_path, |loan| {
664+ self . each_in_scope_loan_affecting_path (
665+ region:: CodeExtent :: from_node_id ( expr_id) , use_path, |loan| {
661666 if !compatible_borrow_kinds ( loan. kind , borrow_kind) {
662667 ret = UseWhileBorrowed ( loan. loan_path . clone ( ) , loan. span ) ;
663668 false
@@ -924,7 +929,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
924929 None => { return ; /* no loan path, can't be any loans */ }
925930 } ;
926931
927- this. each_in_scope_loan_affecting_path ( assignment_id, & * loan_path, |loan| {
932+ let scope = region:: CodeExtent :: from_node_id ( assignment_id) ;
933+ this. each_in_scope_loan_affecting_path ( scope, & * loan_path, |loan| {
928934 this. report_illegal_mutation ( assignment_span, & * loan_path, loan) ;
929935 false
930936 } ) ;
0 commit comments