Skip to content

Commit 748ecb1

Browse files
authored
Auto merge of #35086 - Manishearth:rollup, r=Manishearth
Rollup of 7 pull requests - Successful merges: #34951, #34963, #34969, #35013, #35037, #35040, #35058 - Failed merges:
2 parents cec262e + bc283bb commit 748ecb1

File tree

18 files changed

+242
-156
lines changed

18 files changed

+242
-156
lines changed

src/librustc/infer/bivariate.rs

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

35-
pub struct Bivariate<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
36-
fields: CombineFields<'a, 'gcx, 'tcx>
35+
pub struct Bivariate<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
36+
fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
37+
a_is_expected: bool,
3738
}
3839

39-
impl<'a, 'gcx, 'tcx> Bivariate<'a, 'gcx, 'tcx> {
40-
pub fn new(fields: CombineFields<'a, 'gcx, 'tcx>) -> Bivariate<'a, 'gcx, 'tcx> {
41-
Bivariate { fields: fields }
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)
42+
-> Bivariate<'combine, 'infcx, 'gcx, 'tcx>
43+
{
44+
Bivariate { fields: fields, a_is_expected: a_is_expected }
4245
}
4346
}
4447

45-
impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Bivariate<'a, 'gcx, 'tcx> {
48+
impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
49+
for Bivariate<'combine, 'infcx, 'gcx, 'tcx>
50+
{
4651
fn tag(&self) -> &'static str { "Bivariate" }
4752

48-
fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> { self.fields.tcx() }
53+
fn tcx(&self) -> TyCtxt<'infcx, 'gcx, 'tcx> { self.fields.tcx() }
4954

50-
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
55+
fn a_is_expected(&self) -> bool { self.a_is_expected }
5156

5257
fn relate_with_variance<T: Relate<'tcx>>(&mut self,
5358
variance: ty::Variance,
@@ -86,12 +91,12 @@ impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Bivariate<'a, 'gcx, 'tcx>
8691
}
8792

8893
(&ty::TyInfer(TyVar(a_id)), _) => {
89-
self.fields.instantiate(b, BiTo, a_id)?;
94+
self.fields.instantiate(b, BiTo, a_id, self.a_is_expected)?;
9095
Ok(a)
9196
}
9297

9398
(_, &ty::TyInfer(TyVar(b_id))) => {
94-
self.fields.instantiate(a, BiTo, b_id)?;
99+
self.fields.instantiate(a, BiTo, b_id, self.a_is_expected)?;
95100
Ok(a)
96101
}
97102

src/librustc/infer/combine.rs

+24-30
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,20 @@ use syntax::ast;
5252
use syntax_pos::Span;
5353

5454
#[derive(Clone)]
55-
pub struct CombineFields<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
56-
pub infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
57-
pub a_is_expected: bool,
55+
pub struct CombineFields<'infcx, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
56+
pub infcx: &'infcx InferCtxt<'infcx, 'gcx, 'tcx>,
5857
pub trace: TypeTrace<'tcx>,
5958
pub cause: Option<ty::relate::Cause>,
6059
pub obligations: PredicateObligations<'tcx>,
6160
}
6261

63-
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
62+
impl<'infcx, 'gcx, 'tcx> InferCtxt<'infcx, 'gcx, 'tcx> {
6463
pub fn super_combine_tys<R>(&self,
6564
relation: &mut R,
6665
a: Ty<'tcx>,
6766
b: Ty<'tcx>)
6867
-> RelateResult<'tcx, Ty<'tcx>>
69-
where R: TypeRelation<'a, 'gcx, 'tcx>
68+
where R: TypeRelation<'infcx, 'gcx, 'tcx>
7069
{
7170
let a_is_expected = relation.a_is_expected();
7271

@@ -150,42 +149,36 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
150149
}
151150
}
152151

153-
impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
154-
pub fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> {
152+
impl<'infcx, 'gcx, 'tcx> CombineFields<'infcx, 'gcx, 'tcx> {
153+
pub fn tcx(&self) -> TyCtxt<'infcx, 'gcx, 'tcx> {
155154
self.infcx.tcx
156155
}
157156

158-
pub fn switch_expected(&self) -> CombineFields<'a, 'gcx, 'tcx> {
159-
CombineFields {
160-
a_is_expected: !self.a_is_expected,
161-
..(*self).clone()
162-
}
163-
}
164-
165-
pub fn equate(&self) -> Equate<'a, 'gcx, 'tcx> {
166-
Equate::new(self.clone())
157+
pub fn equate<'a>(&'a mut self, a_is_expected: bool) -> Equate<'a, 'infcx, 'gcx, 'tcx> {
158+
Equate::new(self, a_is_expected)
167159
}
168160

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

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

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

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

