19
19
use self :: UseError :: * ;
20
20
21
21
use middle:: borrowck:: * ;
22
+ use middle:: borrowck:: LoanPathElem :: * ;
23
+ use middle:: borrowck:: LoanPathKind :: * ;
22
24
use middle:: expr_use_visitor as euv;
23
25
use middle:: mem_categorization as mc;
24
26
use middle:: region;
@@ -33,51 +35,51 @@ use std::rc::Rc;
33
35
// be less precise in its handling of Box while still allowing moves out of a
34
36
// Box. They should be removed when OwnedPtr is removed from LoanPath.
35
37
36
- fn owned_ptr_base_path < ' a > ( loan_path : & ' a LoanPath ) -> & ' a LoanPath {
38
+ fn owned_ptr_base_path < ' a , ' tcx > ( loan_path : & ' a LoanPath < ' tcx > ) -> & ' a LoanPath < ' tcx > {
37
39
//! Returns the base of the leftmost dereference of an OwnedPtr in
38
40
//! `loan_path`. If there is no dereference of an OwnedPtr in `loan_path`,
39
41
//! then it just returns `loan_path` itself.
40
42
41
- return match owned_ptr_base_path_helper ( loan_path) {
43
+ return match helper ( loan_path) {
42
44
Some ( new_loan_path) => new_loan_path,
43
45
None => loan_path. clone ( )
44
46
} ;
45
47
46
- fn owned_ptr_base_path_helper < ' a > ( loan_path : & ' a LoanPath ) -> Option < & ' a LoanPath > {
47
- match * loan_path {
48
+ fn helper < ' a , ' tcx > ( loan_path : & ' a LoanPath < ' tcx > ) -> Option < & ' a LoanPath < ' tcx > > {
49
+ match loan_path. kind {
48
50
LpVar ( _) | LpUpvar ( _) => None ,
49
51
LpExtend ( ref lp_base, _, LpDeref ( mc:: OwnedPtr ) ) => {
50
- match owned_ptr_base_path_helper ( & * * lp_base) {
52
+ match helper ( & * * lp_base) {
51
53
v @ Some ( _) => v,
52
54
None => Some ( & * * lp_base)
53
55
}
54
56
}
55
57
LpDowncast ( ref lp_base, _) |
56
- LpExtend ( ref lp_base, _, _) => owned_ptr_base_path_helper ( & * * lp_base)
58
+ LpExtend ( ref lp_base, _, _) => helper ( & * * lp_base)
57
59
}
58
60
}
59
61
}
60
62
61
- fn owned_ptr_base_path_rc ( loan_path : & Rc < LoanPath > ) -> Rc < LoanPath > {
63
+ fn owned_ptr_base_path_rc < ' tcx > ( loan_path : & Rc < LoanPath < ' tcx > > ) -> Rc < LoanPath < ' tcx > > {
62
64
//! The equivalent of `owned_ptr_base_path` for an &Rc<LoanPath> rather than
63
65
//! a &LoanPath.
64
66
65
- return match owned_ptr_base_path_helper ( loan_path) {
67
+ return match helper ( loan_path) {
66
68
Some ( new_loan_path) => new_loan_path,
67
69
None => loan_path. clone ( )
68
70
} ;
69
71
70
- fn owned_ptr_base_path_helper ( loan_path : & Rc < LoanPath > ) -> Option < Rc < LoanPath > > {
71
- match * * loan_path {
72
+ fn helper < ' tcx > ( loan_path : & Rc < LoanPath < ' tcx > > ) -> Option < Rc < LoanPath < ' tcx > > > {
73
+ match loan_path. kind {
72
74
LpVar ( _) | LpUpvar ( _) => None ,
73
75
LpExtend ( ref lp_base, _, LpDeref ( mc:: OwnedPtr ) ) => {
74
- match owned_ptr_base_path_helper ( lp_base) {
76
+ match helper ( lp_base) {
75
77
v @ Some ( _) => v,
76
78
None => Some ( lp_base. clone ( ) )
77
79
}
78
80
}
79
81
LpDowncast ( ref lp_base, _) |
80
- LpExtend ( ref lp_base, _, _) => owned_ptr_base_path_helper ( lp_base)
82
+ LpExtend ( ref lp_base, _, _) => helper ( lp_base)
81
83
}
82
84
}
83
85
}
@@ -86,7 +88,7 @@ struct CheckLoanCtxt<'a, 'tcx: 'a> {
86
88
bccx : & ' a BorrowckCtxt < ' a , ' tcx > ,
87
89
dfcx_loans : & ' a LoanDataFlow < ' a , ' tcx > ,
88
90
move_data : move_data:: FlowedMoveData < ' a , ' tcx > ,
89
- all_loans : & ' a [ Loan ] ,
91
+ all_loans : & ' a [ Loan < ' tcx > ] ,
90
92
}
91
93
92
94
impl < ' a , ' tcx > euv:: Delegate < ' tcx > for CheckLoanCtxt < ' a , ' tcx > {
@@ -185,7 +187,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {
185
187
pub fn check_loans < ' a , ' b , ' c , ' tcx > ( bccx : & BorrowckCtxt < ' a , ' tcx > ,
186
188
dfcx_loans : & LoanDataFlow < ' b , ' tcx > ,
187
189
move_data : move_data:: FlowedMoveData < ' c , ' tcx > ,
188
- all_loans : & [ Loan ] ,
190
+ all_loans : & [ Loan < ' tcx > ] ,
189
191
decl : & ast:: FnDecl ,
190
192
body : & ast:: Block ) {
191
193
debug ! ( "check_loans(body id={})" , body. id) ;
@@ -204,9 +206,9 @@ pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
204
206
}
205
207
206
208
#[ deriving( PartialEq ) ]
207
- enum UseError {
209
+ enum UseError < ' tcx > {
208
210
UseOk ,
209
- UseWhileBorrowed ( /*loan*/ Rc < LoanPath > , /*loan*/ Span )
211
+ UseWhileBorrowed ( /*loan*/ Rc < LoanPath < ' tcx > > , /*loan*/ Span )
210
212
}
211
213
212
214
fn compatible_borrow_kinds ( borrow_kind1 : ty:: BorrowKind ,
@@ -218,7 +220,7 @@ fn compatible_borrow_kinds(borrow_kind1: ty::BorrowKind,
218
220
impl < ' a , ' tcx > CheckLoanCtxt < ' a , ' tcx > {
219
221
pub fn tcx ( & self ) -> & ' a ty:: ctxt < ' tcx > { self . bccx . tcx }
220
222
221
- pub fn each_issued_loan ( & self , scope : region:: CodeExtent , op: |& Loan | -> bool)
223
+ pub fn each_issued_loan ( & self , scope : region:: CodeExtent , op: |& Loan < ' tcx > | -> bool )
222
224
-> bool {
223
225
//! Iterates over each loan that has been issued
224
226
//! on entrance to `scope`, regardless of whether it is
@@ -234,7 +236,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
234
236
235
237
pub fn each_in_scope_loan ( & self ,
236
238
scope : region:: CodeExtent ,
237
- op: |& Loan | -> bool)
239
+ op: |& Loan < ' tcx > | -> bool )
238
240
-> bool {
239
241
//! Like `each_issued_loan()`, but only considers loans that are
240
242
//! currently in scope.
@@ -251,8 +253,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
251
253
252
254
fn each_in_scope_loan_affecting_path ( & self ,
253
255
scope : region:: CodeExtent ,
254
- loan_path : & LoanPath ,
255
- op: |& Loan | -> bool)
256
+ loan_path : & LoanPath < ' tcx > ,
257
+ op: |& Loan < ' tcx > | -> bool )
256
258
-> bool {
257
259
//! Iterates through all of the in-scope loans affecting `loan_path`,
258
260
//! calling `op`, and ceasing iteration if `false` is returned.
@@ -296,7 +298,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
296
298
297
299
let mut loan_path = loan_path;
298
300
loop {
299
- match * loan_path {
301
+ match loan_path. kind {
300
302
LpVar ( _) | LpUpvar ( _) => {
301
303
break ;
302
304
}
@@ -366,8 +368,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
366
368
}
367
369
368
370
pub fn report_error_if_loans_conflict ( & self ,
369
- old_loan : & Loan ,
370
- new_loan : & Loan ) {
371
+ old_loan : & Loan < ' tcx > ,
372
+ new_loan : & Loan < ' tcx > ) {
371
373
//! Checks whether `old_loan` and `new_loan` can safely be issued
372
374
//! simultaneously.
373
375
@@ -386,10 +388,10 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
386
388
}
387
389
388
390
pub fn report_error_if_loan_conflicts_with_restriction ( & self ,
389
- loan1 : & Loan ,
390
- loan2 : & Loan ,
391
- old_loan : & Loan ,
392
- new_loan : & Loan )
391
+ loan1 : & Loan < ' tcx > ,
392
+ loan2 : & Loan < ' tcx > ,
393
+ old_loan : & Loan < ' tcx > ,
394
+ new_loan : & Loan < ' tcx > )
393
395
-> bool {
394
396
//! Checks whether the restrictions introduced by `loan1` would
395
397
//! prohibit `loan2`. Returns false if an error is reported.
@@ -552,7 +554,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
552
554
true
553
555
}
554
556
555
- fn is_local_variable_or_arg ( & self , cmt : mc:: cmt ) -> bool {
557
+ fn is_local_variable_or_arg ( & self , cmt : mc:: cmt < ' tcx > ) -> bool {
556
558
match cmt. cat {
557
559
mc:: cat_local( _) => true ,
558
560
_ => false
@@ -562,7 +564,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
562
564
fn consume_common ( & self ,
563
565
id : ast:: NodeId ,
564
566
span : Span ,
565
- cmt : mc:: cmt ,
567
+ cmt : mc:: cmt < ' tcx > ,
566
568
mode : euv:: ConsumeMode ) {
567
569
match opt_loan_path ( & cmt) {
568
570
Some ( lp) => {
@@ -603,7 +605,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
603
605
fn check_for_copy_of_frozen_path ( & self ,
604
606
id : ast:: NodeId ,
605
607
span : Span ,
606
- copy_path : & LoanPath ) {
608
+ copy_path : & LoanPath < ' tcx > ) {
607
609
match self . analyze_restrictions_on_use ( id, copy_path, ty:: ImmBorrow ) {
608
610
UseOk => { }
609
611
UseWhileBorrowed ( loan_path, loan_span) => {
@@ -624,7 +626,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
624
626
fn check_for_move_of_borrowed_path ( & self ,
625
627
id : ast:: NodeId ,
626
628
span : Span ,
627
- move_path : & LoanPath ,
629
+ move_path : & LoanPath < ' tcx > ,
628
630
move_kind : move_data:: MoveKind ) {
629
631
// We want to detect if there are any loans at all, so we search for
630
632
// any loans incompatible with MutBorrrow, since all other kinds of
@@ -655,9 +657,9 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
655
657
656
658
pub fn analyze_restrictions_on_use ( & self ,
657
659
expr_id : ast:: NodeId ,
658
- use_path : & LoanPath ,
660
+ use_path : & LoanPath < ' tcx > ,
659
661
borrow_kind : ty:: BorrowKind )
660
- -> UseError {
662
+ -> UseError < ' tcx > {
661
663
debug ! ( "analyze_restrictions_on_use(expr_id={}, use_path={})" ,
662
664
self . tcx( ) . map. node_to_string( expr_id) ,
663
665
use_path. repr( self . tcx( ) ) ) ;
@@ -681,7 +683,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
681
683
id : ast:: NodeId ,
682
684
span : Span ,
683
685
use_kind : MovedValueUseKind ,
684
- lp : & Rc < LoanPath > ) {
686
+ lp : & Rc < LoanPath < ' tcx > > ) {
685
687
/*!
686
688
* Reports an error if `expr` (which should be a path)
687
689
* is using a moved/uninitialized value
@@ -705,7 +707,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
705
707
id : ast:: NodeId ,
706
708
span : Span ,
707
709
use_kind : MovedValueUseKind ,
708
- lp : & Rc < LoanPath > )
710
+ lp : & Rc < LoanPath < ' tcx > > )
709
711
{
710
712
/*!
711
713
* Reports an error if assigning to `lp` will use a
@@ -725,7 +727,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
725
727
* (*p).x = 22; // not ok, p is uninitialized, can't deref
726
728
*/
727
729
728
- match * * lp {
730
+ match lp . kind {
729
731
LpVar ( _) | LpUpvar ( _) => {
730
732
// assigning to `x` does not require that `x` is initialized
731
733
}
@@ -923,11 +925,11 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
923
925
}
924
926
}
925
927
926
- fn check_for_assignment_to_borrowed_path (
927
- this : & CheckLoanCtxt ,
928
+ fn check_for_assignment_to_borrowed_path < ' a , ' tcx > (
929
+ this : & CheckLoanCtxt < ' a , ' tcx > ,
928
930
assignment_id : ast:: NodeId ,
929
931
assignment_span : Span ,
930
- assignee_cmt : mc:: cmt )
932
+ assignee_cmt : mc:: cmt < ' tcx > )
931
933
{
932
934
//! Check for assignments that violate the terms of an
933
935
//! outstanding loan.
@@ -947,7 +949,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
947
949
948
950
pub fn report_illegal_mutation ( & self ,
949
951
span : Span ,
950
- loan_path : & LoanPath ,
952
+ loan_path : & LoanPath < ' tcx > ,
951
953
loan : & Loan ) {
952
954
self . bccx . span_err (
953
955
span,
0 commit comments