Skip to content

Commit 0907c19

Browse files
committed
infer: Use methods for creating an InferCtxt.
1 parent b5122d5 commit 0907c19

File tree

30 files changed

+126
-154
lines changed

30 files changed

+126
-154
lines changed

src/librustc/infer/mod.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -382,34 +382,36 @@ pub fn fixup_err_to_string(f: FixupError) -> String {
382382
}
383383
}
384384

385-
pub fn new_infer_ctxt<'a, 'tcx>(tcx: &'a TyCtxt<'tcx>,
386-
tables: &'a RefCell<ty::Tables<'tcx>>,
387-
param_env: Option<ty::ParameterEnvironment<'a, 'tcx>>,
388-
projection_mode: ProjectionMode)
389-
-> InferCtxt<'a, 'tcx> {
390-
InferCtxt {
391-
tcx: tcx,
392-
tables: tables,
393-
type_variables: RefCell::new(type_variable::TypeVariableTable::new()),
394-
int_unification_table: RefCell::new(UnificationTable::new()),
395-
float_unification_table: RefCell::new(UnificationTable::new()),
396-
region_vars: RegionVarBindings::new(tcx),
397-
parameter_environment: param_env.unwrap_or(tcx.empty_parameter_environment()),
398-
reported_trait_errors: RefCell::new(FnvHashSet()),
399-
normalize: false,
400-
projection_mode: projection_mode,
385+
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
386+
pub fn new(tcx: &'a TyCtxt<'tcx>,
387+
tables: &'a RefCell<ty::Tables<'tcx>>,
388+
param_env: Option<ty::ParameterEnvironment<'a, 'tcx>>,
389+
projection_mode: ProjectionMode)
390+
-> Self {
391+
InferCtxt {
392+
tcx: tcx,
393+
tables: tables,
394+
type_variables: RefCell::new(type_variable::TypeVariableTable::new()),
395+
int_unification_table: RefCell::new(UnificationTable::new()),
396+
float_unification_table: RefCell::new(UnificationTable::new()),
397+
region_vars: RegionVarBindings::new(tcx),
398+
parameter_environment: param_env.unwrap_or(tcx.empty_parameter_environment()),
399+
reported_trait_errors: RefCell::new(FnvHashSet()),
400+
normalize: false,
401+
projection_mode: projection_mode,
401402
tainted_by_errors_flag: Cell::new(false),
402-
err_count_on_creation: tcx.sess.err_count()
403+
err_count_on_creation: tcx.sess.err_count()
404+
}
403405
}
404-
}
405406

406-
pub fn normalizing_infer_ctxt<'a, 'tcx>(tcx: &'a TyCtxt<'tcx>,
407-
tables: &'a RefCell<ty::Tables<'tcx>>,
408-
projection_mode: ProjectionMode)
409-
-> InferCtxt<'a, 'tcx> {
410-
let mut infcx = new_infer_ctxt(tcx, tables, None, projection_mode);
411-
infcx.normalize = true;
412-
infcx
407+
pub fn normalizing(tcx: &'a TyCtxt<'tcx>,
408+
tables: &'a RefCell<ty::Tables<'tcx>>,
409+
projection_mode: ProjectionMode)
410+
-> Self {
411+
let mut infcx = InferCtxt::new(tcx, tables, None, projection_mode);
412+
infcx.normalize = true;
413+
infcx
414+
}
413415
}
414416

415417
pub fn mk_subty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
@@ -532,7 +534,7 @@ pub fn normalize_associated_type<'tcx,T>(tcx: &TyCtxt<'tcx>, value: &T) -> T
532534
return value;
533535
}
534536

535-
let infcx = new_infer_ctxt(tcx, &tcx.tables, None, ProjectionMode::Any);
537+
let infcx = InferCtxt::new(tcx, &tcx.tables, None, ProjectionMode::Any);
536538
let mut selcx = traits::SelectionContext::new(&infcx);
537539
let cause = traits::ObligationCause::dummy();
538540
let traits::Normalized { value: result, obligations } =

