@@ -26,7 +26,6 @@ use middle::ty;
26
26
use util:: common:: indenter;
27
27
use util:: ppaux:: { Repr } ;
28
28
29
- use syntax:: ast:: { m_const, m_imm, m_mutbl} ;
30
29
use syntax:: ast;
31
30
use syntax:: ast_util:: id_range;
32
31
use syntax:: codemap:: span;
@@ -237,7 +236,11 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
237
236
// make sure that the thing we are pointing out stays valid
238
237
// for the lifetime `scope_r` of the resulting ptr:
239
238
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) ;
241
244
visit:: walk_expr ( v, ex, this) ;
242
245
}
243
246
@@ -278,7 +281,11 @@ fn gather_loans_in_expr(v: &mut GatherLoanVisitor,
278
281
// adjustments).
279
282
let scope_r = ty:: re_scope ( ex. id ) ;
280
283
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) ;
282
289
visit:: walk_expr ( v, ex, this) ;
283
290
}
284
291
@@ -357,26 +364,30 @@ impl GatherLoanCtxt {
357
364
358
365
match * autoref {
359
366
ty:: AutoPtr ( r, m) => {
367
+ let loan_mutability =
368
+ LoanMutability :: from_ast_mutability ( m) ;
360
369
self . guarantee_valid ( expr. id ,
361
370
expr. span ,
362
371
cmt,
363
- m ,
372
+ loan_mutability ,
364
373
r)
365
374
}
366
375
ty:: AutoBorrowVec ( r, m) | ty:: AutoBorrowVecRef ( r, m) => {
367
376
let cmt_index = mcx. cat_index ( expr, cmt, autoderefs+1 ) ;
377
+ let loan_mutability =
378
+ LoanMutability :: from_ast_mutability ( m) ;
368
379
self . guarantee_valid ( expr. id ,
369
380
expr. span ,
370
381
cmt_index,
371
- m ,
382
+ loan_mutability ,
372
383
r)
373
384
}
374
385
ty:: AutoBorrowFn ( r) => {
375
386
let cmt_deref = mcx. cat_deref_fn_or_obj ( expr, cmt, 0 ) ;
376
387
self . guarantee_valid ( expr. id ,
377
388
expr. span ,
378
389
cmt_deref,
379
- m_imm ,
390
+ ImmutableMutability ,
380
391
r)
381
392
}
382
393
ty:: AutoBorrowObj ( r, m) => {
@@ -402,7 +413,7 @@ impl GatherLoanCtxt {
402
413
borrow_id : ast:: NodeId ,
403
414
borrow_span : span ,
404
415
cmt : mc:: cmt ,
405
- req_mutbl : ast :: mutability ,
416
+ req_mutbl : LoanMutability ,
406
417
loan_region : ty:: Region ) {
407
418
debug ! ( "guarantee_valid(borrow_id=%?, cmt=%s, \
408
419
req_mutbl=%?, loan_region=%?)",
@@ -473,7 +484,7 @@ impl GatherLoanCtxt {
473
484
let kill_scope = self . compute_kill_scope ( loan_scope, loan_path) ;
474
485
debug ! ( "kill_scope = %?" , kill_scope) ;
475
486
476
- if req_mutbl == m_mutbl {
487
+ if req_mutbl == MutableMutability {
477
488
self . mark_loan_path_as_mutated ( loan_path) ;
478
489
}
479
490
@@ -516,7 +527,7 @@ impl GatherLoanCtxt {
516
527
// index: all_loans.len(),
517
528
// loan_path: loan_path,
518
529
// cmt: cmt,
519
- // mutbl: m_const ,
530
+ // mutbl: ConstMutability ,
520
531
// gen_scope: borrow_id,
521
532
// kill_scope: kill_scope,
522
533
// span: borrow_span,
@@ -527,29 +538,20 @@ impl GatherLoanCtxt {
527
538
fn check_mutability ( bccx : @BorrowckCtxt ,
528
539
borrow_span : span ,
529
540
cmt : mc:: cmt ,
530
- req_mutbl : ast :: mutability ) {
541
+ req_mutbl : LoanMutability ) {
531
542
//! Implements the M-* rules in doc.rs.
532
543
533
544
match req_mutbl {
534
- m_const => {
545
+ ConstMutability => {
535
546
// Data of any mutability can be lent as const.
536
547
}
537
548
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
550
552
}
551
553
552
- m_mutbl => {
554
+ MutableMutability => {
553
555
// Only mutable data can be lent as mutable.
554
556
if !cmt. mutbl . is_mutable ( ) {
555
557
bccx. report ( BckError { span : borrow_span,
@@ -561,12 +563,14 @@ impl GatherLoanCtxt {
561
563
}
562
564
}
563
565
564
- pub fn restriction_set ( & self , req_mutbl : ast :: mutability )
566
+ pub fn restriction_set ( & self , req_mutbl : LoanMutability )
565
567
-> RestrictionSet {
566
568
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
+ }
570
574
}
571
575
}
572
576
@@ -582,8 +586,8 @@ impl GatherLoanCtxt {
582
586
self . mark_loan_path_as_mutated ( base) ;
583
587
}
584
588
LpExtend ( _, mc:: McDeclared , _) |
585
- LpExtend ( _, mc:: McImmutable , _) |
586
- LpExtend ( _ , mc :: McReadOnly , _ ) => {
589
+ LpExtend ( _, mc:: McImmutable , _) => {
590
+ // Nothing to do.
587
591
}
588
592
}
589
593
}
@@ -701,8 +705,13 @@ impl GatherLoanCtxt {
701
705
}
702
706
}
703
707
} ;
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) ;
706
715
}
707
716
ast:: bind_infer => {
708
717
// No borrows here, but there may be moves
@@ -725,6 +734,8 @@ impl GatherLoanCtxt {
725
734
self . vec_slice_info ( slice_pat, slice_ty) ;
726
735
let mcx = self . bccx . mc_ctxt ( ) ;
727
736
let cmt_index = mcx. cat_index ( slice_pat, cmt, 0 ) ;
737
+ let slice_loan_mutability =
738
+ LoanMutability :: from_ast_mutability ( slice_mutbl) ;
728
739
729
740
// Note: We declare here that the borrow occurs upon
730
741
// entering the `[...]` pattern. This implies that
@@ -743,8 +754,11 @@ impl GatherLoanCtxt {
743
754
// trans do the right thing, and it would only work
744
755
// for `~` vectors. It seems simpler to just require
745
756
// 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) ;
748
762
}
749
763
750
764
_ => { }
0 commit comments