use rustc_data_structures::obligation_forest::ProcessResult;
use rustc_data_structures::obligation_forest::{Error, ForestObligation, Outcome};
use rustc_data_structures::obligation_forest::{ObligationForest, ObligationProcessor};
-use rustc_hir::def::DefKind;
use rustc_infer::traits::ProjectionCacheKey;
use rustc_infer::traits::{SelectionError, TraitEngine, TraitObligation};
use rustc_middle::mir::interpret::ErrorHandled;
// Evaluation will discard candidates using the leak check.
// This means we need to pass it the bound version of our
// predicate.
- ty::PredicateKind::Trait(trait_ref) => {
+ ty::PredicateKind::Clause(ty::Clause::Trait(trait_ref)) => {
let trait_obligation = obligation.with(infcx.tcx, binder.rebind(trait_ref));
self.process_trait_obligation(
&mut pending_obligation.stalled_on,
)
}
- ty::PredicateKind::Projection(data) => {
+ ty::PredicateKind::Clause(ty::Clause::Projection(data)) => {
let project_obligation = obligation.with(infcx.tcx, binder.rebind(data));
self.process_projection_obligation(
&mut pending_obligation.stalled_on,
)
}
- ty::PredicateKind::RegionOutlives(_)
- | ty::PredicateKind::TypeOutlives(_)
+ ty::PredicateKind::Clause(ty::Clause::RegionOutlives(_))
+ | ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_))
| ty::PredicateKind::WellFormed(_)
| ty::PredicateKind::ObjectSafe(_)
| ty::PredicateKind::ClosureKind(..)
}
},
Some(pred) => match pred {
- ty::PredicateKind::Trait(data) => {
+ ty::PredicateKind::Clause(ty::Clause::Trait(data)) => {
let trait_obligation = obligation.with(infcx.tcx, Binder::dummy(data));
self.process_trait_obligation(
)
}
- ty::PredicateKind::RegionOutlives(data) => {
+ ty::PredicateKind::Clause(ty::Clause::RegionOutlives(data)) => {
if infcx.considering_regions {
infcx.region_outlives_predicate(&obligation.cause, Binder::dummy(data));
}
ProcessResult::Changed(vec![])
}
- ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t_a, r_b)) => {
+ ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
+ t_a,
+ r_b,
+ ))) => {
if infcx.considering_regions {
infcx.register_region_obligation_with_cause(t_a, r_b, &obligation.cause);
}
ProcessResult::Changed(vec![])
}
- ty::PredicateKind::Projection(ref data) => {
+ ty::PredicateKind::Clause(ty::Clause::Projection(ref data)) => {
let project_obligation = obligation.with(infcx.tcx, Binder::dummy(*data));
self.process_projection_obligation(
tcx.features().generic_const_exprs,
"`ConstEquate` without a feature gate: {c1:?} {c2:?}",
);
- debug!(?c1, ?c2, "equating consts");
// FIXME: we probably should only try to unify abstract constants
// if the constants depend on generic parameters.
//
// Let's just see where this breaks :shrug:
- match (c1.kind(), c2.kind()) {
- (ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b)) => {
- if tcx.def_kind(a.def.did) == DefKind::AssocConst
- || tcx.def_kind(b.def.did) == DefKind::AssocConst
+ {
+ let c1 = tcx.expand_abstract_consts(c1);
+ let c2 = tcx.expand_abstract_consts(c2);
+ debug!("equating consts:\nc1= {:?}\nc2= {:?}", c1, c2);
+
+ use rustc_hir::def::DefKind;
+ use ty::ConstKind::Unevaluated;
+ match (c1.kind(), c2.kind()) {
+ (Unevaluated(a), Unevaluated(b))
+ if a.def.did == b.def.did
+ && tcx.def_kind(a.def.did) == DefKind::AssocConst =>
{
- // Two different constants using generic parameters ~> error.
- let expected_found = ExpectedFound::new(true, c1, c2);
- return ProcessResult::Error(
- FulfillmentErrorCode::CodeConstEquateError(
- expected_found,
- TypeError::ConstMismatch(expected_found),
- ),
- );
+ if let Ok(new_obligations) = infcx
+ .at(&obligation.cause, obligation.param_env)
+ .trace(c1, c2)
+ .eq(a.substs, b.substs)
+ {
+ return ProcessResult::Changed(mk_pending(
+ new_obligations.into_obligations(),
+ ));
+ }
}
- if let (Ok(Some(a)), Ok(Some(b))) = (
- tcx.expand_bound_abstract_const(
- tcx.bound_abstract_const(a.def),
- a.substs,
- ),
- tcx.expand_bound_abstract_const(
- tcx.bound_abstract_const(b.def),
- b.substs,
- ),
- ) && a.ty() == b.ty() &&
- let Ok(new_obligations) = infcx
- .at(&obligation.cause, obligation.param_env)
- .eq(a, b) {
- return ProcessResult::Changed(mk_pending(
- new_obligations.into_obligations(),
- ));
+ (_, Unevaluated(_)) | (Unevaluated(_), _) => (),
+ (_, _) => {
+ if let Ok(new_obligations) =
+ infcx.at(&obligation.cause, obligation.param_env).eq(c1, c2)
+ {
+ return ProcessResult::Changed(mk_pending(
+ new_obligations.into_obligations(),
+ ));
}
+ }
}
- _ => {}
}
let stalled_on = &mut pending_obligation.stalled_on;
.at(&obligation.cause, obligation.param_env)
.eq(c1, c2)
{
- Ok(_) => ProcessResult::Changed(vec![]),
+ Ok(inf_ok) => {
+ ProcessResult::Changed(mk_pending(inf_ok.into_obligations()))
+ }
Err(err) => ProcessResult::Error(
FulfillmentErrorCode::CodeConstEquateError(
ExpectedFound::new(true, c1, c2),