Skip to content

Commit 0939837

Browse files
committed
Rename the cryptic cres and ures types.
1 parent b3317d6 commit 0939837

File tree

13 files changed

+138
-165
lines changed

13 files changed

+138
-165
lines changed

src/librustc/middle/infer/bivariate.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use middle::ty::BuiltinBounds;
2929
use middle::ty::{self, Ty};
3030
use middle::ty::TyVar;
3131
use middle::infer::combine::*;
32-
use middle::infer::cres;
32+
use middle::infer::CombineResult;
3333
use middle::infer::type_variable::BiTo;
3434
use util::ppaux::Repr;
3535

@@ -47,7 +47,7 @@ impl<'f, 'tcx> Combine<'tcx> for Bivariate<'f, 'tcx> {
4747
fn fields<'a>(&'a self) -> &'a CombineFields<'a, 'tcx> { &self.fields }
4848

4949
fn tys_with_variance(&self, v: ty::Variance, a: Ty<'tcx>, b: Ty<'tcx>)
50-
-> cres<'tcx, Ty<'tcx>>
50+
-> CombineResult<'tcx, Ty<'tcx>>
5151
{
5252
match v {
5353
ty::Invariant => self.equate().tys(a, b),
@@ -58,7 +58,7 @@ impl<'f, 'tcx> Combine<'tcx> for Bivariate<'f, 'tcx> {
5858
}
5959

6060
fn regions_with_variance(&self, v: ty::Variance, a: ty::Region, b: ty::Region)
61-
-> cres<'tcx, ty::Region>
61+
-> CombineResult<'tcx, ty::Region>
6262
{
6363
match v {
6464
ty::Invariant => self.equate().regions(a, b),
@@ -68,14 +68,14 @@ impl<'f, 'tcx> Combine<'tcx> for Bivariate<'f, 'tcx> {
6868
}
6969
}
7070

71-
fn regions(&self, a: ty::Region, _: ty::Region) -> cres<'tcx, ty::Region> {
71+
fn regions(&self, a: ty::Region, _: ty::Region) -> CombineResult<'tcx, ty::Region> {
7272
Ok(a)
7373
}
7474

7575
fn builtin_bounds(&self,
7676
a: BuiltinBounds,
7777
b: BuiltinBounds)
78-
-> cres<'tcx, BuiltinBounds>
78+
-> CombineResult<'tcx, BuiltinBounds>
7979
{
8080
if a != b {
8181
Err(ty::terr_builtin_bounds(expected_found(self, a, b)))
@@ -84,7 +84,7 @@ impl<'f, 'tcx> Combine<'tcx> for Bivariate<'f, 'tcx> {
8484
}
8585
}
8686

87-
fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> {
87+
fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CombineResult<'tcx, Ty<'tcx>> {
8888
debug!("{}.tys({}, {})", self.tag(),
8989
a.repr(self.fields.infcx.tcx), b.repr(self.fields.infcx.tcx));
9090
if a == b { return Ok(a); }
@@ -114,7 +114,7 @@ impl<'f, 'tcx> Combine<'tcx> for Bivariate<'f, 'tcx> {
114114
}
115115
}
116116

117-
fn binders<T>(&self, a: &ty::Binder<T>, b: &ty::Binder<T>) -> cres<'tcx, ty::Binder<T>>
117+
fn binders<T>(&self, a: &ty::Binder<T>, b: &ty::Binder<T>) -> CombineResult<'tcx, ty::Binder<T>>
118118
where T : Combineable<'tcx>
119119
{
120120
let a1 = ty::erase_late_bound_regions(self.tcx(), a);

src/librustc/middle/infer/combine.rs

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use super::glb::Glb;
3838
use super::lub::Lub;
3939
use super::sub::Sub;
4040
use super::unify::InferCtxtMethodsForSimplyUnifiableTypes;
41-
use super::{InferCtxt, cres};
41+
use super::{InferCtxt, CombineResult};
4242
use super::{MiscVariable, TypeTrace};
4343
use super::type_variable::{RelationDir, BiTo, EqTo, SubtypeOf, SupertypeOf};
4444

@@ -74,7 +74,7 @@ pub trait Combine<'tcx> : Sized {
7474
fn lub<'a>(&'a self) -> Lub<'a, 'tcx> { Lub(self.fields().clone()) }
7575
fn glb<'a>(&'a self) -> Glb<'a, 'tcx> { Glb(self.fields().clone()) }
7676

