elaborate

This commit is contained in:
Bastian Kauschke 2020-06-18 17:43:26 +02:00
parent 7f39b0c9ab
commit 4c3b1e89cf
2 changed files with 23 additions and 19 deletions

View File

@ -151,14 +151,22 @@ pub fn filter_to_traits(self) -> FilterToTraits<Self> {
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 @@ fn elaborate(&mut self, obligation: &PredicateObligation<'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 @@ fn elaborate(&mut self, obligation: &PredicateObligation<'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;
}

View File

@ -397,7 +397,7 @@ fn compute(&mut self, arg: GenericArg<'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 @@ fn compute(&mut self, arg: GenericArg<'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()),
));
}
}