1
Fork 0

Convert predicates into Predicate in the Obligation constructor

This commit is contained in:
Oli Scherer 2022-11-09 10:49:28 +00:00
parent 634df06fae
commit 4f11f3b257
49 changed files with 252 additions and 228 deletions

View file

@ -194,6 +194,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
&mut obligations,
);
obligations.push(Obligation::with_depth(
self.tcx(),
obligation.cause.clone(),
obligation.recursion_depth + 1,
obligation.param_env,
@ -482,11 +483,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
super_trait,
&mut nested,
);
nested.push(Obligation::new(
obligation.cause.clone(),
obligation.param_env,
normalized_super_trait,
));
nested.push(obligation.with(tcx, normalized_super_trait));
}
let assoc_types: Vec<_> = tcx
@ -581,11 +578,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
subst_bound,
&mut nested,
);
nested.push(Obligation::new(
obligation.cause.clone(),
obligation.param_env,
normalized_bound,
));
nested.push(obligation.with(tcx, normalized_bound));
}
}
@ -644,9 +637,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
self.tcx().mk_substs_trait(output_ty, &[]),
));
nested.push(Obligation::new(
self.infcx.tcx,
cause,
obligation.param_env,
tr.to_poly_trait_predicate().to_predicate(self.tcx()),
tr.to_poly_trait_predicate(),
));
Ok(ImplSourceFnPointerData { fn_ty: self_ty, nested })
@ -727,11 +721,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// FIXME: Chalk
if !self.tcx().sess.opts.unstable_opts.chalk {
nested.push(Obligation::new(
obligation.cause.clone(),
obligation.param_env,
ty::Binder::dummy(ty::PredicateKind::ClosureKind(closure_def_id, substs, kind))
.to_predicate(self.tcx()),
nested.push(obligation.with(
self.tcx(),
ty::Binder::dummy(ty::PredicateKind::ClosureKind(closure_def_id, substs, kind)),
));
}
@ -860,10 +852,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
);
let outlives = ty::OutlivesPredicate(r_a, r_b);
nested.push(Obligation::with_depth(
tcx,
cause,
obligation.recursion_depth + 1,
obligation.param_env,
obligation.predicate.rebind(outlives).to_predicate(tcx),
obligation.predicate.rebind(outlives),
));
}
_ => bug!(),
@ -957,10 +950,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
);
let outlives = ty::OutlivesPredicate(r_a, r_b);
nested.push(Obligation::with_depth(
tcx,
cause,
obligation.recursion_depth + 1,
obligation.param_env,
obligation.predicate.rebind(outlives).to_predicate(tcx),
obligation.predicate.rebind(outlives),
));
}
@ -979,6 +973,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let predicate_to_obligation = |predicate| {
Obligation::with_depth(
tcx,
cause.clone(),
obligation.recursion_depth + 1,
obligation.param_env,
@ -1255,20 +1250,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.param_env,
cause.clone(),
obligation.recursion_depth + 1,
self_ty
.rebind(ty::TraitPredicate {
trait_ref: ty::TraitRef {
def_id: self.tcx().require_lang_item(LangItem::Destruct, None),
substs: self.tcx().mk_substs_trait(nested_ty, &[]),
},
constness: ty::BoundConstness::ConstIfConst,
polarity: ty::ImplPolarity::Positive,
})
.to_predicate(tcx),
self_ty.rebind(ty::TraitPredicate {
trait_ref: ty::TraitRef {
def_id: self.tcx().require_lang_item(LangItem::Destruct, None),
substs: self.tcx().mk_substs_trait(nested_ty, &[]),
},
constness: ty::BoundConstness::ConstIfConst,
polarity: ty::ImplPolarity::Positive,
}),
&mut nested,
);
nested.push(Obligation::with_depth(
tcx,
cause.clone(),
obligation.recursion_depth + 1,
obligation.param_env,
@ -1280,18 +1274,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// since it's either not `const Drop` (and we raise an error during selection),
// or it's an ADT (and we need to check for a custom impl during selection)
_ => {
let predicate = self_ty
.rebind(ty::TraitPredicate {
trait_ref: ty::TraitRef {
def_id: self.tcx().require_lang_item(LangItem::Destruct, None),
substs: self.tcx().mk_substs_trait(nested_ty, &[]),
},
constness: ty::BoundConstness::ConstIfConst,
polarity: ty::ImplPolarity::Positive,
})
.to_predicate(tcx);
let predicate = self_ty.rebind(ty::TraitPredicate {
trait_ref: ty::TraitRef {
def_id: self.tcx().require_lang_item(LangItem::Destruct, None),
substs: self.tcx().mk_substs_trait(nested_ty, &[]),
},
constness: ty::BoundConstness::ConstIfConst,
polarity: ty::ImplPolarity::Positive,
});
nested.push(Obligation::with_depth(
tcx,
cause.clone(),
obligation.recursion_depth + 1,
obligation.param_env,