Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f8ea24e

Browse files
committedMay 11, 2016
rustc: Avoid free functions taking &TyCtxt and &InferCtxt.
1 parent d7ee56e commit f8ea24e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+765
-1003
lines changed
 

‎src/librustc/infer/bivariate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
//! In particular, it might be enough to say (A,B) are bivariant for
2626
//! all (A,B).
2727
28-
use super::combine::{self, CombineFields};
28+
use super::combine::CombineFields;
2929
use super::type_variable::{BiTo};
3030

3131
use ty::{self, Ty, TyCtxt};
@@ -96,7 +96,7 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Bivariate<'a, 'tcx> {
9696
}
9797

9898
_ => {
99-
combine::super_combine_tys(self.fields.infcx, self, a, b)
99+
self.fields.infcx.super_combine_tys(self, a, b)
100100
}
101101
}
102102
}

‎src/librustc/infer/combine.rs

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -60,50 +60,51 @@ pub struct CombineFields<'a, 'tcx: 'a> {
6060
pub obligations: PredicateObligations<'tcx>,
6161
}
6262

63-
pub fn super_combine_tys<'a,'tcx:'a,R>(infcx: &InferCtxt<'a, 'tcx>,
64-
relation: &mut R,
65-
a: Ty<'tcx>,
66-
b: Ty<'tcx>)
67-
-> RelateResult<'tcx, Ty<'tcx>>
63+
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
64+
pub fn super_combine_tys<R>(&self,
65+
relation: &mut R,
66+
a: Ty<'tcx>,
67+
b: Ty<'tcx>)
68+
-> RelateResult<'tcx, Ty<'tcx>>
6869
where R: TypeRelation<'a,'tcx>
6970
{
7071
let a_is_expected = relation.a_is_expected();
7172

7273
match (&a.sty, &b.sty) {
7374
// Relate integral variables to other types
7475
(&ty::TyInfer(ty::IntVar(a_id)), &ty::TyInfer(ty::IntVar(b_id))) => {
75-
infcx.int_unification_table
76-
.borrow_mut()
77-
.unify_var_var(a_id, b_id)
78-
.map_err(|e| int_unification_error(a_is_expected, e))?;
76+
self.int_unification_table
77+
.borrow_mut()
78+
.unify_var_var(a_id, b_id)
79+
.map_err(|e| int_unification_error(a_is_expected, e))?;
7980
Ok(a)
8081
}
8182
(&ty::TyInfer(ty::IntVar(v_id)), &ty::TyInt(v)) => {
82-
unify_integral_variable(infcx, a_is_expected, v_id, IntType(v))
83+
self.unify_integral_variable(a_is_expected, v_id, IntType(v))
8384
}
8485
(&ty::TyInt(v), &ty::TyInfer(ty::IntVar(v_id))) => {
85-
unify_integral_variable(infcx, !a_is_expected, v_id, IntType(v))
86+
self.unify_integral_variable(!a_is_expected, v_id, IntType(v))
8687
}
8788
(&ty::TyInfer(ty::IntVar(v_id)), &ty::TyUint(v)) => {
88-
unify_integral_variable(infcx, a_is_expected, v_id, UintType(v))
89+
self.unify_integral_variable(a_is_expected, v_id, UintType(v))
8990
}
9091
(&ty::TyUint(v), &ty::TyInfer(ty::IntVar(v_id))) => {
91-
unify_integral_variable(infcx, !a_is_expected, v_id, UintType(v))
92+
self.unify_integral_variable(!a_is_expected, v_id, UintType(v))
9293
}
9394

9495
// Relate floating-point variables to other types
9596
(&ty::TyInfer(ty::FloatVar(a_id)), &ty::TyInfer(ty::FloatVar(b_id))) => {
96-
infcx.float_unification_table
97-
.borrow_mut()
98-
.unify_var_var(a_id, b_id)
99-
.map_err(|e| float_unification_error(relation.a_is_expected(), e))?;
97+
self.float_unification_table
98+
.borrow_mut()
99+
.unify_var_var(a_id, b_id)
100+
.map_err(|e| float_unification_error(relation.a_is_expected(), e))?;
100101
Ok(a)
101102
}
102103
(&ty::TyInfer(ty::FloatVar(v_id)), &ty::TyFloat(v)) => {
103-
unify_float_variable(infcx, a_is_expected, v_id, v)
104+
self.unify_float_variable(a_is_expected, v_id, v)
104105
}
105106
(&ty::TyFloat(v), &ty::TyInfer(ty::FloatVar(v_id))) => {
106-
unify_float_variable(infcx, !a_is_expected, v_id, v)
107+
self.unify_float_variable(!a_is_expected, v_id, v)
107108
}
108109

109110
// All other cases of inference are errors
@@ -119,33 +120,34 @@ pub fn super_combine_tys<'a,'tcx:'a,R>(infcx: &InferCtxt<'a, 'tcx>,
119120
}
120121
}
121122

122-
fn unify_integral_variable<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
123-
vid_is_expected: bool,
124-
vid: ty::IntVid,
125-
val: ty::IntVarValue)
126-
-> RelateResult<'tcx, Ty<'tcx>>
123+
fn unify_integral_variable(&self,
124+
vid_is_expected: bool,
125+
vid: ty::IntVid,
126+
val: ty::IntVarValue)
127+
-> RelateResult<'tcx, Ty<'tcx>>
127128
{
128-
infcx.int_unification_table
129-
.borrow_mut()
130-
.unify_var_value(vid, val)
131-
.map_err(|e| int_unification_error(vid_is_expected, e))?;
129+
self.int_unification_table
130+
.borrow_mut()
131+
.unify_var_value(vid, val)
132+
.map_err(|e| int_unification_error(vid_is_expected, e))?;
132133
match val {
133-
IntType(v) => Ok(infcx.tcx.mk_mach_int(v)),
134-
UintType(v) => Ok(infcx.tcx.mk_mach_uint(v)),
134+
IntType(v) => Ok(self.tcx.mk_mach_int(v)),
135+
UintType(v) => Ok(self.tcx.mk_mach_uint(v)),
135136
}
136137
}
137138

138-
fn unify_float_variable<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
139-
vid_is_expected: bool,
140-
vid: ty::FloatVid,
141-
val: ast::FloatTy)
142-
-> RelateResult<'tcx, Ty<'tcx>>
139+
fn unify_float_variable(&self,
140+
vid_is_expected: bool,
141+
vid: ty::FloatVid,
142+
val: ast::FloatTy)
143+
-> RelateResult<'tcx, Ty<'tcx>>
143144
{
144-
infcx.float_unification_table
145-
.borrow_mut()
146-
.unify_var_value(vid, val)
147-
.map_err(|e| float_unification_error(vid_is_expected, e))?;
148-
Ok(infcx.tcx.mk_mach_float(val))
145+
self.float_unification_table
146+
.borrow_mut()
147+
.unify_var_value(vid, val)
148+
.map_err(|e| float_unification_error(vid_is_expected, e))?;
149+
Ok(self.tcx.mk_mach_float(val))
150+
}
149151
}
150152

151153
impl<'a, 'tcx> CombineFields<'a, 'tcx> {

0 commit comments

Comments
 (0)
Please sign in to comment.