rustc_next_trait_solver/
delegate.rs

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