@@ -28,6 +28,7 @@ use ty::{self, TyCtxt, adjustment};
28
28
29
29
use hir:: { self , PatKind } ;
30
30
use rustc_data_structures:: sync:: Lrc ;
31
+ use std:: rc:: Rc ;
31
32
use syntax:: ast;
32
33
use syntax:: ptr:: P ;
33
34
use syntax_pos:: Span ;
@@ -44,7 +45,7 @@ pub trait Delegate<'tcx> {
44
45
fn consume ( & mut self ,
45
46
consume_id : ast:: NodeId ,
46
47
consume_span : Span ,
47
- cmt : mc:: cmt < ' tcx > ,
48
+ cmt : & mc:: cmt_ < ' tcx > ,
48
49
mode : ConsumeMode ) ;
49
50
50
51
// The value found at `cmt` has been determined to match the
@@ -61,22 +62,22 @@ pub trait Delegate<'tcx> {
61
62
// called on a subpart of an input passed to `matched_pat).
62
63
fn matched_pat ( & mut self ,
63
64
matched_pat : & hir:: Pat ,
64
- cmt : mc:: cmt < ' tcx > ,
65
+ cmt : & mc:: cmt_ < ' tcx > ,
65
66
mode : MatchMode ) ;
66
67
67
68
// The value found at `cmt` is either copied or moved via the
68
69
// pattern binding `consume_pat`, depending on mode.
69
70
fn consume_pat ( & mut self ,
70
71
consume_pat : & hir:: Pat ,
71
- cmt : mc:: cmt < ' tcx > ,
72
+ cmt : & mc:: cmt_ < ' tcx > ,
72
73
mode : ConsumeMode ) ;
73
74
74
75
// The value found at `borrow` is being borrowed at the point
75
76
// `borrow_id` for the region `loan_region` with kind `bk`.
76
77
fn borrow ( & mut self ,
77
78
borrow_id : ast:: NodeId ,
78
79
borrow_span : Span ,
79
- cmt : mc:: cmt < ' tcx > ,
80
+ cmt : & mc:: cmt_ < ' tcx > ,
80
81
loan_region : ty:: Region < ' tcx > ,
81
82
bk : ty:: BorrowKind ,
82
83
loan_cause : LoanCause ) ;
@@ -90,7 +91,7 @@ pub trait Delegate<'tcx> {
90
91
fn mutate ( & mut self ,
91
92
assignment_id : ast:: NodeId ,
92
93
assignment_span : Span ,
93
- assignee_cmt : mc:: cmt < ' tcx > ,
94
+ assignee_cmt : & mc:: cmt_ < ' tcx > ,
94
95
mode : MutateMode ) ;
95
96
}
96
97
@@ -316,11 +317,11 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
316
317
317
318
let fn_body_scope_r =
318
319
self . tcx ( ) . mk_region ( ty:: ReScope ( region:: Scope :: Node ( body. value . hir_id . local_id ) ) ) ;
319
- let arg_cmt = self . mc . cat_rvalue (
320
+ let arg_cmt = Rc :: new ( self . mc . cat_rvalue (
320
321
arg. id ,
321
322
arg. pat . span ,
322
323
fn_body_scope_r, // Args live only as long as the fn body.
323
- arg_ty) ;
324
+ arg_ty) ) ;
324
325
325
326
self . walk_irrefutable_pat ( arg_cmt, & arg. pat ) ;
326
327
}
@@ -335,11 +336,11 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
335
336
fn delegate_consume ( & mut self ,
336
337
consume_id : ast:: NodeId ,
337
338
consume_span : Span ,
338
- cmt : mc:: cmt < ' tcx > ) {
339
+ cmt : & mc:: cmt_ < ' tcx > ) {
339
340
debug ! ( "delegate_consume(consume_id={}, cmt={:?})" ,
340
341
consume_id, cmt) ;
341
342
342
- let mode = copy_or_move ( & self . mc , self . param_env , & cmt, DirectRefMove ) ;
343
+ let mode = copy_or_move ( & self . mc , self . param_env , cmt, DirectRefMove ) ;
343
344
self . delegate . consume ( consume_id, consume_span, cmt, mode) ;
344
345
}
345
346
@@ -353,7 +354,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
353
354
debug ! ( "consume_expr(expr={:?})" , expr) ;
354
355
355
356
let cmt = return_if_err ! ( self . mc. cat_expr( expr) ) ;
356
- self . delegate_consume ( expr. id , expr. span , cmt) ;
357
+ self . delegate_consume ( expr. id , expr. span , & cmt) ;
357
358
self . walk_expr ( expr) ;
358
359
}
359
360
@@ -362,7 +363,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
362
363
expr : & hir:: Expr ,
363
364
mode : MutateMode ) {
364
365
let cmt = return_if_err ! ( self . mc. cat_expr( expr) ) ;
365
- self . delegate . mutate ( assignment_expr. id , assignment_expr. span , cmt, mode) ;
366
+ self . delegate . mutate ( assignment_expr. id , assignment_expr. span , & cmt, mode) ;
366
367
self . walk_expr ( expr) ;
367
368
}
368
369
@@ -375,7 +376,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
375
376
expr, r, bk) ;
376
377
377
378
let cmt = return_if_err ! ( self . mc. cat_expr( expr) ) ;
378
- self . delegate . borrow ( expr. id , expr. span , cmt, r, bk, cause) ;
379
+ self . delegate . borrow ( expr. id , expr. span , & cmt, r, bk, cause) ;
379
380
380
381
self . walk_expr ( expr)
381
382
}
@@ -435,7 +436,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
435
436
}
436
437
437
438
hir:: ExprMatch ( ref discr, ref arms, _) => {
438
- let discr_cmt = return_if_err ! ( self . mc. cat_expr( & discr) ) ;
439
+ let discr_cmt = Rc :: new ( return_if_err ! ( self . mc. cat_expr( & discr) ) ) ;
439
440
let r = self . tcx ( ) . types . re_empty ;
440
441
self . borrow_expr ( & discr, r, ty:: ImmBorrow , MatchDiscriminant ) ;
441
442
@@ -619,7 +620,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
619
620
// "assigns", which is handled by
620
621
// `walk_pat`:
621
622
self . walk_expr ( & expr) ;
622
- let init_cmt = return_if_err ! ( self . mc. cat_expr( & expr) ) ;
623
+ let init_cmt = Rc :: new ( return_if_err ! ( self . mc. cat_expr( & expr) ) ) ;
623
624
self . walk_irrefutable_pat ( init_cmt, & local. pat ) ;
624
625
}
625
626
}
@@ -652,7 +653,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
652
653
None => { return ; }
653
654
} ;
654
655
655
- let with_cmt = return_if_err ! ( self . mc. cat_expr( & with_expr) ) ;
656
+ let with_cmt = Rc :: new ( return_if_err ! ( self . mc. cat_expr( & with_expr) ) ) ;
656
657
657
658
// Select just those fields of the `with`
658
659
// expression that will actually be used
@@ -671,7 +672,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
671
672
with_field. name ,
672
673
with_field. ty ( self . tcx ( ) , substs)
673
674
) ;
674
- self . delegate_consume ( with_expr. id , with_expr. span , cmt_field) ;
675
+ self . delegate_consume ( with_expr. id , with_expr. span , & cmt_field) ;
675
676
}
676
677
}
677
678
}
@@ -710,7 +711,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
710
711
adjustment:: Adjust :: Unsize => {
711
712
// Creating a closure/fn-pointer or unsizing consumes
712
713
// the input and stores it into the resulting rvalue.
713
- self . delegate_consume ( expr. id , expr. span , cmt. clone ( ) ) ;
714
+ self . delegate_consume ( expr. id , expr. span , & cmt) ;
714
715
}
715
716
716
717
adjustment:: Adjust :: Deref ( None ) => { }
@@ -722,12 +723,11 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
722
723
// this is an autoref of `x`.
723
724
adjustment:: Adjust :: Deref ( Some ( ref deref) ) => {
724
725
let bk = ty:: BorrowKind :: from_mutbl ( deref. mutbl ) ;
725
- self . delegate . borrow ( expr. id , expr. span , cmt. clone ( ) ,
726
- deref. region , bk, AutoRef ) ;
726
+ self . delegate . borrow ( expr. id , expr. span , & cmt, deref. region , bk, AutoRef ) ;
727
727
}
728
728
729
729
adjustment:: Adjust :: Borrow ( ref autoref) => {
730
- self . walk_autoref ( expr, cmt. clone ( ) , autoref) ;
730
+ self . walk_autoref ( expr, & cmt, autoref) ;
731
731
}
732
732
}
733
733
cmt = return_if_err ! ( self . mc. cat_expr_adjusted( expr, cmt, & adjustment) ) ;
@@ -739,7 +739,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
739
739
/// after all relevant autoderefs have occurred.
740
740
fn walk_autoref ( & mut self ,
741
741
expr : & hir:: Expr ,
742
- cmt_base : mc:: cmt < ' tcx > ,
742
+ cmt_base : & mc:: cmt_ < ' tcx > ,
743
743
autoref : & adjustment:: AutoBorrow < ' tcx > ) {
744
744
debug ! ( "walk_autoref(expr.id={} cmt_base={:?} autoref={:?})" ,
745
745
expr. id,
@@ -852,7 +852,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
852
852
// Each match binding is effectively an assignment to the
853
853
// binding being produced.
854
854
let def = Def :: Local ( canonical_id) ;
855
- if let Ok ( binding_cmt) = mc. cat_def( pat. id, pat. span, pat_ty, def) {
855
+ if let Ok ( ref binding_cmt) = mc. cat_def( pat. id, pat. span, pat_ty, def) {
856
856
delegate. mutate( pat. id, pat. span, binding_cmt, MutateMode :: Init ) ;
857
857
}
858
858
@@ -861,13 +861,13 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
861
861
ty:: BindByReference ( m) => {
862
862
if let ty:: TyRef ( r, _) = pat_ty. sty {
863
863
let bk = ty:: BorrowKind :: from_mutbl( m) ;
864
- delegate. borrow( pat. id, pat. span, cmt_pat, r, bk, RefBinding ) ;
864
+ delegate. borrow( pat. id, pat. span, & cmt_pat, r, bk, RefBinding ) ;
865
865
}
866
866
}
867
867
ty:: BindByValue ( ..) => {
868
868
let mode = copy_or_move( mc, param_env, & cmt_pat, PatBindingMove ) ;
869
869
debug!( "walk_pat binding consuming pat" ) ;
870
- delegate. consume_pat( pat, cmt_pat, mode) ;
870
+ delegate. consume_pat( pat, & cmt_pat, mode) ;
871
871
}
872
872
}
873
873
}
@@ -891,12 +891,12 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
891
891
let downcast_cmt = mc. cat_downcast_if_needed( pat, cmt_pat, variant_did) ;
892
892
893
893
debug!( "variant downcast_cmt={:?} pat={:?}" , downcast_cmt, pat) ;
894
- delegate. matched_pat( pat, downcast_cmt, match_mode) ;
894
+ delegate. matched_pat( pat, & downcast_cmt, match_mode) ;
895
895
}
896
896
Def :: Struct ( ..) | Def :: StructCtor ( ..) | Def :: Union ( ..) |
897
897
Def :: TyAlias ( ..) | Def :: AssociatedTy ( ..) | Def :: SelfTy ( ..) => {
898
898
debug!( "struct cmt_pat={:?} pat={:?}" , cmt_pat, pat) ;
899
- delegate. matched_pat( pat, cmt_pat, match_mode) ;
899
+ delegate. matched_pat( pat, & cmt_pat, match_mode) ;
900
900
}
901
901
_ => { }
902
902
}
@@ -924,12 +924,12 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
924
924
self . param_env ,
925
925
& cmt_var,
926
926
CaptureMove ) ;
927
- self . delegate . consume ( closure_expr. id , freevar. span , cmt_var, mode) ;
927
+ self . delegate . consume ( closure_expr. id , freevar. span , & cmt_var, mode) ;
928
928
}
929
929
ty:: UpvarCapture :: ByRef ( upvar_borrow) => {
930
930
self . delegate . borrow ( closure_expr. id ,
931
931
fn_decl_span,
932
- cmt_var,
932
+ & cmt_var,
933
933
upvar_borrow. region ,
934
934
upvar_borrow. kind ,
935
935
ClosureCapture ( freevar. span ) ) ;
@@ -943,7 +943,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
943
943
closure_id : ast:: NodeId ,
944
944
closure_span : Span ,
945
945
upvar : & hir:: Freevar )
946
- -> mc:: McResult < mc:: cmt < ' tcx > > {
946
+ -> mc:: McResult < mc:: cmt_ < ' tcx > > {
947
947
// Create the cmt for the variable being borrowed, from the
948
948
// caller's perspective
949
949
let var_hir_id = self . tcx ( ) . hir . node_to_hir_id ( upvar. var_id ( ) ) ;
@@ -954,7 +954,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
954
954
955
955
fn copy_or_move < ' a , ' gcx , ' tcx > ( mc : & mc:: MemCategorizationContext < ' a , ' gcx , ' tcx > ,
956
956
param_env : ty:: ParamEnv < ' tcx > ,
957
- cmt : & mc:: cmt < ' tcx > ,
957
+ cmt : & mc:: cmt_ < ' tcx > ,
958
958
move_reason : MoveReason )
959
959
-> ConsumeMode
960
960
{
0 commit comments