Skip to content

Commit e2d7e90

Browse files
committed
Remove Typer + ClosureTyper impls for ParameterEnv
1 parent fb295a6 commit e2d7e90

File tree

18 files changed

+60
-117
lines changed

18 files changed

+60
-117
lines changed

src/librustc/middle/check_const.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,16 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
111111

112112
fn with_euv<'b, F, R>(&'b mut self, item_id: Option<ast::NodeId>, f: F) -> R where
113113
F: for<'t> FnOnce(&mut euv::ExprUseVisitor<'b, 't, 'tcx,
114-
ty::ParameterEnvironment<'a, 'tcx>>) -> R,
114+
infer::InferCtxt<'a, 'tcx>>) -> R,
115115
{
116116
let param_env = match item_id {
117117
Some(item_id) => ty::ParameterEnvironment::for_item(self.tcx, item_id),
118118
None => self.tcx.empty_parameter_environment()
119119
};
120-
f(&mut euv::ExprUseVisitor::new(self, &param_env))
120+
121+
let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, Some(param_env), false);
122+
123+
f(&mut euv::ExprUseVisitor::new(self, &infcx))
121124
}
122125

123126
fn global_expr(&mut self, mode: Mode, expr: &ast::Expr) -> ConstQualif {
@@ -287,7 +290,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
287290
let cause = traits::ObligationCause::new(e.span, e.id, traits::SharedStatic);
288291
let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut();
289292
fulfill_cx.register_builtin_bound(&infcx, ty, ty::BoundSync, cause);
290-
match fulfill_cx.select_all_or_error(&infcx, &infcx.parameter_environment) {
293+
match fulfill_cx.select_all_or_error(&infcx, &infcx) {
291294
Ok(()) => { },
292295
Err(ref errors) => {
293296
traits::report_fulfillment_errors(&infcx, errors);

src/librustc/middle/check_match.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use middle::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Init};
2020
use middle::expr_use_visitor::{JustWrite, LoanCause, MutateMode};
2121
use middle::expr_use_visitor::WriteAndRead;
2222
use middle::expr_use_visitor as euv;
23+
use middle::infer;
2324
use middle::mem_categorization::{cmt, Typer};
2425
use middle::pat_util::*;
2526
use middle::ty::*;
@@ -1111,7 +1112,9 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
11111112
match p.node {
11121113
ast::PatIdent(ast::BindByValue(_), _, ref sub) => {
11131114
let pat_ty = tcx.node_id_to_type(p.id);
1114-
if cx.param_env.type_moves_by_default(pat_ty, pat.span) {
1115+
//FIXME: (@jroesch) this code should be floated up as well
1116+
let infcx = infer::new_infer_ctxt(cx.tcx, &cx.tcx.tables, Some(cx.param_env.clone()), false);
1117+
if infcx.type_moves_by_default(pat_ty, pat.span) {
11151118
check_move(p, sub.as_ref().map(|p| &**p));
11161119
}
11171120
}
@@ -1139,8 +1142,9 @@ fn check_for_mutation_in_guard<'a, 'tcx>(cx: &'a MatchCheckCtxt<'a, 'tcx>,
11391142
let mut checker = MutationChecker {
11401143
cx: cx,
11411144
};
1142-
let mut visitor = ExprUseVisitor::new(&mut checker,
1143-
&checker.cx.param_env);
1145+
1146+
let infcx = infer::new_infer_ctxt(cx.tcx, &cx.tcx.tables, Some(checker.cx.param_env.clone()), false);
1147+
let mut visitor = ExprUseVisitor::new(&mut checker, &infcx);
11441148
visitor.walk_expr(guard);
11451149
}
11461150

src/librustc/middle/check_rvalues.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// is the public starting point.
1313

1414
use middle::expr_use_visitor as euv;
15+
use middle::infer;
1516
use middle::mem_categorization as mc;
1617
use middle::ty::ParameterEnvironment;
1718
use middle::ty;
@@ -38,9 +39,11 @@ impl<'a, 'tcx, 'v> visit::Visitor<'v> for RvalueContext<'a, 'tcx> {
3839
s: Span,
3940
fn_id: ast::NodeId) {
4041
{
42+
// FIXME (@jroesch) change this to be an inference context
4143
let param_env = ParameterEnvironment::for_item(self.tcx, fn_id);
42-
let mut delegate = RvalueContextDelegate { tcx: self.tcx, param_env: &param_env };
43-
let mut euv = euv::ExprUseVisitor::new(&mut delegate, &param_env);
44+
let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, Some(param_env), false);
45+
let mut delegate = RvalueContextDelegate { tcx: self.tcx, param_env: &infcx.parameter_environment };
46+
let mut euv = euv::ExprUseVisitor::new(&mut delegate, &infcx);
4447
euv.walk_fn(fd, b);
4548
}
4649
visit::walk_fn(self, fk, fd, b, s)

src/librustc/middle/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ fn resolve_trait_associated_const<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>,
10331033
tcx.populate_implementations_for_trait_if_necessary(trait_ref.def_id());
10341034
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, false);
10351035

1036-
let mut selcx = traits::SelectionContext::new(&infcx, &infcx.parameter_environment);
1036+
let mut selcx = traits::SelectionContext::new(&infcx, &infcx);
10371037
let obligation = traits::Obligation::new(traits::ObligationCause::dummy(),
10381038
trait_ref.to_poly_trait_predicate());
10391039
let selection = match selcx.select(&obligation) {

src/librustc/middle/infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl<'a, 'tcx> mc::Typer<'tcx> for InferCtxt<'a, 'tcx> {
525525
}
526526

527527
fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option<CodeExtent> {
528-
self.parameter_environment.temporary_scope(rvalue_id)
528+
self.tcx.region_maps.temporary_scope(rvalue_id)
529529
}
530530

531531
fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> {

src/librustc/middle/traits/coherence.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ pub fn overlapping_impls(infcx: &InferCtxt,
3838
impl1_def_id,
3939
impl2_def_id);
4040

41-
let param_env = &infcx.tcx.empty_parameter_environment();
42-
let selcx = &mut SelectionContext::intercrate(infcx, param_env);
41+
let selcx = &mut SelectionContext::intercrate(infcx, infcx);
4342
infcx.probe(|_| {
4443
overlap(selcx, impl1_def_id, impl2_def_id) || overlap(selcx, impl2_def_id, impl1_def_id)
4544
})

src/librustc/middle/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ pub fn normalize_param_env_or_error<'a,'tcx>(unnormalized_env: ty::ParameterEnvi
398398
let elaborated_env = unnormalized_env.with_caller_bounds(predicates);
399399

400400
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(elaborated_env), false);
401-
let predicates = match fully_normalize(&infcx, &infcx.parameter_environment, cause,
401+
let predicates = match fully_normalize(&infcx, &infcx, cause,
402402
&infcx.parameter_environment.caller_bounds) {
403403
Ok(predicates) => predicates,
404404
Err(errors) => {

src/librustc/middle/ty.rs

Lines changed: 11 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ use middle::dependency_format;
5252
use middle::fast_reject;
5353
use middle::free_region::FreeRegionMap;
5454
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
55-
use middle::mem_categorization as mc;
5655
use middle::mem_categorization::Typer;
5756
use middle::region;
5857
use middle::resolve_lifetime;
@@ -2919,11 +2918,14 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
29192918
-> Result<(),CopyImplementationError> {
29202919
let tcx = self.tcx;
29212920

2921+
// FIXME: (@jroesch) float this code up
2922+
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(self.clone()), false);
2923+
29222924
let did = match self_type.sty {
29232925
ty::TyStruct(struct_did, substs) => {
29242926
let fields = tcx.struct_fields(struct_did, substs);
29252927
for field in &fields {
2926-
if self.type_moves_by_default(field.mt.ty, span) {
2928+
if infcx.type_moves_by_default(field.mt.ty, span) {
29272929
return Err(FieldDoesNotImplementCopy(field.name))
29282930
}
29292931
}
@@ -2935,7 +2937,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
29352937
for variant_arg_type in &variant.args {
29362938
let substd_arg_type =
29372939
variant_arg_type.subst(tcx, substs);
2938-
if self.type_moves_by_default(substd_arg_type, span) {
2940+
if infcx.type_moves_by_default(substd_arg_type, span) {
29392941
return Err(VariantDoesNotImplementCopy(variant.name))
29402942
}
29412943
}
@@ -4272,7 +4274,8 @@ impl<'tcx> TyS<'tcx> {
42724274
TyClosure(did, substs) => {
42734275
// FIXME(#14449): `borrowed_contents` below assumes `&mut` closure.
42744276
let param_env = cx.empty_parameter_environment();
4275-
let upvars = param_env.closure_upvars(did, substs).unwrap();
4277+
let infcx = infer::new_infer_ctxt(cx, &cx.tables, Some(param_env), false);
4278+
let upvars = infcx.closure_upvars(did, substs).unwrap();
42764279
TypeContents::union(&upvars, |f| tc_ty(cx, &f.ty, cache))
42774280
}
42784281

@@ -4400,10 +4403,10 @@ impl<'tcx> TyS<'tcx> {
44004403
span: Span)
44014404
-> bool
44024405
{
4403-
let tcx = param_env.tcx();
4406+
let tcx = param_env.tcx;
44044407
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(param_env.clone()), false);
44054408

4406-
let is_impld = traits::type_known_to_meet_builtin_bound(&infcx, param_env,
4409+
let is_impld = traits::type_known_to_meet_builtin_bound(&infcx, &infcx,
44074410
self, bound, span);
44084411

44094412
debug!("Ty::impls_bound({:?}, {:?}) = {:?}",
@@ -4412,7 +4415,8 @@ impl<'tcx> TyS<'tcx> {
44124415
is_impld
44134416
}
44144417

4415-
fn moves_by_default<'a>(&'tcx self, param_env: &ParameterEnvironment<'a,'tcx>,
4418+
// temp hack, probably should be private
4419+
pub fn moves_by_default<'a>(&'tcx self, param_env: &ParameterEnvironment<'a,'tcx>,
44164420
span: Span) -> bool {
44174421
if self.flags.get().intersects(TypeFlags::MOVENESS_CACHED) {
44184422
return self.flags.get().intersects(TypeFlags::MOVES_BY_DEFAULT);
@@ -6711,79 +6715,6 @@ impl<'tcx> ctxt<'tcx> {
67116715
}
67126716
}
67136717

6714-
impl<'a,'tcx> Typer<'tcx> for ParameterEnvironment<'a,'tcx> {
6715-
fn node_ty(&self, id: ast::NodeId) -> mc::McResult<Ty<'tcx>> {
6716-
Ok(self.tcx.node_id_to_type(id))
6717-
}
6718-
6719-
fn expr_ty_adjusted(&self, expr: &ast::Expr) -> mc::McResult<Ty<'tcx>> {
6720-
Ok(self.tcx.expr_ty_adjusted(expr))
6721-
}
6722-
6723-
fn node_method_ty(&self, method_call: ty::MethodCall) -> Option<Ty<'tcx>> {
6724-
self.tcx.tables.borrow().method_map.get(&method_call).map(|method| method.ty)
6725-
}
6726-
6727-
fn node_method_origin(&self, method_call: ty::MethodCall)
6728-
-> Option<ty::MethodOrigin<'tcx>>
6729-
{
6730-
self.tcx.tables.borrow().method_map.get(&method_call).map(|method| method.origin.clone())
6731-
}
6732-
6733-
fn adjustments(&self) -> Ref<NodeMap<ty::AutoAdjustment<'tcx>>> {
6734-
fn projection<'a, 'tcx>(tables: &'a Tables<'tcx>) -> &'a NodeMap<ty::AutoAdjustment<'tcx>> {
6735-
&tables.adjustments
6736-
}
6737-
6738-
Ref::map(self.tcx.tables.borrow(), projection)
6739-
}
6740-
6741-
fn is_method_call(&self, id: ast::NodeId) -> bool {
6742-
self.tcx.is_method_call(id)
6743-
}
6744-
6745-
fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option<region::CodeExtent> {
6746-
self.tcx.region_maps.temporary_scope(rvalue_id)
6747-
}
6748-
6749-
fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> {
6750-
self.tcx.upvar_capture(upvar_id)
6751-
}
6752-
6753-
fn type_moves_by_default(&self, ty: Ty<'tcx>, span: Span) -> bool {
6754-
ty.moves_by_default(self, span)
6755-
}
6756-
}
6757-
6758-
impl<'a,'tcx> ClosureTyper<'tcx> for ty::ParameterEnvironment<'a,'tcx> {
6759-
fn param_env<'b>(&'b self) -> &'b ty::ParameterEnvironment<'b,'tcx> {
6760-
self
6761-
}
6762-
6763-
fn closure_kind(&self,
6764-
def_id: ast::DefId)
6765-
-> Option<ty::ClosureKind>
6766-
{
6767-
Some(self.tcx.closure_kind(def_id))
6768-
}
6769-
6770-
fn closure_type(&self,
6771-
def_id: ast::DefId,
6772-
substs: &subst::Substs<'tcx>)
6773-
-> ty::ClosureTy<'tcx>
6774-
{
6775-
self.tcx.closure_type(def_id, substs)
6776-
}
6777-
6778-
fn closure_upvars(&self,
6779-
def_id: ast::DefId,
6780-
substs: &Substs<'tcx>)
6781-
-> Option<Vec<ClosureUpvar<'tcx>>> {
6782-
ctxt::closure_upvars(self, def_id, substs)
6783-
}
6784-
}
6785-
6786-
67876718
/// The category of explicit self.
67886719
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
67896720
pub enum ExplicitSelfCategory {

src/librustc_borrowck/borrowck/check_loans.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use self::UseError::*;
2121
use borrowck::*;
2222
use borrowck::InteriorKind::{InteriorElement, InteriorField};
2323
use rustc::middle::expr_use_visitor as euv;
24+
use rustc::middle::infer;
2425
use rustc::middle::mem_categorization as mc;
2526
use rustc::middle::region;
2627
use rustc::middle::ty;
@@ -198,17 +199,18 @@ pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
198199
debug!("check_loans(body id={})", body.id);
199200

200201
let param_env = ty::ParameterEnvironment::for_item(bccx.tcx, fn_id);
202+
let infcx = infer::new_infer_ctxt(bccx.tcx, &bccx.tcx.tables, Some(param_env), false);
201203

202204
let mut clcx = CheckLoanCtxt {
203205
bccx: bccx,
204206
dfcx_loans: dfcx_loans,
205207
move_data: move_data,
206208
all_loans: all_loans,
207-
param_env: &param_env,
209+
param_env: &infcx.parameter_environment
208210
};
209211

210212
{
211-
let mut euv = euv::ExprUseVisitor::new(&mut clcx, &param_env);
213+
let mut euv = euv::ExprUseVisitor::new(&mut clcx, &infcx);
212214
euv.walk_fn(decl, body);
213215
}
214216
}

src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use borrowck::*;
2020
use borrowck::move_data::MoveData;
2121
use rustc::middle::expr_use_visitor as euv;
22+
use rustc::middle::infer;
2223
use rustc::middle::mem_categorization as mc;
2324
use rustc::middle::region;
2425
use rustc::middle::ty;
@@ -49,9 +50,9 @@ pub fn gather_loans_in_fn<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
4950
};
5051

5152
let param_env = ty::ParameterEnvironment::for_item(bccx.tcx, fn_id);
52-
53+
let infcx = infer::new_infer_ctxt(bccx.tcx, &bccx.tcx.tables, Some(param_env), false);
5354
{
54-
let mut euv = euv::ExprUseVisitor::new(&mut glcx, &param_env);
55+
let mut euv = euv::ExprUseVisitor::new(&mut glcx, &infcx);
5556
euv.walk_fn(decl, body);
5657
}
5758

@@ -490,8 +491,8 @@ struct StaticInitializerCtxt<'a, 'tcx: 'a> {
490491
impl<'a, 'tcx, 'v> Visitor<'v> for StaticInitializerCtxt<'a, 'tcx> {
491492
fn visit_expr(&mut self, ex: &Expr) {
492493
if let ast::ExprAddrOf(mutbl, ref base) = ex.node {
493-
let param_env = self.bccx.tcx.empty_parameter_environment();
494-
let mc = mc::MemCategorizationContext::new(&param_env);
494+
let infcx = infer::new_infer_ctxt(self.bccx.tcx, &self.bccx.tcx.tables, None, false);
495+
let mc = mc::MemCategorizationContext::new(&infcx);
495496
let base_cmt = mc.cat_expr(&**base).unwrap();
496497
let borrow_kind = ty::BorrowKind::from_mutbl(mutbl);
497498
// Check that we don't allow borrows of unsafe static items.

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
747747
-> (&'static str, &'static str) {
748748
match ty.sty {
749749
_ => {
750-
if param_env.type_moves_by_default(ty, span) {
750+
if ty.moves_by_default(param_env, span) {
751751
("non-copyable",
752752
"perhaps you meant to use `clone()`?")
753753
} else {

src/librustc_lint/builtin.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,9 @@ impl LintPass for MissingCopyImplementations {
17041704
_ => return,
17051705
};
17061706
let parameter_environment = cx.tcx.empty_parameter_environment();
1707-
if !parameter_environment.type_moves_by_default(ty, item.span) {
1707+
// FIXME (@jroesch) should probably inver this so that the parameter env still impls this
1708+
// method
1709+
if !ty.moves_by_default(&parameter_environment, item.span) {
17081710
return;
17091711
}
17101712
if parameter_environment.can_type_implement_copy(ty, item.span).is_ok() {

src/librustc_trans/trans/_match.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ use middle::def::{self, DefMap};
197197
use middle::expr_use_visitor as euv;
198198
use middle::lang_items::StrEqFnLangItem;
199199
use middle::mem_categorization as mc;
200-
use middle::mem_categorization::Typer;
201200
use middle::pat_util::*;
202201
use trans::adt;
203202
use trans::base::*;
@@ -1416,7 +1415,7 @@ fn create_bindings_map<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pat: &ast::Pat,
14161415
let trmode;
14171416
match bm {
14181417
ast::BindByValue(_)
1419-
if !param_env.type_moves_by_default(variable_ty, span) || reassigned =>
1418+
if !variable_ty.moves_by_default(&param_env, span) || reassigned =>
14201419
{
14211420
llmatch = alloca_no_lifetime(bcx,
14221421
llvariable_ty.ptr_to(),

src/librustc_trans/trans/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn type_needs_drop_given_env<'a,'tcx>(cx: &ty::ctxt<'tcx>,
154154
// normalized version of the type, and therefore will definitely
155155
// know whether the type implements Copy (and thus needs no
156156
// cleanup/drop/zeroing) ...
157-
let implements_copy = !param_env.type_moves_by_default(ty, DUMMY_SP);
157+
let implements_copy = !ty.moves_by_default(param_env, DUMMY_SP);
158158

159159
if implements_copy { return false; }
160160

@@ -630,7 +630,7 @@ impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> {
630630
}
631631

632632
fn type_moves_by_default(&self, ty: Ty<'tcx>, span: Span) -> bool {
633-
self.fcx.param_env.type_moves_by_default(ty, span)
633+
ty.moves_by_default(&self.fcx.param_env, span)
634634
}
635635
}
636636

src/librustc_trans/trans/datum.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ use trans::cleanup::CleanupMethods;
101101
use trans::expr;
102102
use trans::tvec;
103103
use trans::type_of;
104-
use middle::mem_categorization::Typer;
105104
use middle::ty::Ty;
106105

107106
use std::fmt;
@@ -606,8 +605,8 @@ impl<'tcx, K: KindOps + fmt::Debug> Datum<'tcx, K> {
606605
* affine values (since they must never be duplicated).
607606
*/
608607

609-
assert!(!bcx.tcx().empty_parameter_environment()
610-
.type_moves_by_default(self.ty, DUMMY_SP));
608+
assert!(!self.ty
609+
.moves_by_default(&bcx.tcx().empty_parameter_environment(), DUMMY_SP));
611610
self.shallow_copy_raw(bcx, dst)
612611
}
613612

0 commit comments

Comments
 (0)