@@ -24,8 +24,10 @@ use middle::moves;
24
24
use middle:: ty;
25
25
use syntax:: ast:: { MutImmutable , MutMutable } ;
26
26
use syntax:: ast;
27
+ use syntax:: ast_map;
27
28
use syntax:: ast_util;
28
29
use syntax:: codemap:: Span ;
30
+ use syntax:: parse:: token;
29
31
use syntax:: visit:: Visitor ;
30
32
use syntax:: visit;
31
33
use util:: ppaux:: Repr ;
@@ -77,6 +79,7 @@ pub fn check_loans(bccx: &BorrowckCtxt,
77
79
clcx. visit_block ( body, ( ) ) ;
78
80
}
79
81
82
+ #[ deriving( Eq ) ]
80
83
enum MoveError {
81
84
MoveOk ,
82
85
MoveWhileBorrowed ( /*loan*/ @LoanPath , /*loan*/ Span )
@@ -125,6 +128,9 @@ impl<'a> CheckLoanCtxt<'a> {
125
128
//! given `loan_path`
126
129
127
130
self . each_in_scope_loan ( scope_id, |loan| {
131
+ debug ! ( "each_in_scope_restriction found loan: {:?}" ,
132
+ loan. repr( self . tcx( ) ) ) ;
133
+
128
134
let mut ret = true ;
129
135
for restr in loan. restrictions . iter ( ) {
130
136
if restr. loan_path == loan_path {
@@ -647,22 +653,34 @@ impl<'a> CheckLoanCtxt<'a> {
647
653
648
654
pub fn analyze_move_out_from ( & self ,
649
655
expr_id : ast:: NodeId ,
650
- move_path : @LoanPath ) -> MoveError {
656
+ mut move_path : @LoanPath )
657
+ -> MoveError {
651
658
debug ! ( "analyze_move_out_from(expr_id={:?}, move_path={})" ,
652
- expr_id, move_path. repr( self . tcx( ) ) ) ;
653
-
654
- // FIXME(#4384) inadequare if/when we permit `move a.b`
655
-
656
- let mut ret = MoveOk ;
659
+ ast_map:: node_id_to_str( self . tcx( ) . items,
660
+ expr_id,
661
+ token:: get_ident_interner( ) ) ,
662
+ move_path. repr( self . tcx( ) ) ) ;
663
+
664
+ // We must check every element of a move path. See
665
+ // `borrowck-move-subcomponent.rs` for a test case.
666
+ loop {
667
+ // check for a conflicting loan:
668
+ let mut ret = MoveOk ;
669
+ self . each_in_scope_restriction ( expr_id, move_path, |loan, _| {
670
+ // Any restriction prevents moves.
671
+ ret = MoveWhileBorrowed ( loan. loan_path , loan. span ) ;
672
+ false
673
+ } ) ;
657
674
658
- // check for a conflicting loan:
659
- self . each_in_scope_restriction ( expr_id, move_path, |loan, _| {
660
- // Any restriction prevents moves.
661
- ret = MoveWhileBorrowed ( loan. loan_path , loan. span ) ;
662
- false
663
- } ) ;
675
+ if ret != MoveOk {
676
+ return ret
677
+ }
664
678
665
- ret
679
+ match * move_path {
680
+ LpVar ( _) => return MoveOk ,
681
+ LpExtend ( subpath, _, _) => move_path = subpath,
682
+ }
683
+ }
666
684
}
667
685
668
686
pub fn check_call ( & self ,
0 commit comments