185-
pub fn instantiate(&self,
177+
pub fn instantiate(&mut self,
186178
a_ty: Ty<'tcx>,
187179
dir: RelationDir,
188-
b_vid: ty::TyVid)
180+
b_vid: ty::TyVid,
181+
a_is_expected: bool)
189182
-> RelateResult<'tcx, ()>
190183
{
191184
let mut stack = Vec::new();
@@ -255,10 +248,11 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
255248
// to associate causes/spans with each of the relations in
256249
// the stack to get this right.
257250
match dir {
258-
BiTo => self.bivariate().relate(&a_ty, &b_ty),
259-
EqTo => self.equate().relate(&a_ty, &b_ty),
260-
SubtypeOf => self.sub().relate(&a_ty, &b_ty),
261-
SupertypeOf => self.sub().relate_with_variance(ty::Contravariant, &a_ty, &b_ty),
251+
BiTo => self.bivariate(a_is_expected).relate(&a_ty, &b_ty),
252+
EqTo => self.equate(a_is_expected).relate(&a_ty, &b_ty),
253+
SubtypeOf => self.sub(a_is_expected).relate(&a_ty, &b_ty),
254+
SupertypeOf => self.sub(a_is_expected).relate_with_variance(
255+
ty::Contravariant, &a_ty, &b_ty),
262256
}?;
263257
}
264258

src/librustc/infer/equate.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,29 @@ 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<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
22-
fields: CombineFields<'a, 'gcx, 'tcx>
20+
pub struct Equate<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
21+
fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
22+
a_is_expected: bool,
2323
}
2424

25-
impl<'a, 'gcx, 'tcx> Equate<'a, 'gcx, 'tcx> {
26-
pub fn new(fields: CombineFields<'a, 'gcx, 'tcx>) -> Equate<'a, 'gcx, 'tcx> {
27-
Equate { fields: fields }
28-
}
29-
30-
pub fn obligations(self) -> PredicateObligations<'tcx> {
31-
self.fields.obligations
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)
27+
-> Equate<'combine, 'infcx, 'gcx, 'tcx>
28+
{
29+
Equate { fields: fields, a_is_expected: a_is_expected }
3230
}
3331
}
3432

35-
impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Equate<'a, 'gcx, 'tcx> {
33+
impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
34+
for Equate<'combine, 'infcx, 'gcx, 'tcx>
35+
{
3636
fn tag(&self) -> &'static str { "Equate" }
3737

38-
fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> { self.fields.tcx() }
38+
fn tcx(&self) -> TyCtxt<'infcx, 'gcx, 'tcx> { self.fields.tcx() }
3939

40-
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
40+
fn a_is_expected(&self) -> bool { self.a_is_expected }
4141

4242
fn relate_with_variance<T: Relate<'tcx>>(&mut self,
4343
_: ty::Variance,
@@ -63,12 +63,12 @@ impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Equate<'a, 'gcx, 'tcx> {
6363
}
6464

6565
(&ty::TyInfer(TyVar(a_id)), _) => {
66-
self.fields.instantiate(b, EqTo, a_id)?;
66+
self.fields.instantiate(b, EqTo, a_id, self.a_is_expected)?;
6767
Ok(a)
6868
}
6969

