1 // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Generalized type relating mechanism. A type relation R relates a
12 //! pair of values (A, B). A and B are usually types or regions but
13 //! can be other things. Examples of type relations are subtyping,
14 //! type equality, etc.
16 use hir::def_id::DefId;
17 use mir::interpret::ConstValue;
18 use ty::subst::{Kind, UnpackedKind, Substs};
19 use ty::{self, Ty, TyCtxt, TypeFoldable};
20 use ty::error::{ExpectedFound, TypeError};
21 use mir::interpret::GlobalId;
22 use util::common::ErrorReported;
23 use syntax_pos::DUMMY_SP;
26 use rustc_target::spec::abi;
29 pub type RelateResult<'tcx, T> = Result<T, TypeError<'tcx>>;
31 #[derive(Clone, Debug)]
33 ExistentialRegionBound, // relating an existential region bound
36 pub trait TypeRelation<'a, 'gcx: 'a+'tcx, 'tcx: 'a> : Sized {
37 fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx>;
39 /// Returns a static string we can use for printouts.
40 fn tag(&self) -> &'static str;
42 /// Returns true if the value `a` is the "expected" type in the
43 /// relation. Just affects error messages.
44 fn a_is_expected(&self) -> bool;
46 fn with_cause<F,R>(&mut self, _cause: Cause, f: F) -> R
47 where F: FnOnce(&mut Self) -> R
52 /// Generic relation routine suitable for most anything.
53 fn relate<T: Relate<'tcx>>(&mut self, a: &T, b: &T) -> RelateResult<'tcx, T> {
54 Relate::relate(self, a, b)
57 /// Relate the two substitutions for the given item. The default
58 /// is to look up the variance for the item and proceed
60 fn relate_item_substs(&mut self,
62 a_subst: &'tcx Substs<'tcx>,
63 b_subst: &'tcx Substs<'tcx>)
64 -> RelateResult<'tcx, &'tcx Substs<'tcx>>
66 debug!("relate_item_substs(item_def_id={:?}, a_subst={:?}, b_subst={:?})",
71 let opt_variances = self.tcx().variances_of(item_def_id);
72 relate_substs(self, Some(&opt_variances), a_subst, b_subst)
75 /// Switch variance for the purpose of relating `a` and `b`.
76 fn relate_with_variance<T: Relate<'tcx>>(&mut self,
77 variance: ty::Variance,
80 -> RelateResult<'tcx, T>;
82 // Overrideable relations. You shouldn't typically call these
83 // directly, instead call `relate()`, which in turn calls
84 // these. This is both more uniform but also allows us to add
85 // additional hooks for other types in the future if needed
86 // without making older code, which called `relate`, obsolete.
88 fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>)
89 -> RelateResult<'tcx, Ty<'tcx>>;
91 fn regions(&mut self, a: ty::Region<'tcx>, b: ty::Region<'tcx>)
92 -> RelateResult<'tcx, ty::Region<'tcx>>;
94 fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)
95 -> RelateResult<'tcx, ty::Binder<T>>
96 where T: Relate<'tcx>;
99 pub trait Relate<'tcx>: TypeFoldable<'tcx> {
100 fn relate<'a, 'gcx, R>(relation: &mut R, a: &Self, b: &Self)
101 -> RelateResult<'tcx, Self>
102 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a;
105 ///////////////////////////////////////////////////////////////////////////
108 impl<'tcx> Relate<'tcx> for ty::TypeAndMut<'tcx> {
109 fn relate<'a, 'gcx, R>(relation: &mut R,
110 a: &ty::TypeAndMut<'tcx>,
111 b: &ty::TypeAndMut<'tcx>)
112 -> RelateResult<'tcx, ty::TypeAndMut<'tcx>>
113 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
115 debug!("{}.mts({:?}, {:?})",
119 if a.mutbl != b.mutbl {
120 Err(TypeError::Mutability)
123 let variance = match mutbl {
124 ast::Mutability::MutImmutable => ty::Covariant,
125 ast::Mutability::MutMutable => ty::Invariant,
127 let ty = relation.relate_with_variance(variance, &a.ty, &b.ty)?;
128 Ok(ty::TypeAndMut {ty: ty, mutbl: mutbl})
133 pub fn relate_substs<'a, 'gcx, 'tcx, R>(relation: &mut R,
134 variances: Option<&Vec<ty::Variance>>,
135 a_subst: &'tcx Substs<'tcx>,
136 b_subst: &'tcx Substs<'tcx>)
137 -> RelateResult<'tcx, &'tcx Substs<'tcx>>
138 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
140 let tcx = relation.tcx();
142 let params = a_subst.iter().zip(b_subst).enumerate().map(|(i, (a, b))| {
143 let variance = variances.map_or(ty::Invariant, |v| v[i]);
144 relation.relate_with_variance(variance, a, b)
147 Ok(tcx.mk_substs(params)?)
150 impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
151 fn relate<'a, 'gcx, R>(relation: &mut R,
154 -> RelateResult<'tcx, ty::FnSig<'tcx>>
155 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
157 let tcx = relation.tcx();
159 if a.variadic != b.variadic {
160 return Err(TypeError::VariadicMismatch(
161 expected_found(relation, &a.variadic, &b.variadic)));
163 let unsafety = relation.relate(&a.unsafety, &b.unsafety)?;
164 let abi = relation.relate(&a.abi, &b.abi)?;
166 if a.inputs().len() != b.inputs().len() {
167 return Err(TypeError::ArgCount);
170 let inputs_and_output = a.inputs().iter().cloned()
171 .zip(b.inputs().iter().cloned())
173 .chain(iter::once(((a.output(), b.output()), true)))
174 .map(|((a, b), is_output)| {
176 relation.relate(&a, &b)
178 relation.relate_with_variance(ty::Contravariant, &a, &b)
182 inputs_and_output: tcx.mk_type_list(inputs_and_output)?,
183 variadic: a.variadic,
190 impl<'tcx> Relate<'tcx> for ast::Unsafety {
191 fn relate<'a, 'gcx, R>(relation: &mut R,
194 -> RelateResult<'tcx, ast::Unsafety>
195 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
198 Err(TypeError::UnsafetyMismatch(expected_found(relation, a, b)))
205 impl<'tcx> Relate<'tcx> for abi::Abi {
206 fn relate<'a, 'gcx, R>(relation: &mut R,
209 -> RelateResult<'tcx, abi::Abi>
210 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
215 Err(TypeError::AbiMismatch(expected_found(relation, a, b)))
220 impl<'tcx> Relate<'tcx> for ty::ProjectionTy<'tcx> {
221 fn relate<'a, 'gcx, R>(relation: &mut R,
222 a: &ty::ProjectionTy<'tcx>,
223 b: &ty::ProjectionTy<'tcx>)
224 -> RelateResult<'tcx, ty::ProjectionTy<'tcx>>
225 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
227 if a.item_def_id != b.item_def_id {
228 Err(TypeError::ProjectionMismatched(
229 expected_found(relation, &a.item_def_id, &b.item_def_id)))
231 let substs = relation.relate(&a.substs, &b.substs)?;
232 Ok(ty::ProjectionTy {
233 item_def_id: a.item_def_id,
240 impl<'tcx> Relate<'tcx> for ty::ExistentialProjection<'tcx> {
241 fn relate<'a, 'gcx, R>(relation: &mut R,
242 a: &ty::ExistentialProjection<'tcx>,
243 b: &ty::ExistentialProjection<'tcx>)
244 -> RelateResult<'tcx, ty::ExistentialProjection<'tcx>>
245 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
247 if a.item_def_id != b.item_def_id {
248 Err(TypeError::ProjectionMismatched(
249 expected_found(relation, &a.item_def_id, &b.item_def_id)))
251 let ty = relation.relate(&a.ty, &b.ty)?;
252 let substs = relation.relate(&a.substs, &b.substs)?;
253 Ok(ty::ExistentialProjection {
254 item_def_id: a.item_def_id,
262 impl<'tcx> Relate<'tcx> for Vec<ty::PolyExistentialProjection<'tcx>> {
263 fn relate<'a, 'gcx, R>(relation: &mut R,
264 a: &Vec<ty::PolyExistentialProjection<'tcx>>,
265 b: &Vec<ty::PolyExistentialProjection<'tcx>>)
266 -> RelateResult<'tcx, Vec<ty::PolyExistentialProjection<'tcx>>>
267 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
269 // To be compatible, `a` and `b` must be for precisely the
270 // same set of traits and item names. We always require that
271 // projection bounds lists are sorted by trait-def-id and item-name,
272 // so we can just iterate through the lists pairwise, so long as they are the
274 if a.len() != b.len() {
275 Err(TypeError::ProjectionBoundsLength(expected_found(relation, &a.len(), &b.len())))
279 .map(|(a, b)| relation.relate(a, b))
285 impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> {
286 fn relate<'a, 'gcx, R>(relation: &mut R,
287 a: &ty::TraitRef<'tcx>,
288 b: &ty::TraitRef<'tcx>)
289 -> RelateResult<'tcx, ty::TraitRef<'tcx>>
290 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
292 // Different traits cannot be related
293 if a.def_id != b.def_id {
294 Err(TypeError::Traits(expected_found(relation, &a.def_id, &b.def_id)))
296 let substs = relate_substs(relation, None, a.substs, b.substs)?;
297 Ok(ty::TraitRef { def_id: a.def_id, substs: substs })
302 impl<'tcx> Relate<'tcx> for ty::ExistentialTraitRef<'tcx> {
303 fn relate<'a, 'gcx, R>(relation: &mut R,
304 a: &ty::ExistentialTraitRef<'tcx>,
305 b: &ty::ExistentialTraitRef<'tcx>)
306 -> RelateResult<'tcx, ty::ExistentialTraitRef<'tcx>>
307 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
309 // Different traits cannot be related
310 if a.def_id != b.def_id {
311 Err(TypeError::Traits(expected_found(relation, &a.def_id, &b.def_id)))
313 let substs = relate_substs(relation, None, a.substs, b.substs)?;
314 Ok(ty::ExistentialTraitRef { def_id: a.def_id, substs: substs })
319 #[derive(Debug, Clone)]
320 struct GeneratorWitness<'tcx>(&'tcx ty::List<Ty<'tcx>>);
322 TupleStructTypeFoldableImpl! {
323 impl<'tcx> TypeFoldable<'tcx> for GeneratorWitness<'tcx> {
328 impl<'tcx> Relate<'tcx> for GeneratorWitness<'tcx> {
329 fn relate<'a, 'gcx, R>(relation: &mut R,
330 a: &GeneratorWitness<'tcx>,
331 b: &GeneratorWitness<'tcx>)
332 -> RelateResult<'tcx, GeneratorWitness<'tcx>>
333 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
335 assert_eq!(a.0.len(), b.0.len());
336 let tcx = relation.tcx();
337 let types = tcx.mk_type_list(a.0.iter().zip(b.0).map(|(a, b)| relation.relate(a, b)))?;
338 Ok(GeneratorWitness(types))
342 impl<'tcx> Relate<'tcx> for Ty<'tcx> {
343 fn relate<'a, 'gcx, R>(relation: &mut R,
346 -> RelateResult<'tcx, Ty<'tcx>>
347 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
353 /// The main "type relation" routine. Note that this does not handle
354 /// inference artifacts, so you should filter those out before calling
356 pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
359 -> RelateResult<'tcx, Ty<'tcx>>
360 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
362 let tcx = relation.tcx();
365 debug!("super_relate_tys: a_sty={:?} b_sty={:?}", a_sty, b_sty);
366 match (a_sty, b_sty) {
368 (_, &ty::Infer(_)) =>
370 // The caller should handle these cases!
371 bug!("var types encountered in super_relate_tys")
374 (&ty::Error, _) | (_, &ty::Error) =>
391 (&ty::Param(ref a_p), &ty::Param(ref b_p))
392 if a_p.idx == b_p.idx =>
397 (&ty::Adt(a_def, a_substs), &ty::Adt(b_def, b_substs))
400 let substs = relation.relate_item_substs(a_def.did, a_substs, b_substs)?;
401 Ok(tcx.mk_adt(a_def, substs))
404 (&ty::Foreign(a_id), &ty::Foreign(b_id))
407 Ok(tcx.mk_foreign(a_id))
410 (&ty::Dynamic(ref a_obj, ref a_region), &ty::Dynamic(ref b_obj, ref b_region)) => {
411 let region_bound = relation.with_cause(Cause::ExistentialRegionBound,
413 relation.relate_with_variance(
418 Ok(tcx.mk_dynamic(relation.relate(a_obj, b_obj)?, region_bound))
421 (&ty::Generator(a_id, a_substs, movability),
422 &ty::Generator(b_id, b_substs, _))
425 // All Generator types with the same id represent
426 // the (anonymous) type of the same generator expression. So
427 // all of their regions should be equated.
428 let substs = relation.relate(&a_substs, &b_substs)?;
429 Ok(tcx.mk_generator(a_id, substs, movability))
432 (&ty::GeneratorWitness(a_types), &ty::GeneratorWitness(b_types)) =>
434 // Wrap our types with a temporary GeneratorWitness struct
435 // inside the binder so we can related them
436 let a_types = a_types.map_bound(GeneratorWitness);
437 let b_types = b_types.map_bound(GeneratorWitness);
438 // Then remove the GeneratorWitness for the result
439 let types = relation.relate(&a_types, &b_types)?.map_bound(|witness| witness.0);
440 Ok(tcx.mk_generator_witness(types))
443 (&ty::Closure(a_id, a_substs),
444 &ty::Closure(b_id, b_substs))
447 // All Closure types with the same id represent
448 // the (anonymous) type of the same closure expression. So
449 // all of their regions should be equated.
450 let substs = relation.relate(&a_substs, &b_substs)?;
451 Ok(tcx.mk_closure(a_id, substs))
454 (&ty::RawPtr(ref a_mt), &ty::RawPtr(ref b_mt)) =>
456 let mt = relation.relate(a_mt, b_mt)?;
460 (&ty::Ref(a_r, a_ty, a_mutbl), &ty::Ref(b_r, b_ty, b_mutbl)) =>
462 let r = relation.relate_with_variance(ty::Contravariant, &a_r, &b_r)?;
463 let a_mt = ty::TypeAndMut { ty: a_ty, mutbl: a_mutbl };
464 let b_mt = ty::TypeAndMut { ty: b_ty, mutbl: b_mutbl };
465 let mt = relation.relate(&a_mt, &b_mt)?;
466 Ok(tcx.mk_ref(r, mt))
469 (&ty::Array(a_t, sz_a), &ty::Array(b_t, sz_b)) =>
471 let t = relation.relate(&a_t, &b_t)?;
472 assert_eq!(sz_a.ty, tcx.types.usize);
473 assert_eq!(sz_b.ty, tcx.types.usize);
474 let to_u64 = |x: &'tcx ty::Const<'tcx>| -> Result<u64, ErrorReported> {
475 if let Some(s) = x.assert_usize(tcx) {
479 ConstValue::Unevaluated(def_id, substs) => {
480 // FIXME(eddyb) get the right param_env.
481 let param_env = ty::ParamEnv::empty();
482 if let Some(substs) = tcx.lift_to_global(&substs) {
483 let instance = ty::Instance::resolve(
489 if let Some(instance) = instance {
494 if let Some(s) = tcx.const_eval(param_env.and(cid))
496 .map(|c| c.unwrap_usize(tcx)) {
501 tcx.sess.delay_span_bug(tcx.def_span(def_id),
502 "array length could not be evaluated");
506 tcx.sess.delay_span_bug(DUMMY_SP,
507 &format!("arrays should not have {:?} as length", x));
512 match (to_u64(sz_a), to_u64(sz_b)) {
513 (Ok(sz_a_u64), Ok(sz_b_u64)) => {
514 if sz_a_u64 == sz_b_u64 {
515 Ok(tcx.mk_ty(ty::Array(t, sz_a)))
517 Err(TypeError::FixedArraySize(
518 expected_found(relation, &sz_a_u64, &sz_b_u64)))
521 // We reported an error or will ICE, so we can return Error.
522 (Err(ErrorReported), _) | (_, Err(ErrorReported)) => {
528 (&ty::Slice(a_t), &ty::Slice(b_t)) =>
530 let t = relation.relate(&a_t, &b_t)?;
534 (&ty::Tuple(as_), &ty::Tuple(bs)) =>
536 if as_.len() == bs.len() {
537 Ok(tcx.mk_tup(as_.iter().zip(bs).map(|(a, b)| relation.relate(a, b)))?)
538 } else if !(as_.is_empty() || bs.is_empty()) {
539 Err(TypeError::TupleSize(
540 expected_found(relation, &as_.len(), &bs.len())))
542 Err(TypeError::Sorts(expected_found(relation, &a, &b)))
546 (&ty::FnDef(a_def_id, a_substs), &ty::FnDef(b_def_id, b_substs))
547 if a_def_id == b_def_id =>
549 let substs = relation.relate_item_substs(a_def_id, a_substs, b_substs)?;
550 Ok(tcx.mk_fn_def(a_def_id, substs))
553 (&ty::FnPtr(a_fty), &ty::FnPtr(b_fty)) =>
555 let fty = relation.relate(&a_fty, &b_fty)?;
556 Ok(tcx.mk_fn_ptr(fty))
559 (&ty::Projection(ref a_data), &ty::Projection(ref b_data)) =>
561 let projection_ty = relation.relate(a_data, b_data)?;
562 Ok(tcx.mk_projection(projection_ty.item_def_id, projection_ty.substs))
565 (&ty::Opaque(a_def_id, a_substs), &ty::Opaque(b_def_id, b_substs))
566 if a_def_id == b_def_id =>
568 let substs = relate_substs(relation, None, a_substs, b_substs)?;
569 Ok(tcx.mk_opaque(a_def_id, substs))
574 Err(TypeError::Sorts(expected_found(relation, &a, &b)))
579 impl<'tcx> Relate<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {
580 fn relate<'a, 'gcx, R>(relation: &mut R,
583 -> RelateResult<'tcx, Self>
584 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a {
586 if a.len() != b.len() {
587 return Err(TypeError::ExistentialMismatch(expected_found(relation, a, b)));
590 let tcx = relation.tcx();
591 let v = a.iter().zip(b.iter()).map(|(ep_a, ep_b)| {
592 use ty::ExistentialPredicate::*;
593 match (*ep_a, *ep_b) {
594 (Trait(ref a), Trait(ref b)) => Ok(Trait(relation.relate(a, b)?)),
595 (Projection(ref a), Projection(ref b)) => Ok(Projection(relation.relate(a, b)?)),
596 (AutoTrait(ref a), AutoTrait(ref b)) if a == b => Ok(AutoTrait(*a)),
597 _ => Err(TypeError::ExistentialMismatch(expected_found(relation, a, b)))
600 Ok(tcx.mk_existential_predicates(v)?)
604 impl<'tcx> Relate<'tcx> for ty::ClosureSubsts<'tcx> {
605 fn relate<'a, 'gcx, R>(relation: &mut R,
606 a: &ty::ClosureSubsts<'tcx>,
607 b: &ty::ClosureSubsts<'tcx>)
608 -> RelateResult<'tcx, ty::ClosureSubsts<'tcx>>
609 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
611 let substs = relate_substs(relation, None, a.substs, b.substs)?;
612 Ok(ty::ClosureSubsts { substs })
616 impl<'tcx> Relate<'tcx> for ty::GeneratorSubsts<'tcx> {
617 fn relate<'a, 'gcx, R>(relation: &mut R,
618 a: &ty::GeneratorSubsts<'tcx>,
619 b: &ty::GeneratorSubsts<'tcx>)
620 -> RelateResult<'tcx, ty::GeneratorSubsts<'tcx>>
621 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
623 let substs = relate_substs(relation, None, a.substs, b.substs)?;
624 Ok(ty::GeneratorSubsts { substs })
628 impl<'tcx> Relate<'tcx> for &'tcx Substs<'tcx> {
629 fn relate<'a, 'gcx, R>(relation: &mut R,
630 a: &&'tcx Substs<'tcx>,
631 b: &&'tcx Substs<'tcx>)
632 -> RelateResult<'tcx, &'tcx Substs<'tcx>>
633 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
635 relate_substs(relation, None, a, b)
639 impl<'tcx> Relate<'tcx> for ty::Region<'tcx> {
640 fn relate<'a, 'gcx, R>(relation: &mut R,
641 a: &ty::Region<'tcx>,
642 b: &ty::Region<'tcx>)
643 -> RelateResult<'tcx, ty::Region<'tcx>>
644 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
646 relation.regions(*a, *b)
650 impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for ty::Binder<T> {
651 fn relate<'a, 'gcx, R>(relation: &mut R,
654 -> RelateResult<'tcx, ty::Binder<T>>
655 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
657 relation.binders(a, b)
661 impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for Rc<T> {
662 fn relate<'a, 'gcx, R>(relation: &mut R,
665 -> RelateResult<'tcx, Rc<T>>
666 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
670 Ok(Rc::new(relation.relate(a, b)?))
674 impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for Box<T> {
675 fn relate<'a, 'gcx, R>(relation: &mut R,
678 -> RelateResult<'tcx, Box<T>>
679 where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
683 Ok(Box::new(relation.relate(a, b)?))
687 impl<'tcx> Relate<'tcx> for Kind<'tcx> {
688 fn relate<'a, 'gcx, R>(
692 ) -> RelateResult<'tcx, Kind<'tcx>>
694 R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a,
696 match (a.unpack(), b.unpack()) {
697 (UnpackedKind::Lifetime(a_lt), UnpackedKind::Lifetime(b_lt)) => {
698 Ok(relation.relate(&a_lt, &b_lt)?.into())
700 (UnpackedKind::Type(a_ty), UnpackedKind::Type(b_ty)) => {
701 Ok(relation.relate(&a_ty, &b_ty)?.into())
703 (UnpackedKind::Lifetime(unpacked), x) => {
704 bug!("impossible case reached: can't relate: {:?} with {:?}", unpacked, x)
706 (UnpackedKind::Type(unpacked), x) => {
707 bug!("impossible case reached: can't relate: {:?} with {:?}", unpacked, x)
713 ///////////////////////////////////////////////////////////////////////////
716 pub fn expected_found<'a, 'gcx, 'tcx, R, T>(relation: &mut R,
720 where R: TypeRelation<'a, 'gcx, 'tcx>, T: Clone, 'gcx: 'a+'tcx, 'tcx: 'a
722 expected_found_bool(relation.a_is_expected(), a, b)
725 pub fn expected_found_bool<T>(a_is_expected: bool,
734 ExpectedFound {expected: a, found: b}
736 ExpectedFound {expected: b, found: a}