Skip to content

Commit a5b8a30

Browse files
committed
Simplify fields of MemCategorizationContext
1 parent 4195b60 commit a5b8a30

File tree

4 files changed

+57
-143
lines changed

4 files changed

+57
-143
lines changed

src/librustc/middle/expr_use_visitor.rs

+11-41
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::hir::def_id::DefId;
1010
use crate::hir::ptr::P;
1111
use crate::infer::InferCtxt;
1212
use crate::middle::mem_categorization as mc;
13-
use crate::middle::region;
1413
use crate::ty::{self, TyCtxt, adjustment};
1514

1615
use crate::hir::{self, PatKind};
@@ -85,7 +84,6 @@ impl OverloadedCallType {
8584
pub struct ExprUseVisitor<'a, 'tcx> {
8685
mc: mc::MemCategorizationContext<'a, 'tcx>,
8786
delegate: &'a mut dyn Delegate<'tcx>,
88-
param_env: ty::ParamEnv<'tcx>,
8987
}
9088

9189
// If the MC results in an error, it's because the type check
@@ -112,49 +110,22 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
112110
///
113111
/// - `delegate` -- who receives the callbacks
114112
/// - `param_env` --- parameter environment for trait lookups (esp. pertaining to `Copy`)
115-
/// - `region_scope_tree` --- region scope tree for the code being analyzed
116113
/// - `tables` --- typeck results for the code being analyzed
117-
///
118-
/// See also `with_infer`, which is used *during* typeck.
119114
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(
141115
delegate: &'a mut (dyn Delegate<'tcx> + 'a),
142116
infcx: &'a InferCtxt<'a, 'tcx>,
143117
body_owner: DefId,
144118
param_env: ty::ParamEnv<'tcx>,
145-
region_scope_tree: &'a region::ScopeTree,
146119
tables: &'a ty::TypeckTables<'tcx>,
147120
) -> Self {
148121
ExprUseVisitor {
149-
mc: mc::MemCategorizationContext::with_infer(
122+
mc: mc::MemCategorizationContext::new(
150123
infcx,
151124
param_env,
152125
body_owner,
153-
region_scope_tree,
154126
tables,
155127
),
156128
delegate,
157-
param_env,
158129
}
159130
}
160131

@@ -177,14 +148,14 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
177148
}
178149

179150
fn tcx(&self) -> TyCtxt<'tcx> {
180-
self.mc.tcx
151+
self.mc.tcx()
181152
}
182153

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);
185156

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);
188159
}
189160

190161
fn consume_exprs(&mut self, exprs: &[hir::Expr]) {
@@ -573,7 +544,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
573544
debug!("walk_pat(cmt_discr={:?}, pat={:?})", cmt_discr, pat);
574545

575546
let tcx = self.tcx();
576-
let ExprUseVisitor { ref mc, ref mut delegate, param_env } = *self;
547+
let ExprUseVisitor { ref mc, ref mut delegate } = *self;
577548
return_if_err!(mc.cat_pattern(cmt_discr.clone(), pat, |cmt_pat, pat| {
578549
if let PatKind::Binding(_, canonical_id, ..) = pat.kind {
579550
debug!(
@@ -602,7 +573,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
602573
delegate.borrow(&cmt_pat, bk);
603574
}
604575
ty::BindByValue(..) => {
605-
let mode = copy_or_move(mc, param_env, &cmt_pat);
576+
let mode = copy_or_move(mc, &cmt_pat);
606577
debug!("walk_pat binding consuming pat");
607578
delegate.consume(&cmt_pat, mode);
608579
}
@@ -630,7 +601,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
630601
var_id));
631602
match upvar_capture {
632603
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);
634605
self.delegate.consume(&cmt_var, mode);
635606
}
636607
ty::UpvarCapture::ByRef(upvar_borrow) => {
@@ -655,10 +626,9 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
655626

656627
fn copy_or_move<'a, 'tcx>(
657628
mc: &mc::MemCategorizationContext<'a, 'tcx>,
658-
param_env: ty::ParamEnv<'tcx>,
659-
cmt: &mc::Place<'tcx>,
629+
place: &mc::Place<'tcx>,
660630
) -> 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) {
662632
Move
663633
} else {
664634
Copy

0 commit comments

Comments
 (0)