Skip to content

Commit e88df94

Browse files
Use &mut for CombineFields in inference relations
1 parent dddaf34 commit e88df94

File tree

9 files changed

+58
-78
lines changed

9 files changed

+58
-78
lines changed

src/librustc/infer/bivariate.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ use ty::{self, Ty, TyCtxt};
3232
use ty::TyVar;
3333
use ty::relate::{Relate, RelateResult, TypeRelation};
3434

35-
pub struct Bivariate<'infcx, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
36-
fields: CombineFields<'infcx, 'gcx, 'tcx>,
35+
pub struct Bivariate<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
36+
fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
3737
a_is_expected: bool,
3838
}
3939

40-
impl<'infcx, 'gcx, 'tcx> Bivariate<'infcx, 'gcx, 'tcx> {
41-
pub fn new(fields: CombineFields<'infcx, 'gcx, 'tcx>, a_is_expected: bool) -> Bivariate<'infcx, 'gcx, 'tcx> {
40+
impl<'combine, 'infcx, 'gcx, 'tcx> Bivariate<'combine, 'infcx, 'gcx, 'tcx> {
41+
pub fn new(fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>, a_is_expected: bool) -> Bivariate<'combine, 'infcx, 'gcx, 'tcx> {
4242
Bivariate { fields: fields, a_is_expected: a_is_expected }
4343
}
4444
}
4545

46-
impl<'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx> for Bivariate<'infcx, 'gcx, 'tcx> {
46+
impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx> for Bivariate<'combine, 'infcx, 'gcx, 'tcx> {
4747
fn tag(&self) -> &'static str { "Bivariate" }
4848

4949
fn tcx(&self) -> TyCtxt<'infcx, 'gcx, 'tcx> { self.fields.tcx() }

src/librustc/infer/combine.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -154,27 +154,27 @@ impl<'infcx, 'gcx, 'tcx> CombineFields<'infcx, 'gcx, 'tcx> {
154154
self.infcx.tcx
155155
}
156156

157-
pub fn equate(&self, a_is_expected: bool) -> Equate<'infcx, 'gcx, 'tcx> {
158-
Equate::new(self.clone(), a_is_expected)
157+
pub fn equate<'a>(&'a mut self, a_is_expected: bool) -> Equate<'a, 'infcx, 'gcx, 'tcx> {
158+
Equate::new(self, a_is_expected)
159159
}
160160

161-
pub fn bivariate(&self, a_is_expected: bool) -> Bivariate<'infcx, 'gcx, 'tcx> {
162-
Bivariate::new(self.clone(), a_is_expected)
161+
pub fn bivariate<'a>(&'a mut self, a_is_expected: bool) -> Bivariate<'a, 'infcx, 'gcx, 'tcx> {
162+
Bivariate::new(self, a_is_expected)
163163
}
164164

165-
pub fn sub(&self, a_is_expected: bool) -> Sub<'infcx, 'gcx, 'tcx> {
166-
Sub::new(self.clone(), a_is_expected)
165+
pub fn sub<'a>(&'a mut self, a_is_expected: bool) -> Sub<'a, 'infcx, 'gcx, 'tcx> {
166+
Sub::new(self, a_is_expected)
167167
}
168168

169-
pub fn lub(&self, a_is_expected: bool) -> Lub<'infcx, 'gcx, 'tcx> {
170-
Lub::new(self.clone(), a_is_expected)
169+
pub fn lub<'a>(&'a mut self, a_is_expected: bool) -> Lub<'a, 'infcx, 'gcx, 'tcx> {
170+
Lub::new(self, a_is_expected)
171171
}
172172

173-
pub fn glb(&self, a_is_expected: bool) -> Glb<'infcx, 'gcx, 'tcx> {
174-
Glb::new(self.clone(), a_is_expected)
173+
pub fn glb<'a>(&'a mut self, a_is_expected: bool) -> Glb<'a, 'infcx, 'gcx, 'tcx> {
174+
Glb::new(self, a_is_expected)
175175
}
176176

177-
pub fn instantiate(&self,
177+
pub fn instantiate(&mut self,
178178
a_ty: Ty<'tcx>,
179179
dir: RelationDir,
180180
b_vid: ty::TyVid,

src/librustc/infer/equate.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,20 @@ use super::type_variable::{EqTo};
1515
use ty::{self, Ty, TyCtxt};
1616
use ty::TyVar;
1717
use ty::relate::{Relate, RelateResult, TypeRelation};
18-
use traits::PredicateObligations;
1918

2019
/// Ensures `a` is made equal to `b`. Returns `a` on success.
21-
pub struct Equate<'infcx, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
22-
fields: CombineFields<'infcx, 'gcx, 'tcx>,
20+
pub struct Equate<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
21+
fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
2322
a_is_expected: bool,
2423
}
2524

26-
impl<'infcx, 'gcx, 'tcx> Equate<'infcx, 'gcx, 'tcx> {
27-
pub fn new(fields: CombineFields<'infcx, 'gcx, 'tcx>, a_is_expected: bool) -> Equate<'infcx, 'gcx, 'tcx> {
25+
impl<'combine, 'infcx, 'gcx, 'tcx> Equate<'combine, 'infcx, 'gcx, 'tcx> {
26+
pub fn new(fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>, a_is_expected: bool) -> Equate<'combine, 'infcx, 'gcx, 'tcx> {
2827
Equate { fields: fields, a_is_expected: a_is_expected }
2928
}
30-
31-
pub fn obligations(self) -> PredicateObligations<'tcx> {
32-
self.fields.obligations
33-
}
3429
}
3530

36-
impl<'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx> for Equate<'infcx, 'gcx, 'tcx> {
31+
impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx> for Equate<'combine, 'infcx, 'gcx, 'tcx> {
3732
fn tag(&self) -> &'static str { "Equate" }
3833

3934
fn tcx(&self) -> TyCtxt<'infcx, 'gcx, 'tcx> { self.fields.tcx() }

src/librustc/infer/glb.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,20 @@ use super::Subtype;
1515

1616
use ty::{self, Ty, TyCtxt};
1717
use ty::relate::{Relate, RelateResult, TypeRelation};
18-
use traits::PredicateObligations;
1918

2019
/// "Greatest lower bound" (common subtype)
21-
pub struct Glb<'infcx, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
22-
fields: CombineFields<'infcx, 'gcx, 'tcx>,
20+
pub struct Glb<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
21+
fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
2322
a_is_expected: bool,
2423
}
2524

26-
impl<'infcx, 'gcx, 'tcx> Glb<'infcx, 'gcx, 'tcx> {
27-
pub fn new(fields: CombineFields<'infcx, 'gcx, 'tcx>, a_is_expected: bool) -> Glb<'infcx, 'gcx, 'tcx> {
25+
impl<'combine, 'infcx, 'gcx, 'tcx> Glb<'combine, 'infcx, 'gcx, 'tcx> {
26+
pub fn new(fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>, a_is_expected: bool) -> Glb<'combine, 'infcx, 'gcx, 'tcx> {
2827
Glb { fields: fields, a_is_expected: a_is_expected }
2928
}
30-
31-
pub fn obligations(self) -> PredicateObligations<'tcx> {
32-
self.fields.obligations
33-
}
3429
}
3530

36-
impl<'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx> for Glb<'infcx, 'gcx, 'tcx> {
31+
impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx> for Glb<'combine, 'infcx, 'gcx, 'tcx> {
3732
fn tag(&self) -> &'static str { "Glb" }
3833

3934
fn tcx(&self) -> TyCtxt<'infcx, 'gcx, 'tcx> { self.fields.tcx() }
@@ -76,12 +71,12 @@ impl<'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx> for Glb<'infcx, 'gcx,
7671
}
7772
}
7873

79-
impl<'infcx, 'gcx, 'tcx> LatticeDir<'infcx, 'gcx, 'tcx> for Glb<'infcx, 'gcx, 'tcx> {
74+
impl<'combine, 'infcx, 'gcx, 'tcx> LatticeDir<'infcx, 'gcx, 'tcx> for Glb<'combine, 'infcx, 'gcx, 'tcx> {
8075
fn infcx(&self) -> &'infcx InferCtxt<'infcx, 'gcx, 'tcx> {
8176
self.fields.infcx
8277
}
8378

84-
fn relate_bound(&self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
79+
fn relate_bound(&mut self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
8580
let mut sub = self.fields.sub(self.a_is_expected);
8681
sub.relate(&v, &a)?;
8782
sub.relate(&v, &b)?;

src/librustc/infer/higher_ranked/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct HrMatchResult<U> {
4040
}
4141

4242
impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
43-
pub fn higher_ranked_sub<T>(&self, a: &Binder<T>, b: &Binder<T>, a_is_expected: bool)
43+
pub fn higher_ranked_sub<T>(&mut self, a: &Binder<T>, b: &Binder<T>, a_is_expected: bool)
4444
-> RelateResult<'tcx, Binder<T>>
4545
where T: Relate<'tcx>
4646
{
@@ -106,7 +106,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
106106
/// NB. It should not happen that there are LBR appearing in `U`
107107
/// that do not appear in `T`. If that happens, those regions are
108108
/// unconstrained, and this routine replaces them with `'static`.
109-
pub fn higher_ranked_match<T, U>(&self,
109+
pub fn higher_ranked_match<T, U>(&mut self,
110110
span: Span,
111111
a_pair: &Binder<(T, U)>,
112112
b_match: &T,
@@ -222,7 +222,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
222222
});
223223
}
224224

225-
pub fn higher_ranked_lub<T>(&self, a: &Binder<T>, b: &Binder<T>, a_is_expected: bool)
225+
pub fn higher_ranked_lub<T>(&mut self, a: &Binder<T>, b: &Binder<T>, a_is_expected: bool)
226226
-> RelateResult<'tcx, Binder<T>>
227227
where T: Relate<'tcx>
228228
{
@@ -312,7 +312,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
312312
}
313313
}
314314

315-
pub fn higher_ranked_glb<T>(&self, a: &Binder<T>, b: &Binder<T>, a_is_expected: bool)
315+
pub fn higher_ranked_glb<T>(&mut self, a: &Binder<T>, b: &Binder<T>, a_is_expected: bool)
316316
-> RelateResult<'tcx, Binder<T>>
317317
where T: Relate<'tcx>
318318
{

src/librustc/infer/lattice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub trait LatticeDir<'f, 'gcx: 'f+'tcx, 'tcx: 'f> : TypeRelation<'f, 'gcx, 'tcx>
4040

4141
// Relates the type `v` to `a` and `b` such that `v` represents
4242
// the LUB/GLB of `a` and `b` as appropriate.
43-
fn relate_bound(&self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()>;
43+
fn relate_bound(&mut self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()>;
4444
}
4545

4646
pub fn super_lattice_tys<'a, 'gcx, 'tcx, L>(this: &mut L,

src/librustc/infer/lub.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,20 @@ use super::Subtype;
1515

1616
use ty::{self, Ty, TyCtxt};
1717
use ty::relate::{Relate, RelateResult, TypeRelation};
18-
use traits::PredicateObligations;
1918

2019
/// "Least upper bound" (common supertype)
21-
pub struct Lub<'infcx, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
22-
fields: CombineFields<'infcx, 'gcx, 'tcx>,
20+
pub struct Lub<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
21+
fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
2322
a_is_expected: bool,
2423
}
2524

26-
impl<'infcx, 'gcx, 'tcx> Lub<'infcx, 'gcx, 'tcx> {
27-
pub fn new(fields: CombineFields<'infcx, 'gcx, 'tcx>, a_is_expected: bool) -> Lub<'infcx, 'gcx, 'tcx> {
25+
impl<'combine, 'infcx, 'gcx, 'tcx> Lub<'combine, 'infcx, 'gcx, 'tcx> {
26+
pub fn new(fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>, a_is_expected: bool) -> Lub<'combine, 'infcx, 'gcx, 'tcx> {
2827
Lub { fields: fields, a_is_expected: a_is_expected }
2928
}
30-
31-
pub fn obligations(self) -> PredicateObligations<'tcx> {
32-
self.fields.obligations
33-
}
3429
}
3530

36-
impl<'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx> for Lub<'infcx, 'gcx, 'tcx> {
31+
impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx> for Lub<'combine, 'infcx, 'gcx, 'tcx> {
3732
fn tag(&self) -> &'static str { "Lub" }
3833

3934
fn tcx(&self) -> TyCtxt<'infcx, 'gcx, 'tcx> { self.fields.tcx() }
@@ -76,12 +71,12 @@ impl<'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx> for Lub<'infcx, 'gcx,
7671
}
7772
}
7873

79-
impl<'infcx, 'gcx, 'tcx> LatticeDir<'infcx, 'gcx, 'tcx> for Lub<'infcx, 'gcx, 'tcx> {
74+
impl<'combine, 'infcx, 'gcx, 'tcx> LatticeDir<'infcx, 'gcx, 'tcx> for Lub<'combine, 'infcx, 'gcx, 'tcx> {
8075
fn infcx(&self) -> &'infcx InferCtxt<'infcx, 'gcx, 'tcx> {
8176
self.fields.infcx
8277
}
8378

84-
fn relate_bound(&self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
79+
fn relate_bound(&mut self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
8580
let mut sub = self.fields.sub(self.a_is_expected);
8681
sub.relate(&a, &v)?;
8782
sub.relate(&b, &v)?;

src/librustc/infer/mod.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -813,36 +813,36 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
813813
-> InferResult<'tcx, T>
814814
where T: Relate<'tcx>
815815
{
816-
let mut equate = self.combine_fields(trace).equate(a_is_expected);
817-
let result = equate.relate(a, b);
818-
result.map(|t| InferOk { value: t, obligations: equate.obligations() })
816+
let mut fields = self.combine_fields(trace);
817+
let result = fields.equate(a_is_expected).relate(a, b);
818+
result.map(move |t| InferOk { value: t, obligations: fields.obligations })
819819
}
820820

821821
pub fn sub<T>(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>, a: &T, b: &T)
822822
-> InferResult<'tcx, T>
823823
where T: Relate<'tcx>
824824
{
825-
let mut sub = self.combine_fields(trace).sub(a_is_expected);
826-
let result = sub.relate(a, b);
827-
result.map(|t| InferOk { value: t, obligations: sub.obligations() })
825+
let mut fields = self.combine_fields(trace);
826+
let result = fields.sub(a_is_expected).relate(a, b);
827+
result.map(move |t| InferOk { value: t, obligations: fields.obligations })
828828
}
829829

830830
pub fn lub<T>(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>, a: &T, b: &T)
831831
-> InferResult<'tcx, T>
832832
where T: Relate<'tcx>
833833
{
834-
let mut lub = self.combine_fields(trace).lub(a_is_expected);
835-
let result = lub.relate(a, b);
836-
result.map(|t| InferOk { value: t, obligations: lub.obligations() })
834+
let mut fields = self.combine_fields(trace);
835+
let result = fields.lub(a_is_expected).relate(a, b);
836+
result.map(move |t| InferOk { value: t, obligations: fields.obligations })
837837
}
838838

839839
pub fn glb<T>(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>, a: &T, b: &T)
840840
-> InferResult<'tcx, T>
841841
where T: Relate<'tcx>
842842
{
843-
let mut glb = self.combine_fields(trace).glb(a_is_expected);
844-
let result = glb.relate(a, b);
845-
result.map(|t| InferOk { value: t, obligations: glb.obligations() })
843+
let mut fields = self.combine_fields(trace);
844+
let result = fields.glb(a_is_expected).relate(a, b);
845+
result.map(move |t| InferOk { value: t, obligations: fields.obligations })
846846
}
847847

848848
fn start_snapshot(&self) -> CombinedSnapshot {
@@ -1645,7 +1645,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
16451645
};
16461646

16471647
let match_pair = match_a.map_bound(|p| (p.projection_ty.trait_ref, p.ty));
1648-
let combine = self.combine_fields(trace);
1648+
let mut combine = self.combine_fields(trace);
16491649
let result = combine.higher_ranked_match(span, &match_pair, &match_b, true)?;
16501650
Ok(InferOk { value: result, obligations: combine.obligations })
16511651
}

src/librustc/infer/sub.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,19 @@ use super::type_variable::{SubtypeOf, SupertypeOf};
1515
use ty::{self, Ty, TyCtxt};
1616
use ty::TyVar;
1717
use ty::relate::{Cause, Relate, RelateResult, TypeRelation};
18-
use traits::PredicateObligations;
1918
use std::mem;
2019

2120
/// Ensures `a` is made a subtype of `b`. Returns `a` on success.
22-
pub struct Sub<'infcx, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
23-
fields: CombineFields<'infcx, 'gcx, 'tcx>,
21+
pub struct Sub<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
22+
fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
2423
a_is_expected: bool,
2524
}
2625

27-
impl<'infcx, 'gcx, 'tcx> Sub<'infcx, 'gcx, 'tcx> {
28-
pub fn new(f: CombineFields<'infcx, 'gcx, 'tcx>, a_is_expected: bool) -> Sub<'infcx, 'gcx, 'tcx> {
26+
impl<'combine, 'infcx, 'gcx, 'tcx> Sub<'combine, 'infcx, 'gcx, 'tcx> {
27+
pub fn new(f: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>, a_is_expected: bool) -> Sub<'combine, 'infcx, 'gcx, 'tcx> {
2928
Sub { fields: f, a_is_expected: a_is_expected }
3029
}
3130

32-
pub fn obligations(self) -> PredicateObligations<'tcx> {
33-
self.fields.obligations
34-
}
35-
3631
fn with_expected_switched<R, F: FnOnce(&mut Self) -> R>(&mut self, f: F) -> R {
3732
self.a_is_expected = !self.a_is_expected;
3833
let result = f(self);
@@ -41,7 +36,7 @@ impl<'infcx, 'gcx, 'tcx> Sub<'infcx, 'gcx, 'tcx> {
4136
}
4237
}
4338

44-
impl<'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx> for Sub<'infcx, 'gcx, 'tcx> {
39+
impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx> for Sub<'combine, 'infcx, 'gcx, 'tcx> {
4540
fn tag(&self) -> &'static str { "Sub" }
4641
fn tcx(&self) -> TyCtxt<'infcx, 'gcx, 'tcx> { self.fields.infcx.tcx }
4742
fn a_is_expected(&self) -> bool { self.a_is_expected }

0 commit comments

Comments
 (0)