7070
(_, &ty::TyInfer(TyVar(b_id))) => {
71-
self.fields.instantiate(a, EqTo, b_id)?;
71+
self.fields.instantiate(a, EqTo, b_id, self.a_is_expected)?;
7272
Ok(a)
7373
}
7474

@@ -93,7 +93,7 @@ impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Equate<'a, 'gcx, 'tcx> {
9393
-> RelateResult<'tcx, ty::Binder<T>>
9494
where T: Relate<'tcx>
9595
{
96-
self.fields.higher_ranked_sub(a, b)?;
97-
self.fields.higher_ranked_sub(b, a)
96+
self.fields.higher_ranked_sub(a, b, self.a_is_expected)?;
97+
self.fields.higher_ranked_sub(b, a, self.a_is_expected)
9898
}
9999
}

src/librustc/infer/glb.rs

+23-21
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,29 @@ 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<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
22-
fields: CombineFields<'a, 'gcx, 'tcx>
20+
pub struct Glb<'combine, 'infcx: 'combine, 'gcx: 'infcx+'tcx, 'tcx: 'infcx> {
21+
fields: &'combine mut CombineFields<'infcx, 'gcx, 'tcx>,
22+
a_is_expected: bool,
2323
}
2424

25-
impl<'a, 'gcx, 'tcx> Glb<'a, 'gcx, 'tcx> {
26-
pub fn new(fields: CombineFields<'a, 'gcx, 'tcx>) -> Glb<'a, 'gcx, 'tcx> {
27-
Glb { fields: fields }
28-
}
29-
30-
pub fn obligations(self) -> PredicateObligations<'tcx> {
31-
self.fields.obligations
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)
27+
-> Glb<'combine, 'infcx, 'gcx, 'tcx>
28+
{
29+
Glb { fields: fields, a_is_expected: a_is_expected }
3230
}
3331
}
3432

35-
impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Glb<'a, 'gcx, 'tcx> {
33+
impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
34+
for Glb<'combine, 'infcx, 'gcx, 'tcx>
35+
{
3636
fn tag(&self) -> &'static str { "Glb" }
3737

38-
fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> { self.fields.tcx() }
38+
fn tcx(&self) -> TyCtxt<'infcx, 'gcx, 'tcx> { self.fields.tcx() }
3939

40-
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
40+
fn a_is_expected(&self) -> bool { self.a_is_expected }
4141

4242
fn relate_with_variance<T: Relate<'tcx>>(&mut self,
4343
variance: ty::Variance,
@@ -46,10 +46,10 @@ impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Glb<'a, 'gcx, 'tcx> {
4646
-> RelateResult<'tcx, T>
4747
{
4848
match variance {
49-
ty::Invariant => self.fields.equate().relate(a, b),
49+
ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b),
5050
ty::Covariant => self.relate(a, b),
51-
ty::Bivariant => self.fields.bivariate().relate(a, b),
52-
ty::Contravariant => self.fields.lub().relate(a, b),
51+
ty::Bivariant => self.fields.bivariate(self.a_is_expected).relate(a, b),
52+
ty::Contravariant => self.fields.lub(self.a_is_expected).relate(a, b),
5353
}
5454
}
5555

@@ -71,17 +71,19 @@ impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Glb<'a, 'gcx, 'tcx> {
7171
-> RelateResult<'tcx, ty::Binder<T>>
7272
where T: Relate<'tcx>
7373
{
74-
self.fields.higher_ranked_glb(a, b)
74+
self.fields.higher_ranked_glb(a, b, self.a_is_expected)
7575
}
7676
}
7777