77-
fn mts(&self, a: &ty::mt<'tcx>, b: &ty::mt<'tcx>) -> cres<'tcx, ty::mt<'tcx>> {
77+
fn mts(&self, a: &ty::mt<'tcx>, b: &ty::mt<'tcx>) -> CombineResult<'tcx, ty::mt<'tcx>> {
7878
debug!("{}.mts({}, {})",
7979
self.tag(),
8080
a.repr(self.tcx()),
@@ -94,20 +94,20 @@ pub trait Combine<'tcx> : Sized {
9494
}
9595

9696
fn tys_with_variance(&self, variance: ty::Variance, a: Ty<'tcx>, b: Ty<'tcx>)
97-
-> cres<'tcx, Ty<'tcx>>;
97+
-> CombineResult<'tcx, Ty<'tcx>>;
9898

99-
fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>>;
99+
fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CombineResult<'tcx, Ty<'tcx>>;
100100

101101
fn regions_with_variance(&self, variance: ty::Variance, a: ty::Region, b: ty::Region)
102-
-> cres<'tcx, ty::Region>;
102+
-> CombineResult<'tcx, ty::Region>;
103103

104-
fn regions(&self, a: ty::Region, b: ty::Region) -> cres<'tcx, ty::Region>;
104+
fn regions(&self, a: ty::Region, b: ty::Region) -> CombineResult<'tcx, ty::Region>;
105105

106106
fn substs(&self,
107107
item_def_id: ast::DefId,
108108
a_subst: &subst::Substs<'tcx>,
109109
b_subst: &subst::Substs<'tcx>)
110-
-> cres<'tcx, subst::Substs<'tcx>>
110+
-> CombineResult<'tcx, subst::Substs<'tcx>>
111111
{
112112
debug!("substs: item_def_id={} a_subst={} b_subst={}",
113113
item_def_id.repr(self.infcx().tcx),
@@ -126,7 +126,7 @@ pub trait Combine<'tcx> : Sized {
126126
variances: Option<&ty::ItemVariances>,
127127
a_subst: &subst::Substs<'tcx>,
128128
b_subst: &subst::Substs<'tcx>)
129-
-> cres<'tcx, subst::Substs<'tcx>>
129+
-> CombineResult<'tcx, subst::Substs<'tcx>>
130130
{
131131
let mut substs = subst::Substs::empty();
132132

@@ -163,7 +163,7 @@ pub trait Combine<'tcx> : Sized {
163163
variances: Option<&[ty::Variance]>,
164164
a_tys: &[Ty<'tcx>],
165165
b_tys: &[Ty<'tcx>])
166-
-> cres<'tcx, Vec<Ty<'tcx>>>
166+
-> CombineResult<'tcx, Vec<Ty<'tcx>>>
167167
{
168168
if a_tys.len() != b_tys.len() {
169169
return Err(ty::terr_ty_param_size(expected_found(this,
@@ -183,7 +183,7 @@ pub trait Combine<'tcx> : Sized {
183183
variances: Option<&[ty::Variance]>,
184184
a_rs: &[ty::Region],
185185
b_rs: &[ty::Region])
186-
-> cres<'tcx, Vec<ty::Region>>
186+
-> CombineResult<'tcx, Vec<ty::Region>>
187187
{
188188
let tcx = this.infcx().tcx;
189189
let num_region_params = a_rs.len();
@@ -212,7 +212,7 @@ pub trait Combine<'tcx> : Sized {
212212
}
213213

214214
fn bare_fn_tys(&self, a: &ty::BareFnTy<'tcx>,
215-
b: &ty::BareFnTy<'tcx>) -> cres<'tcx, ty::BareFnTy<'tcx>> {
215+
b: &ty::BareFnTy<'tcx>) -> CombineResult<'tcx, ty::BareFnTy<'tcx>> {
216216
let unsafety = try!(self.unsafeties(a.unsafety, b.unsafety));
217217
let abi = try!(self.abi(a.abi, b.abi));
218218
let sig = try!(self.binders(&a.sig, &b.sig));
@@ -221,7 +221,7 @@ pub trait Combine<'tcx> : Sized {
221221
sig: sig})
222222
}
223223

224-
fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>) -> cres<'tcx, ty::FnSig<'tcx>> {
224+
fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>) -> CombineResult<'tcx, ty::FnSig<'tcx>> {
225225
if a.variadic != b.variadic {
226226
return Err(ty::terr_variadic_mismatch(expected_found(self, a.variadic, b.variadic)));
227227
}
@@ -248,7 +248,7 @@ pub trait Combine<'tcx> : Sized {
248248
fn argvecs<'tcx, C>(combiner: &C,
249249
a_args: &[Ty<'tcx>],
250250
b_args: &[Ty<'tcx>])
251-
-> cres<'tcx, Vec<Ty<'tcx>>>
251+
-> CombineResult<'tcx, Vec<Ty<'tcx>>>
252252
where C: Combine<'tcx> {
253253
if a_args.len() == b_args.len() {
254254
a_args.iter().zip(b_args.iter())
@@ -259,19 +259,19 @@ pub trait Combine<'tcx> : Sized {
259259
}
260260
}
261261

262-
fn args(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> {
262+
fn args(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CombineResult<'tcx, Ty<'tcx>> {
263263
self.tys_with_variance(ty::Contravariant, a, b).and_then(|t| Ok(t))
264264
}
265265

266-
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
266+
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> CombineResult<'tcx, Unsafety> {
267267
if a != b {
268268
Err(ty::terr_unsafety_mismatch(expected_found(self, a, b)))
269269
} else {
270270
Ok(a)
271271
}
272272
}
273273

274-
fn abi(&self, a: abi::Abi, b: abi::Abi) -> cres<'tcx, abi::Abi> {
274+
fn abi(&self, a: abi::Abi, b: abi::Abi) -> CombineResult<'tcx, abi::Abi> {
275275
if a == b {
276276
Ok(a)
277277
} else {
@@ -282,7 +282,7 @@ pub trait Combine<'tcx> : Sized {
282282
fn projection_tys(&self,
283283
a: &ty::ProjectionTy<'tcx>,
284284
b: &ty::ProjectionTy<'tcx>)
285-
-> cres<'tcx, ty::ProjectionTy<'tcx>>
285+
-> CombineResult<'tcx, ty::ProjectionTy<'tcx>>
286286
{
287287
if a.item_name != b.item_name {
288288
Err(ty::terr_projection_name_mismatched(
@@ -296,7 +296,7 @@ pub trait Combine<'tcx> : Sized {
296296
fn projection_predicates(&self,
297297
a: &ty::ProjectionPredicate<'tcx>,
298298
b: &ty::ProjectionPredicate<'tcx>)
299-
-> cres<'tcx, ty::ProjectionPredicate<'tcx>>
299+
-> CombineResult<'tcx, ty::ProjectionPredicate<'tcx>>
300300
{
301301
let projection_ty = try!(self.projection_tys(&a.projection_ty, &b.projection_ty));
302302
let ty = try!(self.tys(a.ty, b.ty));
@@ -306,7 +306,7 @@ pub trait Combine<'tcx> : Sized {
306306
fn projection_bounds(&self,
307307
a: &Vec<ty::PolyProjectionPredicate<'tcx>>,
308308
b: &Vec<ty::PolyProjectionPredicate<'tcx>>)
309-
-> cres<'tcx, Vec<ty::PolyProjectionPredicate<'tcx>>>
309+
-> CombineResult<'tcx, Vec<ty::PolyProjectionPredicate<'tcx>>>
310310
{
311311
// To be compatible, `a` and `b` must be for precisely the
312312
// same set of traits and item names. We always require that
@@ -326,7 +326,7 @@ pub trait Combine<'tcx> : Sized {
326326
fn existential_bounds(&self,
327327
a: &ty::ExistentialBounds<'tcx>,
328328
b: &ty::ExistentialBounds<'tcx>)
329-
-> cres<'tcx, ty::ExistentialBounds<'tcx>>
329+
-> CombineResult<'tcx, ty::ExistentialBounds<'tcx>>
330330
{
331331
let r = try!(self.regions_with_variance(ty::Contravariant, a.region_bound, b.region_bound));
332332
let nb = try!(self.builtin_bounds(a.builtin_bounds, b.builtin_bounds));
@@ -339,7 +339,7 @@ pub trait Combine<'tcx> : Sized {
339339
fn builtin_bounds(&self,
340340
a: BuiltinBounds,
341341
b: BuiltinBounds)
342-
-> cres<'tcx, BuiltinBounds>
342+
-> CombineResult<'tcx, BuiltinBounds>
343343
{
344344
// Two sets of builtin bounds are only relatable if they are
345345
// precisely the same (but see the coercion code).
@@ -353,7 +353,7 @@ pub trait Combine<'tcx> : Sized {
353353
fn trait_refs(&self,
354354
a: &ty::TraitRef<'tcx>,
355355
b: &ty::TraitRef<'tcx>)
356-
-> cres<'tcx, ty::TraitRef<'tcx>>
356+
-> CombineResult<'tcx, ty::TraitRef<'tcx>>
357357
{
358358
// Different traits cannot be related
359359
if a.def_id != b.def_id {
@@ -364,14 +364,14 @@ pub trait Combine<'tcx> : Sized {
364364
}
365365
}
366366

367-
fn binders<T>(&self, a: &ty::Binder<T>, b: &ty::Binder<T>) -> cres<'tcx, ty::Binder<T>>
367+
fn binders<T>(&self, a: &ty::Binder<T>, b: &ty::Binder<T>) -> CombineResult<'tcx, ty::Binder<T>>
368368
where T : Combineable<'tcx>;
369369
// this must be overridden to do correctly, so as to account for higher-ranked
370370
// behavior
371371
}
372372

373373
pub trait Combineable<'tcx> : Repr<'tcx> + TypeFoldable<'tcx> {
374-
fn combine<C:Combine<'tcx>>(combiner: &C, a: &Self, b: &Self) -> cres<'tcx, Self>;
374+
fn combine<C:Combine<'tcx>>(combiner: &C, a: &Self, b: &Self) -> CombineResult<'tcx, Self>;
375375
}
376376

377377
impl<'tcx,T> Combineable<'tcx> for Rc<T>
@@ -380,7 +380,7 @@ impl<'tcx,T> Combineable<'tcx> for Rc<T>
380380
fn combine<C>(combiner: &C,
381381
a: &Rc<T>,
382382
b: &Rc<T>)
383-
-> cres<'tcx, Rc<T>>
383+
-> CombineResult<'tcx, Rc<T>>
384384
where C: Combine<'tcx> {
385385
Ok(Rc::new(try!(Combineable::combine(combiner, &**a, &**b))))
386386
}
@@ -390,7 +390,7 @@ impl<'tcx> Combineable<'tcx> for ty::TraitRef<'tcx> {
390390
fn combine<C>(combiner: &C,
391391
a: &ty::TraitRef<'tcx>,
392392
b: &ty::TraitRef<'tcx>)
393-
-> cres<'tcx, ty::TraitRef<'tcx>>
393+
-> CombineResult<'tcx, ty::TraitRef<'tcx>>
394394
where C: Combine<'tcx> {
395395
combiner.trait_refs(a, b)
396396
}
@@ -400,7 +400,7 @@ impl<'tcx> Combineable<'tcx> for Ty<'tcx> {
400400
fn combine<C>(combiner: &C,
401401
a: &Ty<'tcx>,
402402
b: &Ty<'tcx>)
403-
-> cres<'tcx, Ty<'tcx>>
403+
-> CombineResult<'tcx, Ty<'tcx>>
404404
where C: Combine<'tcx> {
405405
combiner.tys(*a, *b)
406406
}
@@ -410,7 +410,7 @@ impl<'tcx> Combineable<'tcx> for ty::ProjectionPredicate<'tcx> {
410410
fn combine<C>(combiner: &C,
411411
a: &ty::ProjectionPredicate<'tcx>,
412412
b: &ty::ProjectionPredicate<'tcx>)
413-
-> cres<'tcx, ty::ProjectionPredicate<'tcx>>
413+
-> CombineResult<'tcx, ty::ProjectionPredicate<'tcx>>
414414
where C: Combine<'tcx> {
415415
combiner.projection_predicates(a, b)
416416
}
@@ -420,7 +420,7 @@ impl<'tcx> Combineable<'tcx> for ty::FnSig<'tcx> {
420420
fn combine<C>(combiner: &C,
421421
a: &ty::FnSig<'tcx>,
422422
b: &ty::FnSig<'tcx>)
423-
-> cres<'tcx, ty::FnSig<'tcx>>
423+
-> CombineResult<'tcx, ty::FnSig<'tcx>>
424424
where C: Combine<'tcx> {
425425
combiner.fn_sigs(a, b)
426426
}
@@ -448,7 +448,7 @@ pub fn expected_found<'tcx, C, T>(this: &C,
448448
pub fn super_tys<'tcx, C>(this: &C,
449449
a: Ty<'tcx>,
450450
b: Ty<'tcx>)
451-
-> cres<'tcx, Ty<'tcx>>
451+
-> CombineResult<'tcx, Ty<'tcx>>
452452
where C: Combine<'tcx> {
453453
let tcx = this.infcx().tcx;
454454
let a_sty = &a.sty;
@@ -616,7 +616,7 @@ pub fn super_tys<'tcx, C>(this: &C,
616616
vid_is_expected: bool,
617617
vid: ty::IntVid,
618618
val: ty::IntVarValue)
619-
-> cres<'tcx, Ty<'tcx>>
619+
-> CombineResult<'tcx, Ty<'tcx>>
620620
where C: Combine<'tcx> {
621621
try!(this.infcx().simple_var_t(vid_is_expected, vid, val));
622622
match val {
@@ -629,7 +629,7 @@ pub fn super_tys<'tcx, C>(this: &C,
629629
vid_is_expected: bool,
630630
vid: ty::FloatVid,
631631
val: ast::FloatTy)
632-
-> cres<'tcx, Ty<'tcx>>
632+
-> CombineResult<'tcx, Ty<'tcx>>
633633
where C: Combine<'tcx> {
634634
try!(this.infcx().simple_var_t(vid_is_expected, vid, val));
635635
Ok(ty::mk_mach_float(this.tcx(), val))
@@ -660,7 +660,7 @@ impl<'f, 'tcx> CombineFields<'f, 'tcx> {
660660
a_ty: Ty<'tcx>,
661661
dir: RelationDir,
662662
b_vid: ty::TyVid)
663-
-> cres<'tcx, ()>
663+
-> CombineResult<'tcx, ()>
664664
{
665665
let tcx = self.infcx.tcx;
666666
let mut stack = Vec::new();
@@ -746,7 +746,7 @@ impl<'f, 'tcx> CombineFields<'f, 'tcx> {
746746
ty: Ty<'tcx>,
747747
for_vid: ty::TyVid,
748748
make_region_vars: bool)
749-
-> cres<'tcx, Ty<'tcx>>
749+
-> CombineResult<'tcx, Ty<'tcx>>
750750
{
751751
let mut generalize = Generalizer {
752752
infcx: self.infcx,
@@ -839,3 +839,23 @@ impl<'cx, 'tcx> ty_fold::TypeFolder<'tcx> for Generalizer<'cx, 'tcx> {
839839
self.infcx.next_region_var(MiscVariable(self.span))
840840
}
841841
}
842+
843+
pub trait CombineResultCompare<'tcx, T> {
844+
fn compare<F>(&self, t: T, f: F) -> CombineResult<'tcx, T> where
845+
F: FnOnce() -> ty::type_err<'tcx>;
846+
}
847+
848+
impl<'tcx, T:Clone + PartialEq> CombineResultCompare<'tcx, T> for CombineResult<'tcx, T> {
849+
fn compare<F>(&self, t: T, f: F) -> CombineResult<'tcx, T> where
850+
F: FnOnce() -> ty::type_err<'tcx>,
851+
{
852+
(*self).clone().and_then(|s| {
853+
if s == t {
854+
(*self).clone()
855+
} else {
856+
Err(f())
857+
}
858+
})
859+
}
860+
}
861+

0 commit comments

Comments
 (0)