Skip to content

Commit 575f129

Browse files
Obligation::as_goal
1 parent aa8f0fd commit 575f129

File tree

7 files changed

+17
-18
lines changed

7 files changed

+17
-18
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A utility module to inspect currently ambiguous obligations in the current context.
22
33
use rustc_infer::traits::{self, ObligationCause, PredicateObligations};
4-
use rustc_middle::traits::solve::{Goal, GoalSource};
4+
use rustc_middle::traits::solve::GoalSource;
55
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
66
use rustc_span::Span;
77
use rustc_trait_selection::solve::inspect::{
@@ -85,7 +85,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8585
root_cause: &obligation.cause,
8686
};
8787

88-
let goal = Goal::new(self.tcx, obligation.param_env, obligation.predicate);
88+
let goal = obligation.as_goal();
8989
self.visit_proof_tree(goal, &mut visitor);
9090
}
9191

compiler/rustc_infer/src/infer/opaque_types/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ impl<'tcx> InferCtxt<'tcx> {
246246
.eq(DefineOpaqueTypes::Yes, prev, hidden_ty)?
247247
.obligations
248248
.into_iter()
249-
// FIXME: Shuttling between obligations and goals is awkward.
250-
.map(Goal::from),
249+
.map(|obligation| obligation.as_goal()),
251250
);
252251
}
253252
}

compiler/rustc_infer/src/traits/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ pub struct Obligation<'tcx, T> {
5454
pub recursion_depth: usize,
5555
}
5656

57+
impl<'tcx, T: Copy> Obligation<'tcx, T> {
58+
pub fn as_goal(&self) -> solve::Goal<'tcx, T> {
59+
solve::Goal { param_env: self.param_env, predicate: self.predicate }
60+
}
61+
}
62+
5763
impl<'tcx, T: PartialEq> PartialEq<Obligation<'tcx, T>> for Obligation<'tcx, T> {
5864
#[inline]
5965
fn eq(&self, other: &Obligation<'tcx, T>) -> bool {
@@ -75,12 +81,6 @@ impl<T: Hash> Hash for Obligation<'_, T> {
7581
}
7682
}
7783

78-
impl<'tcx, P> From<Obligation<'tcx, P>> for solve::Goal<'tcx, P> {
79-
fn from(value: Obligation<'tcx, P>) -> Self {
80-
solve::Goal { param_env: value.param_env, predicate: value.predicate }
81-
}
82-
}
83-
8484
pub type PredicateObligation<'tcx> = Obligation<'tcx, ty::Predicate<'tcx>>;
8585
pub type TraitObligation<'tcx> = Obligation<'tcx, ty::TraitPredicate<'tcx>>;
8686
pub type PolyTraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>;

compiler/rustc_trait_selection/src/solve/delegate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
9696
) -> Option<Vec<Goal<'tcx, ty::Predicate<'tcx>>>> {
9797
crate::traits::wf::unnormalized_obligations(&self.0, param_env, arg, DUMMY_SP, CRATE_DEF_ID)
9898
.map(|obligations| {
99-
obligations.into_iter().map(|obligation| obligation.into()).collect()
99+
obligations.into_iter().map(|obligation| obligation.as_goal()).collect()
100100
})
101101
}
102102

compiler/rustc_trait_selection/src/solve/fulfill.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<'tcx> ObligationStorage<'tcx> {
8080
// change.
8181
// FIXME: <https://github.com/Gankra/thin-vec/pull/66> is merged, this can be removed.
8282
self.overflowed.extend(ExtractIf::new(&mut self.pending, |o| {
83-
let goal = o.clone().into();
83+
let goal = o.as_goal();
8484
let result = <&SolverDelegate<'tcx>>::from(infcx)
8585
.evaluate_root_goal(goal, GenerateProofTree::No, o.cause.span)
8686
.0;
@@ -161,7 +161,7 @@ where
161161

162162
let mut has_changed = false;
163163
for obligation in self.obligations.unstalled_for_select() {
164-
let goal = obligation.clone().into();
164+
let goal = obligation.as_goal();
165165
let result = <&SolverDelegate<'tcx>>::from(infcx)
166166
.evaluate_root_goal(goal, GenerateProofTree::No, obligation.cause.span)
167167
.0;

compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::ty::error::{ExpectedFound, TypeError};
1010
use rustc_middle::ty::{self, Ty, TyCtxt};
1111
use rustc_middle::{bug, span_bug};
1212
use rustc_next_trait_solver::solve::{GenerateProofTree, SolverDelegateEvalExt as _};
13-
use rustc_type_ir::solve::{Goal, NoSolution};
13+
use rustc_type_ir::solve::NoSolution;
1414
use tracing::{instrument, trace};
1515

1616
use crate::solve::Certainty;
@@ -89,7 +89,7 @@ pub(super) fn fulfillment_error_for_stalled<'tcx>(
8989
let (code, refine_obligation) = infcx.probe(|_| {
9090
match <&SolverDelegate<'tcx>>::from(infcx)
9191
.evaluate_root_goal(
92-
root_obligation.clone().into(),
92+
root_obligation.as_goal(),
9393
GenerateProofTree::No,
9494
root_obligation.cause.span,
9595
)
@@ -155,7 +155,7 @@ fn find_best_leaf_obligation<'tcx>(
155155
.fudge_inference_if_ok(|| {
156156
infcx
157157
.visit_proof_tree(
158-
obligation.clone().into(),
158+
obligation.as_goal(),
159159
&mut BestObligation { obligation: obligation.clone(), consider_ambiguities },
160160
)
161161
.break_value()
@@ -245,7 +245,7 @@ impl<'tcx> BestObligation<'tcx> {
245245
{
246246
let nested_goal = candidate.instantiate_proof_tree_for_nested_goal(
247247
GoalSource::Misc,
248-
Goal::new(infcx.tcx, obligation.param_env, obligation.predicate),
248+
obligation.as_goal(),
249249
self.span(),
250250
);
251251
// Skip nested goals that aren't the *reason* for our goal's failure.

compiler/rustc_trait_selection/src/traits/coherence.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ fn compute_intercrate_ambiguity_causes<'tcx>(
625625
let mut causes: FxIndexSet<IntercrateAmbiguityCause<'tcx>> = Default::default();
626626

627627
for obligation in obligations {
628-
search_ambiguity_causes(infcx, obligation.clone().into(), &mut causes);
628+
search_ambiguity_causes(infcx, obligation.as_goal(), &mut causes);
629629
}
630630

631631
causes

0 commit comments

Comments
 (0)