78-
impl<'a, 'gcx, 'tcx> LatticeDir<'a, 'gcx, 'tcx> for Glb<'a, 'gcx, 'tcx> {
79-
fn infcx(&self) -> &'a InferCtxt<'a, 'gcx, 'tcx> {
78+
impl<'combine, 'infcx, 'gcx, 'tcx> LatticeDir<'infcx, 'gcx, 'tcx>
79+
for Glb<'combine, 'infcx, 'gcx, 'tcx>
80+
{
81+
fn infcx(&self) -> &'infcx InferCtxt<'infcx, 'gcx, 'tcx> {
8082
self.fields.infcx
8183
}
8284

83-
fn relate_bound(&self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
84-
let mut sub = self.fields.sub();
85+
fn relate_bound(&mut self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
86+
let mut sub = self.fields.sub(self.a_is_expected);
8587
sub.relate(&v, &a)?;
8688
sub.relate(&v, &b)?;
8789
Ok(())

src/librustc/infer/higher_ranked/mod.rs

+11-10
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>)
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
{
@@ -77,11 +77,11 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
7777
debug!("b_prime={:?}", b_prime);
7878

7979
// Compare types now that bound regions have been replaced.
80-
let result = self.sub().relate(&a_prime, &b_prime)?;
80+
let result = self.sub(a_is_expected).relate(&a_prime, &b_prime)?;
8181

8282
// Presuming type comparison succeeds, we need to check
8383
// that the skolemized regions do not "leak".
84-
self.infcx.leak_check(!self.a_is_expected, span, &skol_map, snapshot)?;
84+
self.infcx.leak_check(!a_is_expected, span, &skol_map, snapshot)?;
8585

8686
// We are finished with the skolemized regions now so pop
8787
// them off.
@@ -106,10 +106,11 @@ 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)>,
112-
b_match: &T)
112+
b_match: &T,
113+
a_is_expected: bool)
113114
-> RelateResult<'tcx, HrMatchResult<U>>
114115
where T: Relate<'tcx>,
115116
U: TypeFoldable<'tcx>
@@ -129,7 +130,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
129130
debug!("higher_ranked_match: skol_map={:?}", skol_map);
130131

131132
// Equate types now that bound regions have been replaced.
132-
try!(self.equate().relate(&a_match, &b_match));
133+
try!(self.equate(a_is_expected).relate(&a_match, &b_match));
133134

134135
// Map each skolemized region to a vector of other regions that it
135136
// must be equated with. (Note that this vector may include other
@@ -221,7 +222,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
221222
});
222223
}
223224

224-
pub fn higher_ranked_lub<T>(&self, a: &Binder<T>, b: &Binder<T>)
225+
pub fn higher_ranked_lub<T>(&mut self, a: &Binder<T>, b: &Binder<T>, a_is_expected: bool)
225226
-> RelateResult<'tcx, Binder<T>>
226227
where T: Relate<'tcx>
227228
{
@@ -239,7 +240,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
239240

240241
// Collect constraints.
241242
let result0 =
242-
self.lub().relate(&a_with_fresh, &b_with_fresh)?;
243+
self.lub(a_is_expected).relate(&a_with_fresh, &b_with_fresh)?;
243244
let result0 =
244245
self.infcx.resolve_type_vars_if_possible(&result0);
245246
debug!("lub result0 = {:?}", result0);
@@ -311,7 +312,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
311312
}
312313
}
313314

314-
pub fn higher_ranked_glb<T>(&self, a: &Binder<T>, b: &Binder<T>)
315+
pub fn higher_ranked_glb<T>(&mut self, a: &Binder<T>, b: &Binder<T>, a_is_expected: bool)
315316
-> RelateResult<'tcx, Binder<T>>
316317
where T: Relate<'tcx>
317318
{
@@ -333,7 +334,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
333334

334335
// Collect constraints.
335336
let result0 =
336-
self.glb().relate(&a_with_fresh, &b_with_fresh)?;
337+
self.glb(a_is_expected).relate(&a_with_fresh, &b_with_fresh)?;
337338
let result0 =
338339
self.infcx.resolve_type_vars_if_possible(&result0);
339340
debug!("glb result0 = {:?}", result0);

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,

0 commit comments

Comments
 (0)