src/librustc/middle/intrinsicck.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use dep_graph::DepNode;
1212
use hir::def::Def;
1313
use hir::def_id::DefId;
14-
use infer::{InferCtxt, new_infer_ctxt};
14+
use infer::InferCtxt;
1515
use traits::ProjectionMode;
1616
use ty::{self, Ty, TyCtxt};
1717
use ty::layout::{LayoutError, Pointer, SizeSkeleton};
@@ -36,7 +36,7 @@ struct ItemVisitor<'a, 'tcx: 'a> {
3636
impl<'a, 'tcx> ItemVisitor<'a, 'tcx> {
3737
fn visit_const(&mut self, item_id: ast::NodeId, expr: &hir::Expr) {
3838
let param_env = ty::ParameterEnvironment::for_item(self.tcx, item_id);
39-
let infcx = new_infer_ctxt(self.tcx, &self.tcx.tables,
39+
let infcx = InferCtxt::new(self.tcx, &self.tcx.tables,
4040
Some(param_env),
4141
ProjectionMode::Any);
4242
let mut visitor = ExprVisitor {
@@ -115,7 +115,7 @@ impl<'a, 'tcx> ExprVisitor<'a, 'tcx> {
115115
impl<'a, 'tcx, 'v> Visitor<'v> for ItemVisitor<'a, 'tcx> {
116116
// const, static and N in [T; N].
117117
fn visit_expr(&mut self, expr: &hir::Expr) {
118-
let infcx = new_infer_ctxt(self.tcx, &self.tcx.tables,
118+
let infcx = InferCtxt::new(self.tcx, &self.tcx.tables,
119119
None, ProjectionMode::Any);
120120
let mut visitor = ExprVisitor {
121121
infcx: &infcx
@@ -144,7 +144,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ItemVisitor<'a, 'tcx> {
144144
match fk {
145145
FnKind::ItemFn(..) | FnKind::Method(..) => {
146146
let param_env = ty::ParameterEnvironment::for_item(self.tcx, id);
147-
let infcx = new_infer_ctxt(self.tcx, &self.tcx.tables,
147+
let infcx = InferCtxt::new(self.tcx, &self.tcx.tables,
148148
Some(param_env),
149149
ProjectionMode::Any);
150150
let mut visitor = ExprVisitor {

src/librustc/middle/liveness.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ use hir::def::*;
114114
use hir::pat_util;
115115
use ty::{self, TyCtxt, ParameterEnvironment};
116116
use traits::{self, ProjectionMode};
117-
use infer;
117+
use infer::InferCtxt;
118118
use ty::subst::Subst;
119119
use lint;
120120
use util::nodemap::NodeMap;
@@ -1488,10 +1488,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
14881488

14891489
let param_env = ParameterEnvironment::for_item(&self.ir.tcx, id);
14901490
let t_ret_subst = t_ret.subst(&self.ir.tcx, &param_env.free_substs);
1491-
let infcx = infer::new_infer_ctxt(&self.ir.tcx,
1492-
&self.ir.tcx.tables,
1493-
Some(param_env),
1494-
ProjectionMode::Any);
1491+
let infcx = InferCtxt::new(&self.ir.tcx,
1492+
&self.ir.tcx.tables,
1493+
Some(param_env),
1494+
ProjectionMode::Any);
14951495
let cause = traits::ObligationCause::dummy();
14961496
let norm = traits::fully_normalize(&infcx,
14971497
cause,

src/librustc/traits/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use hir::def_id::DefId;
1919
use middle::free_region::FreeRegionMap;
2020
use ty::subst;
2121
use ty::{self, Ty, TypeFoldable};
22-
use infer::{self, fixup_err_to_string, InferCtxt};
22+
use infer::{fixup_err_to_string, InferCtxt};
2323

2424
use std::rc::Rc;
2525
use syntax::ast;
@@ -437,10 +437,8 @@ pub fn normalize_param_env_or_error<'a,'tcx>(unnormalized_env: ty::ParameterEnvi
437437

438438
let elaborated_env = unnormalized_env.with_caller_bounds(predicates);
439439

440-
let infcx = infer::new_infer_ctxt(tcx,
441-
&tcx.tables,
442-
Some(elaborated_env),
443-
ProjectionMode::AnyFinal);
440+
let infcx = InferCtxt::new(tcx, &tcx.tables, Some(elaborated_env),
441+
ProjectionMode::AnyFinal);
444442
let predicates = match fully_normalize(&infcx,
445443
cause,
446444
&infcx.parameter_environment.caller_bounds) {

src/librustc/traits/specialize/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn specializes(tcx: &TyCtxt, impl1_def_id: DefId, impl2_def_id: DefId) -> bo
133133
return false;
134134
}
135135

136-
let mut infcx = infer::normalizing_infer_ctxt(tcx, &tcx.tables, ProjectionMode::Topmost);
136+
let mut infcx = InferCtxt::normalizing(tcx, &tcx.tables, ProjectionMode::Topmost);
137137

138138
// create a parameter environment corresponding to a (skolemized) instantiation of impl1
139139
let scheme = tcx.lookup_item_type(impl1_def_id);

src/librustc/traits/specialize/specialization_graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::rc::Rc;
1414
use super::{Overlap, specializes};
1515

1616
use hir::def_id::DefId;
17-
use infer;
17+
use infer::InferCtxt;
1818
use traits::{self, ProjectionMode};
1919
use ty::{self, TyCtxt, ImplOrTraitItem, TraitDef, TypeFoldable};
2020
use ty::fast_reject::{self, SimplifiedType};
@@ -113,7 +113,7 @@ impl Children {
113113
} {
114114
let possible_sibling = *slot;
115115

116-
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, ProjectionMode::Topmost);
116+
let infcx = InferCtxt::new(tcx, &tcx.tables, None, ProjectionMode::Topmost);
117117
let overlap = traits::overlapping_impls(&infcx, possible_sibling, impl_def_id);
118118

119119
if let Some(impl_header) = overlap {

src/librustc/ty/util.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use hir::svh::Svh;
1414
use hir::def_id::DefId;
1515
use ty::subst;
16-
use infer;
16+
use infer::InferCtxt;
1717
use hir::pat_util;
1818
use traits::{self, ProjectionMode};
1919
use ty::{self, Ty, TyCtxt, TypeAndMut, TypeFlags, TypeFoldable};
@@ -129,10 +129,8 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
129129
let tcx = self.tcx;
130130

131131
// FIXME: (@jroesch) float this code up
132-
let infcx = infer::new_infer_ctxt(tcx,
133-
&tcx.tables,
134-
Some(self.clone()),
135-
ProjectionMode::Topmost);
132+
let infcx = InferCtxt::new(tcx, &tcx.tables, Some(self.clone()),
133+
ProjectionMode::Topmost);
136134

137135
let adt = match self_type.sty {
138136
ty::TyStruct(struct_def, substs) => {
@@ -511,10 +509,8 @@ impl<'tcx> ty::TyS<'tcx> {
511509
-> bool
512510
{
513511
let tcx = param_env.tcx;
514-
let infcx = infer::new_infer_ctxt(tcx,
515-
&tcx.tables,
516-
Some(param_env.clone()),
517-
ProjectionMode::Topmost);
512+
let infcx = InferCtxt::new(tcx, &tcx.tables, Some(param_env.clone()),
513+
ProjectionMode::Topmost);
518514

519515
let is_impld = traits::type_known_to_meet_builtin_bound(&infcx,
520516
self, bound, span);
@@ -600,7 +596,7 @@ impl<'tcx> ty::TyS<'tcx> {
600596
}
601597

602598
#[inline]
603-
pub fn layout<'a>(&'tcx self, infcx: &infer::InferCtxt<'a, 'tcx>)
599+
pub fn layout<'a>(&'tcx self, infcx: &InferCtxt<'a, 'tcx>)
604600
-> Result<&'tcx Layout, LayoutError<'tcx>> {
605601
let can_cache = !self.has_param_types() && !self.has_self_ty();
606602
if can_cache {

src/librustc_borrowck/borrowck/check_loans.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use borrowck::*;
2222
use borrowck::InteriorKind::{InteriorElement, InteriorField};
2323
use rustc::middle::expr_use_visitor as euv;
2424
use rustc::middle::expr_use_visitor::MutateMode;
25-
use rustc::infer;
25+
use rustc::infer::InferCtxt;
2626
use rustc::middle::mem_categorization as mc;
2727
use rustc::middle::mem_categorization::Categorization;
2828
use rustc::middle::region;
@@ -203,10 +203,8 @@ pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
203203
debug!("check_loans(body id={})", body.id);
204204

205205
let param_env = ty::ParameterEnvironment::for_item(bccx.tcx, fn_id);
206-
let infcx = infer::new_infer_ctxt(bccx.tcx,
207-
&bccx.tcx.tables,
208-
Some(param_env),
209-
ProjectionMode::AnyFinal);
206+
let infcx = InferCtxt::new(bccx.tcx, &bccx.tcx.tables, Some(param_env),
207+
ProjectionMode::AnyFinal);
210208

211209
let mut clcx = CheckLoanCtxt {
212210
bccx: bccx,

src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use borrowck::*;
2020
use borrowck::move_data::MoveData;
2121
use rustc::middle::expr_use_visitor as euv;
22-
use rustc::infer;
22+
use rustc::infer::InferCtxt;
2323
use rustc::middle::mem_categorization as mc;
2424
use rustc::middle::mem_categorization::Categorization;
2525
use rustc::middle::region;
@@ -56,10 +56,8 @@ pub fn gather_loans_in_fn<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
5656
};
5757

5858
let param_env = ty::ParameterEnvironment::for_item(bccx.tcx, fn_id);
59-
let infcx = infer::new_infer_ctxt(bccx.tcx,
60-
&bccx.tcx.tables,
61-
Some(param_env),
62-
ProjectionMode::AnyFinal);
59+
let infcx = InferCtxt::new(bccx.tcx, &bccx.tcx.tables, Some(param_env),
60+
ProjectionMode::AnyFinal);
6361
{
6462
let mut euv = euv::ExprUseVisitor::new(&mut glcx, &infcx);
6563
euv.walk_fn(decl, body);
@@ -529,10 +527,8 @@ struct StaticInitializerCtxt<'a, 'tcx: 'a> {
529527
impl<'a, 'tcx, 'v> Visitor<'v> for StaticInitializerCtxt<'a, 'tcx> {
530528
fn visit_expr(&mut self, ex: &Expr) {
531529
if let hir::ExprAddrOf(mutbl, ref base) = ex.node {
532-
let infcx = infer::new_infer_ctxt(self.bccx.tcx,
533-
&self.bccx.tcx.tables,
534-
None,
535-
ProjectionMode::AnyFinal);
530+
let infcx = InferCtxt::new(self.bccx.tcx, &self.bccx.tcx.tables, None,
531+
ProjectionMode::AnyFinal);
536532
let mc = mc::MemCategorizationContext::new(&infcx);
537533
let base_cmt = mc.cat_expr(&base).unwrap();
538534
let borrow_kind = ty::BorrowKind::from_mutbl(mutbl);

src/librustc_const_eval/check_match.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc::hir::def_id::{DefId};
2222
use rustc::middle::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor};
2323
use rustc::middle::expr_use_visitor::{LoanCause, MutateMode};
2424
use rustc::middle::expr_use_visitor as euv;
25-
use rustc::infer;
25+
use rustc::infer::InferCtxt;
2626
use rustc::middle::mem_categorization::{cmt};
2727
use rustc::hir::pat_util::*;
2828
use rustc::traits::ProjectionMode;
@@ -1123,10 +1123,9 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
11231123
PatKind::Ident(hir::BindByValue(_), _, ref sub) => {
11241124
let pat_ty = tcx.node_id_to_type(p.id);
11251125
//FIXME: (@jroesch) this code should be floated up as well
1126-
let infcx = infer::new_infer_ctxt(cx.tcx,
1127-
&cx.tcx.tables,
1128-
Some(cx.param_env.clone()),
1129-
ProjectionMode::AnyFinal);
1126+
let infcx = InferCtxt::new(cx.tcx, &cx.tcx.tables,
1127+
Some(cx.param_env.clone()),
1128+
ProjectionMode::AnyFinal);
11301129
if infcx.type_moves_by_default(pat_ty, pat.span) {
11311130
check_move(p, sub.as_ref().map(|p| &**p));
11321131
}
@@ -1155,10 +1154,9 @@ fn check_for_mutation_in_guard<'a, 'tcx>(cx: &'a MatchCheckCtxt<'a, 'tcx>,
11551154
cx: cx,
11561155
};
11571156

1158-
let infcx = infer::new_infer_ctxt(cx.tcx,
1159-
&cx.tcx.tables,
1160-
Some(checker.cx.param_env.clone()),
1161-
ProjectionMode::AnyFinal);
1157+
let infcx = InferCtxt::new(cx.tcx, &cx.tcx.tables,
1158+
Some(checker.cx.param_env.clone()),
1159+
ProjectionMode::AnyFinal);
11621160

11631161
let mut visitor = ExprUseVisitor::new(&mut checker, &infcx);
11641162
visitor.walk_expr(guard);

src/librustc_const_eval/eval.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use self::EvalHint::*;
1818
use rustc::hir::map as ast_map;
1919
use rustc::hir::map::blocks::FnLikeNode;
2020
use rustc::middle::cstore::{self, InlinedItem};
21-
use rustc::{infer, traits};
21+
use rustc::traits;
22+
use rustc::infer::InferCtxt;
2223
use rustc::hir::def::Def;
2324
use rustc::hir::def_id::DefId;
2425
use rustc::hir::pat_util::def_to_path;
@@ -1010,7 +1011,7 @@ fn resolve_trait_associated_const<'a, 'tcx: 'a>(tcx: &'a TyCtxt<'tcx>,
10101011
trait_ref);
10111012

10121013
tcx.populate_implementations_for_trait_if_necessary(trait_ref.def_id());
1013-
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, ProjectionMode::AnyFinal);
1014+
let infcx = InferCtxt::new(tcx, &tcx.tables, None, ProjectionMode::AnyFinal);
10141015

10151016
let mut selcx = traits::SelectionContext::new(&infcx);
10161017
let obligation = traits::Obligation::new(traits::ObligationCause::dummy(),

src/librustc_driver/test.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,8 @@ fn test_env<F>(source_string: &str,
149149
index,
150150
"test_crate",
151151
|tcx| {
152-
let infcx = infer::new_infer_ctxt(tcx,
153-
&tcx.tables,
154-
None,
155-
ProjectionMode::AnyFinal);
152+
let infcx = InferCtxt::new(tcx, &tcx.tables, None,
153+
ProjectionMode::AnyFinal);
156154
body(Env { infcx: &infcx });
157155
let free_regions = FreeRegionMap::new();
158156
infcx.resolve_regions_and_report_errors(&free_regions,

src/librustc_lint/builtin.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
use rustc::hir::def::Def;
3232
use rustc::hir::def_id::DefId;
3333
use middle::stability;
34-
use rustc::{cfg, infer};
34+
use rustc::cfg;
35+
use rustc::infer::InferCtxt;
3536
use rustc::ty::subst::Substs;
3637
use rustc::ty::{self, Ty, TyCtxt};
3738
use rustc::ty::adjustment;
@@ -869,10 +870,8 @@ impl LateLintPass for UnconditionalRecursion {
869870
let node_id = tcx.map.as_local_node_id(method.def_id).unwrap();
870871

871872
let param_env = ty::ParameterEnvironment::for_item(tcx, node_id);
872-
let infcx = infer::new_infer_ctxt(tcx,
873-
&tcx.tables,
874-
Some(param_env),
875-
ProjectionMode::AnyFinal);
873+
let infcx = InferCtxt::new(tcx, &tcx.tables, Some(param_env),
874+
ProjectionMode::AnyFinal);
876875
let mut selcx = traits::SelectionContext::new(&infcx);
877876
match selcx.select(&obligation) {
878877
// The method comes from a `T: Trait` bound.

src/librustc_mir/mir_map.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use pretty;
2424
use hair::cx::Cx;
2525

2626
use rustc::mir::mir_map::MirMap;
27-
use rustc::infer;
27+
use rustc::infer::InferCtxt;
2828
use rustc::traits::ProjectionMode;
2929
use rustc::ty::{self, Ty, TyCtxt};
3030
use rustc::util::nodemap::NodeMap;
@@ -75,10 +75,9 @@ impl<'a, 'tcx> BuildMir<'a, 'tcx> {
7575
};
7676

7777
let param_env = ty::ParameterEnvironment::for_item(self.tcx, src.item_id());
78-
let infcx = infer::new_infer_ctxt(self.tcx,
79-
&self.tcx.tables,
80-
Some(param_env),
81-
ProjectionMode::AnyFinal);
78+
79+
let infcx = InferCtxt::new(self.tcx, &self.tcx.tables, Some(param_env),
80+
ProjectionMode::AnyFinal);
8281

8382
let (mir, scope_auxiliary) = f(Cx::new(&infcx, constness));
8483

0 commit comments

Comments
 (0)