@@ -26,7 +26,6 @@ use middle::ty;
2626use util:: common:: indenter;
2727use util:: ppaux:: { Repr } ;
2828
29- use syntax:: ast:: { m_const, m_imm, m_mutbl} ;
3029use syntax:: ast;
3130use syntax:: ast_util:: id_range;
3231use syntax:: codemap:: span;
@@ -237,7 +236,11 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
237236 // make sure that the thing we are pointing out stays valid
238237 // for the lifetime `scope_r` of the resulting ptr:
239238 let scope_r = ty_region ( tcx, ex. span , ty:: expr_ty ( tcx, ex) ) ;
240- this. guarantee_valid ( ex. id , ex. span , base_cmt, mutbl, scope_r) ;
239+ this. guarantee_valid ( ex. id ,
240+ ex. span ,
241+ base_cmt,
242+ LoanMutability :: from_ast_mutability ( mutbl) ,
243+ scope_r) ;
241244 visit:: walk_expr ( v, ex, this) ;
242245 }
243246
@@ -278,7 +281,11 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
278281 // adjustments).
279282 let scope_r = ty:: re_scope ( ex. id ) ;
280283 let arg_cmt = this. bccx . cat_expr ( arg) ;
281- this. guarantee_valid ( arg. id , arg. span , arg_cmt, m_imm, scope_r) ;
284+ this. guarantee_valid ( arg. id ,
285+ arg. span ,
286+ arg_cmt,
287+ ImmutableMutability ,
288+ scope_r) ;
282289 visit:: walk_expr ( v, ex, this) ;
283290 }
284291
@@ -357,26 +364,30 @@ impl GatherLoanCtxt {
357364
358365 match * autoref {
359366 ty:: AutoPtr ( r, m) => {
367+ let loan_mutability =
368+ LoanMutability :: from_ast_mutability ( m) ;
360369 self . guarantee_valid ( expr. id ,
361370 expr. span ,
362371 cmt,
363- m ,
372+ loan_mutability ,
364373 r)
365374 }
366375 ty:: AutoBorrowVec ( r, m) | ty:: AutoBorrowVecRef ( r, m) => {
367376 let cmt_index = mcx. cat_index ( expr, cmt, autoderefs+1 ) ;
377+ let loan_mutability =
378+ LoanMutability :: from_ast_mutability ( m) ;
368379 self . guarantee_valid ( expr. id ,
369380 expr. span ,
370381 cmt_index,
371- m ,
382+ loan_mutability ,
372383 r)
373384 }
374385 ty:: AutoBorrowFn ( r) => {
375386 let cmt_deref = mcx. cat_deref_fn_or_obj ( expr, cmt, 0 ) ;
376387 self . guarantee_valid ( expr. id ,
377388 expr. span ,
378389 cmt_deref,
379- m_imm ,
390+ ImmutableMutability ,
380391 r)
381392 }
382393 ty:: AutoBorrowObj ( r, m) => {
@@ -402,7 +413,7 @@ impl GatherLoanCtxt {
402413 borrow_id : ast:: NodeId ,
403414 borrow_span : span ,
404415 cmt : mc:: cmt ,
405- req_mutbl : ast :: mutability ,
416+ req_mutbl : LoanMutability ,
406417 loan_region : ty:: Region ) {
407418 debug ! ( "guarantee_valid(borrow_id=%?, cmt=%s, \
408419 req_mutbl=%?, loan_region=%?)",
@@ -473,7 +484,7 @@ impl GatherLoanCtxt {
473484 let kill_scope = self . compute_kill_scope ( loan_scope, loan_path) ;
474485 debug ! ( "kill_scope = %?" , kill_scope) ;
475486
476- if req_mutbl == m_mutbl {
487+ if req_mutbl == MutableMutability {
477488 self . mark_loan_path_as_mutated ( loan_path) ;
478489 }
479490
@@ -516,7 +527,7 @@ impl GatherLoanCtxt {
516527 // index: all_loans.len(),
517528 // loan_path: loan_path,
518529 // cmt: cmt,
519- // mutbl: m_const ,
530+ // mutbl: ConstMutability ,
520531 // gen_scope: borrow_id,
521532 // kill_scope: kill_scope,
522533 // span: borrow_span,
@@ -527,29 +538,20 @@ impl GatherLoanCtxt {
527538 fn check_mutability ( bccx : @BorrowckCtxt ,
528539 borrow_span : span ,
529540 cmt : mc:: cmt ,
530- req_mutbl : ast :: mutability ) {
541+ req_mutbl : LoanMutability ) {
531542 //! Implements the M-* rules in doc.rs.
532543
533544 match req_mutbl {
534- m_const => {
545+ ConstMutability => {
535546 // Data of any mutability can be lent as const.
536547 }
537548
538- m_imm => {
539- match cmt. mutbl {
540- mc:: McImmutable | mc:: McDeclared | mc:: McInherited => {
541- // both imm and mut data can be lent as imm;
542- // for mutable data, this is a freeze
543- }
544- mc:: McReadOnly => {
545- bccx. report ( BckError { span : borrow_span,
546- cmt : cmt,
547- code : err_mutbl ( req_mutbl) } ) ;
548- }
549- }
549+ ImmutableMutability => {
550+ // both imm and mut data can be lent as imm;
551+ // for mutable data, this is a freeze
550552 }
551553
552- m_mutbl => {
554+ MutableMutability => {
553555 // Only mutable data can be lent as mutable.
554556 if !cmt. mutbl . is_mutable ( ) {
555557 bccx. report ( BckError { span : borrow_span,
@@ -561,12 +563,14 @@ impl GatherLoanCtxt {
561563 }
562564 }
563565
564- pub fn restriction_set ( & self , req_mutbl : ast :: mutability )
566+ pub fn restriction_set ( & self , req_mutbl : LoanMutability )
565567 -> RestrictionSet {
566568 match req_mutbl {
567- m_const => RESTR_EMPTY ,
568- m_imm => RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM ,
569- m_mutbl => RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM | RESTR_FREEZE
569+ ConstMutability => RESTR_EMPTY ,
570+ ImmutableMutability => RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM ,
571+ MutableMutability => {
572+ RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM | RESTR_FREEZE
573+ }
570574 }
571575 }
572576
@@ -582,8 +586,8 @@ impl GatherLoanCtxt {
582586 self . mark_loan_path_as_mutated ( base) ;
583587 }
584588 LpExtend ( _, mc:: McDeclared , _) |
585- LpExtend ( _, mc:: McImmutable , _) |
586- LpExtend ( _ , mc :: McReadOnly , _ ) => {
589+ LpExtend ( _, mc:: McImmutable , _) => {
590+ // Nothing to do.
587591 }
588592 }
589593 }
@@ -701,8 +705,13 @@ impl GatherLoanCtxt {
701705 }
702706 }
703707 } ;
704- self . guarantee_valid ( pat. id , pat. span ,
705- cmt_discr, mutbl, scope_r) ;
708+ let loan_mutability =
709+ LoanMutability :: from_ast_mutability ( mutbl) ;
710+ self . guarantee_valid ( pat. id ,
711+ pat. span ,
712+ cmt_discr,
713+ loan_mutability,
714+ scope_r) ;
706715 }
707716 ast:: bind_infer => {
708717 // No borrows here, but there may be moves
@@ -725,6 +734,8 @@ impl GatherLoanCtxt {
725734 self . vec_slice_info ( slice_pat, slice_ty) ;
726735 let mcx = self . bccx . mc_ctxt ( ) ;
727736 let cmt_index = mcx. cat_index ( slice_pat, cmt, 0 ) ;
737+ let slice_loan_mutability =
738+ LoanMutability :: from_ast_mutability ( slice_mutbl) ;
728739
729740 // Note: We declare here that the borrow occurs upon
730741 // entering the `[...]` pattern. This implies that
@@ -743,8 +754,11 @@ impl GatherLoanCtxt {
743754 // trans do the right thing, and it would only work
744755 // for `~` vectors. It seems simpler to just require
745756 // that people call `vec.pop()` or `vec.unshift()`.
746- self . guarantee_valid ( pat. id , pat. span ,
747- cmt_index, slice_mutbl, slice_r) ;
757+ self . guarantee_valid ( pat. id ,
758+ pat. span ,
759+ cmt_index,
760+ slice_loan_mutability,
761+ slice_r) ;
748762 }
749763
750764 _ => { }
0 commit comments