Skip to main content

rustc_next_trait_solver/
delegate.rs

1use std::ops::Deref;
2
3use rustc_type_ir::solve::{
4    Certainty, ComputeGoalFastPathOutcome, FetchEligibleAssocItemResponse, Goal, NoSolution,
5    VisibleForLeakCheck,
6};
7use rustc_type_ir::{self as ty, InferCtxtLike, Interner, TypeFoldable};
8
9pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
10    type Infcx: InferCtxtLike<Interner = Self::Interner>;
11    type Interner: Interner;
12    fn cx(&self) -> Self::Interner {
13        (**self).cx()
14    }
15
16    fn build_with_canonical<V>(
17        cx: Self::Interner,
18        canonical: &ty::CanonicalQueryInput<Self::Interner, V>,
19    ) -> (Self, V, ty::CanonicalVarValues<Self::Interner>)
20    where
21        V: TypeFoldable<Self::Interner>;
22
23    fn compute_goal_fast_path(
24        &self,
25        goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
26        span: <Self::Interner as Interner>::Span,
27    ) -> ComputeGoalFastPathOutcome<Self::Interner>;
28
29    fn fresh_var_for_kind_with_span(
30        &self,
31        arg: <Self::Interner as Interner>::GenericArg,
32        span: <Self::Interner as Interner>::Span,
33    ) -> <Self::Interner as Interner>::GenericArg;
34
35    // FIXME: Uplift the leak check into this crate.
36    fn leak_check(&self, max_input_universe: ty::UniverseIndex) -> Result<(), NoSolution>;
37
38    fn evaluate_const(
39        &self,
40        param_env: <Self::Interner as Interner>::ParamEnv,
41        alias_const: ty::AliasConst<Self::Interner>,
42    ) -> Option<<Self::Interner as Interner>::Const>;
43
44    // FIXME: This only is here because `wf::obligations` is in `rustc_trait_selection`!
45    fn well_formed_goals(
46        &self,
47        param_env: <Self::Interner as Interner>::ParamEnv,
48        term: <Self::Interner as Interner>::Term,
49    ) -> Option<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>>;
50
51    fn make_deduplicated_region_constraints(
52        &self,
53    ) -> Vec<(ty::RegionConstraint<Self::Interner>, VisibleForLeakCheck)>;
54
55    fn instantiate_canonical<V>(
56        &self,
57        canonical: ty::Canonical<Self::Interner, V>,
58        values: ty::CanonicalVarValues<Self::Interner>,
59    ) -> V
60    where
61        V: TypeFoldable<Self::Interner>;
62
63    fn instantiate_canonical_var(
64        &self,
65        kind: ty::CanonicalVarKind<Self::Interner>,
66        span: <Self::Interner as Interner>::Span,
67        var_values: &[<Self::Interner as Interner>::GenericArg],
68        universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
69    ) -> <Self::Interner as Interner>::GenericArg;
70
71    fn add_item_bounds_for_hidden_type(
72        &self,
73        def_id: <Self::Interner as Interner>::OpaqueTyId,
74        args: <Self::Interner as Interner>::GenericArgs,
75        param_env: <Self::Interner as Interner>::ParamEnv,
76        hidden_ty: <Self::Interner as Interner>::Ty,
77        goals: &mut Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>,
78    );
79
80    fn fetch_eligible_assoc_item(
81        &self,
82        goal_trait_ref: ty::TraitRef<Self::Interner>,
83        trait_assoc_def_id: <Self::Interner as Interner>::TraitAssocTermId,
84        impl_def_id: <Self::Interner as Interner>::ImplId,
85    ) -> FetchEligibleAssocItemResponse<Self::Interner>;
86
87    fn is_transmutable(
88        &self,
89        src: <Self::Interner as Interner>::Ty,
90        dst: <Self::Interner as Interner>::Ty,
91        assume: <Self::Interner as Interner>::Const,
92    ) -> Result<Certainty, NoSolution>;
93}