@@ -21,6 +21,7 @@ use self::UseError::*;
21
21
use middle:: borrowck:: * ;
22
22
use middle:: expr_use_visitor as euv;
23
23
use middle:: mem_categorization as mc;
24
+ use middle:: region;
24
25
use middle:: ty;
25
26
use syntax:: ast;
26
27
use syntax:: codemap:: Span ;
@@ -134,7 +135,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {
134
135
None => { }
135
136
}
136
137
137
- self . check_for_conflicting_loans ( borrow_id) ;
138
+ self . check_for_conflicting_loans ( region :: CodeExtent :: from_node_id ( borrow_id) ) ;
138
139
}
139
140
140
141
fn mutate ( & mut self ,
@@ -215,30 +216,30 @@ fn compatible_borrow_kinds(borrow_kind1: ty::BorrowKind,
215
216
impl < ' a , ' tcx > CheckLoanCtxt < ' a , ' tcx > {
216
217
pub fn tcx ( & self ) -> & ' a ty:: ctxt < ' tcx > { self . bccx . tcx }
217
218
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)
219
220
-> bool {
220
221
//! 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
222
223
//! actually *in scope* at that point. Sometimes loans
223
224
//! are issued for future scopes and thus they may have been
224
225
//! *issued* but not yet be in effect.
225
226
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| {
227
228
let loan = & self . all_loans [ loan_index] ;
228
229
op ( loan)
229
230
} )
230
231
}
231
232
232
233
pub fn each_in_scope_loan ( & self ,
233
- scope_id : ast :: NodeId ,
234
+ scope : region :: CodeExtent ,
234
235
op: |& Loan | -> bool)
235
236
-> bool {
236
237
//! Like `each_issued_loan()`, but only considers loans that are
237
238
//! currently in scope.
238
239
239
240
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 ) {
242
243
op ( loan)
243
244
} else {
244
245
true
@@ -247,7 +248,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
247
248
}
248
249
249
250
fn each_in_scope_loan_affecting_path ( & self ,
250
- scope_id : ast :: NodeId ,
251
+ scope : region :: CodeExtent ,
251
252
loan_path : & LoanPath ,
252
253
op: |& Loan | -> bool)
253
254
-> bool {
@@ -262,7 +263,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
262
263
// let y = a; // Conflicts with restriction
263
264
264
265
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| {
266
267
let mut ret = true ;
267
268
for restr_path in loan. restricted_paths . iter ( ) {
268
269
if * * restr_path == * loan_path {
@@ -302,7 +303,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
302
303
}
303
304
}
304
305
305
- let cont = self . each_in_scope_loan ( scope_id , |loan| {
306
+ let cont = self . each_in_scope_loan ( scope , |loan| {
306
307
if * loan. loan_path == * loan_path {
307
308
op ( loan)
308
309
} else {
@@ -318,30 +319,33 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
318
319
return true ;
319
320
}
320
321
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 > {
322
323
//! Returns a vector of the loans that are generated as
323
- //! we encounter `scope_id `.
324
+ //! we enter `scope `.
324
325
325
326
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| {
327
328
result. push ( loan_index) ;
328
329
true
329
330
} ) ;
330
331
return result;
331
332
}
332
333
333
- pub fn check_for_conflicting_loans ( & self , scope_id : ast :: NodeId ) {
334
+ pub fn check_for_conflicting_loans ( & self , scope : region :: CodeExtent ) {
334
335
//! 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
337
338
//! permit two `&mut` borrows of the same variable).
339
+ //!
340
+ //! (Note that some loans can be *issued* without necessarily
341
+ //! taking effect yet.)
338
342
339
- debug ! ( "check_for_conflicting_loans(scope_id ={})" , scope_id ) ;
343
+ debug ! ( "check_for_conflicting_loans(scope ={})" , scope ) ;
340
344
341
- let new_loan_indices = self . loans_generated_by ( scope_id ) ;
345
+ let new_loan_indices = self . loans_generated_by ( scope ) ;
342
346
debug ! ( "new_loan_indices = {}" , new_loan_indices) ;
343
347
344
- self . each_issued_loan ( scope_id , |issued_loan| {
348
+ self . each_issued_loan ( scope , |issued_loan| {
345
349
for & new_loan_index in new_loan_indices. iter ( ) {
346
350
let new_loan = & self . all_loans [ new_loan_index] ;
347
351
self . report_error_if_loans_conflict ( issued_loan, new_loan) ;
@@ -535,7 +539,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
535
539
old_loan. span ,
536
540
format ! ( "{}; {}" , borrow_summary, rule_summary) . as_slice ( ) ) ;
537
541
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 ( ) ) ;
539
543
self . bccx . span_end_note ( old_loan_span,
540
544
"previous borrow ends here" ) ;
541
545
@@ -657,7 +661,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
657
661
658
662
let mut ret = UseOk ;
659
663
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| {
661
666
if !compatible_borrow_kinds ( loan. kind , borrow_kind) {
662
667
ret = UseWhileBorrowed ( loan. loan_path . clone ( ) , loan. span ) ;
663
668
false
@@ -924,7 +929,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
924
929
None => { return ; /* no loan path, can't be any loans */ }
925
930
} ;
926
931
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| {
928
934
this. report_illegal_mutation ( assignment_span, & * loan_path, loan) ;
929
935
false
930
936
} ) ;
0 commit comments