@@ -10,7 +10,6 @@ use crate::hir::def_id::DefId;
10
10
use crate :: hir:: ptr:: P ;
11
11
use crate :: infer:: InferCtxt ;
12
12
use crate :: middle:: mem_categorization as mc;
13
- use crate :: middle:: region;
14
13
use crate :: ty:: { self , TyCtxt , adjustment} ;
15
14
16
15
use crate :: hir:: { self , PatKind } ;
@@ -85,7 +84,6 @@ impl OverloadedCallType {
85
84
pub struct ExprUseVisitor < ' a , ' tcx > {
86
85
mc : mc:: MemCategorizationContext < ' a , ' tcx > ,
87
86
delegate : & ' a mut dyn Delegate < ' tcx > ,
88
- param_env : ty:: ParamEnv < ' tcx > ,
89
87
}
90
88
91
89
// If the MC results in an error, it's because the type check
@@ -112,49 +110,22 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
112
110
///
113
111
/// - `delegate` -- who receives the callbacks
114
112
/// - `param_env` --- parameter environment for trait lookups (esp. pertaining to `Copy`)
115
- /// - `region_scope_tree` --- region scope tree for the code being analyzed
116
113
/// - `tables` --- typeck results for the code being analyzed
117
- ///
118
- /// See also `with_infer`, which is used *during* typeck.
119
114
pub fn new (
120
- delegate : & ' a mut ( dyn Delegate < ' tcx > + ' a ) ,
121
- tcx : TyCtxt < ' tcx > ,
122
- body_owner : DefId ,
123
- param_env : ty:: ParamEnv < ' tcx > ,
124
- region_scope_tree : & ' a region:: ScopeTree ,
125
- tables : & ' a ty:: TypeckTables < ' tcx > ,
126
- ) -> Self {
127
- ExprUseVisitor {
128
- mc : mc:: MemCategorizationContext :: new ( tcx,
129
- param_env,
130
- body_owner,
131
- region_scope_tree,
132
- tables) ,
133
- delegate,
134
- param_env,
135
- }
136
- }
137
- }
138
-
139
- impl < ' a , ' tcx > ExprUseVisitor < ' a , ' tcx > {
140
- pub fn with_infer (
141
115
delegate : & ' a mut ( dyn Delegate < ' tcx > + ' a ) ,
142
116
infcx : & ' a InferCtxt < ' a , ' tcx > ,
143
117
body_owner : DefId ,
144
118
param_env : ty:: ParamEnv < ' tcx > ,
145
- region_scope_tree : & ' a region:: ScopeTree ,
146
119
tables : & ' a ty:: TypeckTables < ' tcx > ,
147
120
) -> Self {
148
121
ExprUseVisitor {
149
- mc : mc:: MemCategorizationContext :: with_infer (
122
+ mc : mc:: MemCategorizationContext :: new (
150
123
infcx,
151
124
param_env,
152
125
body_owner,
153
- region_scope_tree,
154
126
tables,
155
127
) ,
156
128
delegate,
157
- param_env,
158
129
}
159
130
}
160
131
@@ -177,14 +148,14 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
177
148
}
178
149
179
150
fn tcx ( & self ) -> TyCtxt < ' tcx > {
180
- self . mc . tcx
151
+ self . mc . tcx ( )
181
152
}
182
153
183
- fn delegate_consume ( & mut self , cmt : & mc:: Place < ' tcx > ) {
184
- debug ! ( "delegate_consume(cmt ={:?})" , cmt ) ;
154
+ fn delegate_consume ( & mut self , place : & mc:: Place < ' tcx > ) {
155
+ debug ! ( "delegate_consume(place ={:?})" , place ) ;
185
156
186
- let mode = copy_or_move ( & self . mc , self . param_env , cmt ) ;
187
- self . delegate . consume ( cmt , mode) ;
157
+ let mode = copy_or_move ( & self . mc , place ) ;
158
+ self . delegate . consume ( place , mode) ;
188
159
}
189
160
190
161
fn consume_exprs ( & mut self , exprs : & [ hir:: Expr ] ) {
@@ -573,7 +544,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
573
544
debug ! ( "walk_pat(cmt_discr={:?}, pat={:?})" , cmt_discr, pat) ;
574
545
575
546
let tcx = self . tcx ( ) ;
576
- let ExprUseVisitor { ref mc, ref mut delegate, param_env } = * self ;
547
+ let ExprUseVisitor { ref mc, ref mut delegate } = * self ;
577
548
return_if_err ! ( mc. cat_pattern( cmt_discr. clone( ) , pat, |cmt_pat, pat| {
578
549
if let PatKind :: Binding ( _, canonical_id, ..) = pat. kind {
579
550
debug!(
@@ -602,7 +573,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
602
573
delegate. borrow( & cmt_pat, bk) ;
603
574
}
604
575
ty:: BindByValue ( ..) => {
605
- let mode = copy_or_move( mc, param_env , & cmt_pat) ;
576
+ let mode = copy_or_move( mc, & cmt_pat) ;
606
577
debug!( "walk_pat binding consuming pat" ) ;
607
578
delegate. consume( & cmt_pat, mode) ;
608
579
}
@@ -630,7 +601,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
630
601
var_id) ) ;
631
602
match upvar_capture {
632
603
ty:: UpvarCapture :: ByValue => {
633
- let mode = copy_or_move ( & self . mc , self . param_env , & cmt_var) ;
604
+ let mode = copy_or_move ( & self . mc , & cmt_var) ;
634
605
self . delegate . consume ( & cmt_var, mode) ;
635
606
}
636
607
ty:: UpvarCapture :: ByRef ( upvar_borrow) => {
@@ -655,10 +626,9 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
655
626
656
627
fn copy_or_move < ' a , ' tcx > (
657
628
mc : & mc:: MemCategorizationContext < ' a , ' tcx > ,
658
- param_env : ty:: ParamEnv < ' tcx > ,
659
- cmt : & mc:: Place < ' tcx > ,
629
+ place : & mc:: Place < ' tcx > ,
660
630
) -> ConsumeMode {
661
- if !mc. type_is_copy_modulo_regions ( param_env , cmt . ty , cmt . span ) {
631
+ if !mc. type_is_copy_modulo_regions ( place . ty , place . span ) {
662
632
Move
663
633
} else {
664
634
Copy
0 commit comments