Obligation::as_goal
This commit is contained in:
parent
aa8f0fd716
commit
575f129faa
7 changed files with 17 additions and 18 deletions
|
@ -1,7 +1,7 @@
|
||||||
//! A utility module to inspect currently ambiguous obligations in the current context.
|
//! A utility module to inspect currently ambiguous obligations in the current context.
|
||||||
|
|
||||||
use rustc_infer::traits::{self, ObligationCause, PredicateObligations};
|
use rustc_infer::traits::{self, ObligationCause, PredicateObligations};
|
||||||
use rustc_middle::traits::solve::{Goal, GoalSource};
|
use rustc_middle::traits::solve::GoalSource;
|
||||||
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
|
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_trait_selection::solve::inspect::{
|
use rustc_trait_selection::solve::inspect::{
|
||||||
|
@ -85,7 +85,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
root_cause: &obligation.cause,
|
root_cause: &obligation.cause,
|
||||||
};
|
};
|
||||||
|
|
||||||
let goal = Goal::new(self.tcx, obligation.param_env, obligation.predicate);
|
let goal = obligation.as_goal();
|
||||||
self.visit_proof_tree(goal, &mut visitor);
|
self.visit_proof_tree(goal, &mut visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -246,8 +246,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
.eq(DefineOpaqueTypes::Yes, prev, hidden_ty)?
|
.eq(DefineOpaqueTypes::Yes, prev, hidden_ty)?
|
||||||
.obligations
|
.obligations
|
||||||
.into_iter()
|
.into_iter()
|
||||||
// FIXME: Shuttling between obligations and goals is awkward.
|
.map(|obligation| obligation.as_goal()),
|
||||||
.map(Goal::from),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,12 @@ pub struct Obligation<'tcx, T> {
|
||||||
pub recursion_depth: usize,
|
pub recursion_depth: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx, T: Copy> Obligation<'tcx, T> {
|
||||||
|
pub fn as_goal(&self) -> solve::Goal<'tcx, T> {
|
||||||
|
solve::Goal { param_env: self.param_env, predicate: self.predicate }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'tcx, T: PartialEq> PartialEq<Obligation<'tcx, T>> for Obligation<'tcx, T> {
|
impl<'tcx, T: PartialEq> PartialEq<Obligation<'tcx, T>> for Obligation<'tcx, T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &Obligation<'tcx, T>) -> bool {
|
fn eq(&self, other: &Obligation<'tcx, T>) -> bool {
|
||||||
|
@ -75,12 +81,6 @@ impl<T: Hash> Hash for Obligation<'_, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, P> From<Obligation<'tcx, P>> for solve::Goal<'tcx, P> {
|
|
||||||
fn from(value: Obligation<'tcx, P>) -> Self {
|
|
||||||
solve::Goal { param_env: value.param_env, predicate: value.predicate }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type PredicateObligation<'tcx> = Obligation<'tcx, ty::Predicate<'tcx>>;
|
pub type PredicateObligation<'tcx> = Obligation<'tcx, ty::Predicate<'tcx>>;
|
||||||
pub type TraitObligation<'tcx> = Obligation<'tcx, ty::TraitPredicate<'tcx>>;
|
pub type TraitObligation<'tcx> = Obligation<'tcx, ty::TraitPredicate<'tcx>>;
|
||||||
pub type PolyTraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>;
|
pub type PolyTraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>;
|
||||||
|
|
|
@ -96,7 +96,7 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
|
||||||
) -> Option<Vec<Goal<'tcx, ty::Predicate<'tcx>>>> {
|
) -> Option<Vec<Goal<'tcx, ty::Predicate<'tcx>>>> {
|
||||||
crate::traits::wf::unnormalized_obligations(&self.0, param_env, arg, DUMMY_SP, CRATE_DEF_ID)
|
crate::traits::wf::unnormalized_obligations(&self.0, param_env, arg, DUMMY_SP, CRATE_DEF_ID)
|
||||||
.map(|obligations| {
|
.map(|obligations| {
|
||||||
obligations.into_iter().map(|obligation| obligation.into()).collect()
|
obligations.into_iter().map(|obligation| obligation.as_goal()).collect()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ impl<'tcx> ObligationStorage<'tcx> {
|
||||||
// change.
|
// change.
|
||||||
// FIXME: <https://github.com/Gankra/thin-vec/pull/66> is merged, this can be removed.
|
// FIXME: <https://github.com/Gankra/thin-vec/pull/66> is merged, this can be removed.
|
||||||
self.overflowed.extend(ExtractIf::new(&mut self.pending, |o| {
|
self.overflowed.extend(ExtractIf::new(&mut self.pending, |o| {
|
||||||
let goal = o.clone().into();
|
let goal = o.as_goal();
|
||||||
let result = <&SolverDelegate<'tcx>>::from(infcx)
|
let result = <&SolverDelegate<'tcx>>::from(infcx)
|
||||||
.evaluate_root_goal(goal, GenerateProofTree::No, o.cause.span)
|
.evaluate_root_goal(goal, GenerateProofTree::No, o.cause.span)
|
||||||
.0;
|
.0;
|
||||||
|
@ -161,7 +161,7 @@ where
|
||||||
|
|
||||||
let mut has_changed = false;
|
let mut has_changed = false;
|
||||||
for obligation in self.obligations.unstalled_for_select() {
|
for obligation in self.obligations.unstalled_for_select() {
|
||||||
let goal = obligation.clone().into();
|
let goal = obligation.as_goal();
|
||||||
let result = <&SolverDelegate<'tcx>>::from(infcx)
|
let result = <&SolverDelegate<'tcx>>::from(infcx)
|
||||||
.evaluate_root_goal(goal, GenerateProofTree::No, obligation.cause.span)
|
.evaluate_root_goal(goal, GenerateProofTree::No, obligation.cause.span)
|
||||||
.0;
|
.0;
|
||||||
|
|
|
@ -10,7 +10,7 @@ use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
use rustc_middle::{bug, span_bug};
|
use rustc_middle::{bug, span_bug};
|
||||||
use rustc_next_trait_solver::solve::{GenerateProofTree, SolverDelegateEvalExt as _};
|
use rustc_next_trait_solver::solve::{GenerateProofTree, SolverDelegateEvalExt as _};
|
||||||
use rustc_type_ir::solve::{Goal, NoSolution};
|
use rustc_type_ir::solve::NoSolution;
|
||||||
use tracing::{instrument, trace};
|
use tracing::{instrument, trace};
|
||||||
|
|
||||||
use crate::solve::Certainty;
|
use crate::solve::Certainty;
|
||||||
|
@ -89,7 +89,7 @@ pub(super) fn fulfillment_error_for_stalled<'tcx>(
|
||||||
let (code, refine_obligation) = infcx.probe(|_| {
|
let (code, refine_obligation) = infcx.probe(|_| {
|
||||||
match <&SolverDelegate<'tcx>>::from(infcx)
|
match <&SolverDelegate<'tcx>>::from(infcx)
|
||||||
.evaluate_root_goal(
|
.evaluate_root_goal(
|
||||||
root_obligation.clone().into(),
|
root_obligation.as_goal(),
|
||||||
GenerateProofTree::No,
|
GenerateProofTree::No,
|
||||||
root_obligation.cause.span,
|
root_obligation.cause.span,
|
||||||
)
|
)
|
||||||
|
@ -155,7 +155,7 @@ fn find_best_leaf_obligation<'tcx>(
|
||||||
.fudge_inference_if_ok(|| {
|
.fudge_inference_if_ok(|| {
|
||||||
infcx
|
infcx
|
||||||
.visit_proof_tree(
|
.visit_proof_tree(
|
||||||
obligation.clone().into(),
|
obligation.as_goal(),
|
||||||
&mut BestObligation { obligation: obligation.clone(), consider_ambiguities },
|
&mut BestObligation { obligation: obligation.clone(), consider_ambiguities },
|
||||||
)
|
)
|
||||||
.break_value()
|
.break_value()
|
||||||
|
@ -245,7 +245,7 @@ impl<'tcx> BestObligation<'tcx> {
|
||||||
{
|
{
|
||||||
let nested_goal = candidate.instantiate_proof_tree_for_nested_goal(
|
let nested_goal = candidate.instantiate_proof_tree_for_nested_goal(
|
||||||
GoalSource::Misc,
|
GoalSource::Misc,
|
||||||
Goal::new(infcx.tcx, obligation.param_env, obligation.predicate),
|
obligation.as_goal(),
|
||||||
self.span(),
|
self.span(),
|
||||||
);
|
);
|
||||||
// Skip nested goals that aren't the *reason* for our goal's failure.
|
// Skip nested goals that aren't the *reason* for our goal's failure.
|
||||||
|
|
|
@ -625,7 +625,7 @@ fn compute_intercrate_ambiguity_causes<'tcx>(
|
||||||
let mut causes: FxIndexSet<IntercrateAmbiguityCause<'tcx>> = Default::default();
|
let mut causes: FxIndexSet<IntercrateAmbiguityCause<'tcx>> = Default::default();
|
||||||
|
|
||||||
for obligation in obligations {
|
for obligation in obligations {
|
||||||
search_ambiguity_causes(infcx, obligation.clone().into(), &mut causes);
|
search_ambiguity_causes(infcx, obligation.as_goal(), &mut causes);
|
||||||
}
|
}
|
||||||
|
|
||||||
causes
|
causes
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue