diff --git a/src/librustc_infer/traits/util.rs b/src/librustc_infer/traits/util.rs index 9dfe23b5aad..02a30195cc8 100644 --- a/src/librustc_infer/traits/util.rs +++ b/src/librustc_infer/traits/util.rs @@ -151,14 +151,22 @@ impl Elaborator<'tcx> { fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) { let tcx = self.visited.tcx; - match obligation.predicate.kind() { - ty::PredicateKind::Trait(ref data, _) => { + let pred = match obligation.predicate.kint(tcx) { + // We have to be careful and rebind this whenever + // dealing with a predicate further down. + ty::PredicateKint::ForAll(binder) => binder.skip_binder(), + pred => pred, + }; + + match pred { + ty::PredicateKint::ForAll(_) => bug!("unexpected predicate: {:?}", pred), + ty::PredicateKint::Trait(ref data, _) => { // Get predicates declared on the trait. let predicates = tcx.super_predicates_of(data.def_id()); let obligations = predicates.predicates.iter().map(|&(pred, span)| { predicate_obligation( - pred.subst_supertrait(tcx, &data.to_poly_trait_ref()), + pred.subst_supertrait(tcx, &ty::Binder::bind(data.trait_ref)), Some(span), ) }); @@ -173,36 +181,36 @@ impl Elaborator<'tcx> { self.stack.extend(obligations); } - ty::PredicateKind::WellFormed(..) => { + ty::PredicateKint::WellFormed(..) => { // Currently, we do not elaborate WF predicates, // although we easily could. } - ty::PredicateKind::ObjectSafe(..) => { + ty::PredicateKint::ObjectSafe(..) => { // Currently, we do not elaborate object-safe // predicates. } - ty::PredicateKind::Subtype(..) => { + ty::PredicateKint::Subtype(..) => { // Currently, we do not "elaborate" predicates like `X <: Y`, // though conceivably we might. } - ty::PredicateKind::Projection(..) => { + ty::PredicateKint::Projection(..) => { // Nothing to elaborate in a projection predicate. } - ty::PredicateKind::ClosureKind(..) => { + ty::PredicateKint::ClosureKind(..) => { // Nothing to elaborate when waiting for a closure's kind to be inferred. } - ty::PredicateKind::ConstEvaluatable(..) => { + ty::PredicateKint::ConstEvaluatable(..) => { // Currently, we do not elaborate const-evaluatable // predicates. } - ty::PredicateKind::ConstEquate(..) => { + ty::PredicateKint::ConstEquate(..) => { // Currently, we do not elaborate const-equate // predicates. } - ty::PredicateKind::RegionOutlives(..) => { + ty::PredicateKint::RegionOutlives(..) => { // Nothing to elaborate from `'a: 'b`. } - ty::PredicateKind::TypeOutlives(ref data) => { + ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => { // We know that `T: 'a` for some type `T`. We can // often elaborate this. For example, if we know that // `[U]: 'a`, that implies that `U: 'a`. Similarly, if @@ -217,8 +225,6 @@ impl Elaborator<'tcx> { // consider this as evidence that `T: 'static`, but // I'm a bit wary of such constructions and so for now // I want to be conservative. --nmatsakis - let ty_max = data.skip_binder().0; - let r_min = data.skip_binder().1; if r_min.is_late_bound() { return; } diff --git a/src/librustc_trait_selection/traits/wf.rs b/src/librustc_trait_selection/traits/wf.rs index 333f90d78a7..b72359129e9 100644 --- a/src/librustc_trait_selection/traits/wf.rs +++ b/src/librustc_trait_selection/traits/wf.rs @@ -397,7 +397,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { self.out.push(traits::Obligation::new( cause, self.param_env, - ty::PredicateKind::WellFormed(resolved_constant.into()) + ty::PredicateKint::WellFormed(resolved_constant.into()) .to_predicate(self.tcx()), )); } @@ -483,10 +483,8 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { self.out.push(traits::Obligation::new( cause, param_env, - ty::PredicateKind::TypeOutlives(ty::Binder::dummy( - ty::OutlivesPredicate(rty, r), - )) - .to_predicate(self.tcx()), + ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(rty, r)) + .to_predicate(self.tcx()), )); } }