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 fresh_var_for_kind_with_span(
21        &self,
22        arg: <Self::Interner as Interner>::GenericArg,
23        span: <Self::Interner as Interner>::Span,
24    ) -> <Self::Interner as Interner>::GenericArg;
25
26    // FIXME: Uplift the leak check into this crate.
27    fn leak_check(&self, max_input_universe: ty::UniverseIndex) -> Result<(), NoSolution>;
28
29    fn evaluate_const(
30        &self,
31        param_env: <Self::Interner as Interner>::ParamEnv,
32        uv: ty::UnevaluatedConst<Self::Interner>,
33    ) -> Option<<Self::Interner as Interner>::Const>;
34
35    // FIXME: This only is here because `wf::obligations` is in `rustc_trait_selection`!
36    fn well_formed_goals(
37        &self,
38        param_env: <Self::Interner as Interner>::ParamEnv,
39        arg: <Self::Interner as Interner>::GenericArg,
40    ) -> Option<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>>;
41
42    fn clone_opaque_types_for_query_response(
43        &self,
44    ) -> Vec<(ty::OpaqueTypeKey<Self::Interner>, <Self::Interner as Interner>::Ty)>;
45
46    fn make_deduplicated_outlives_constraints(
47        &self,
48    ) -> Vec<ty::OutlivesPredicate<Self::Interner, <Self::Interner as Interner>::GenericArg>>;
49
50    fn instantiate_canonical<V>(
51        &self,
52        canonical: ty::Canonical<Self::Interner, V>,
53        values: ty::CanonicalVarValues<Self::Interner>,
54    ) -> V
55    where
56        V: TypeFoldable<Self::Interner>;
57
58    fn instantiate_canonical_var_with_infer(
59        &self,
60        cv_info: ty::CanonicalVarInfo<Self::Interner>,
61        span: <Self::Interner as Interner>::Span,
62        universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
63    ) -> <Self::Interner as Interner>::GenericArg;
64
65    // FIXME: Can we implement this in terms of `add` and `inject`?
66    fn insert_hidden_type(
67        &self,
68        opaque_type_key: ty::OpaqueTypeKey<Self::Interner>,
69        param_env: <Self::Interner as Interner>::ParamEnv,
70        hidden_ty: <Self::Interner as Interner>::Ty,
71        goals: &mut Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>,
72    ) -> Result<(), NoSolution>;
73
74    fn add_item_bounds_for_hidden_type(
75        &self,
76        def_id: <Self::Interner as Interner>::DefId,
77        args: <Self::Interner as Interner>::GenericArgs,
78        param_env: <Self::Interner as Interner>::ParamEnv,
79        hidden_ty: <Self::Interner as Interner>::Ty,
80        goals: &mut Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>,
81    );
82
83    fn inject_new_hidden_type_unchecked(
84        &self,
85        key: ty::OpaqueTypeKey<Self::Interner>,
86        hidden_ty: <Self::Interner as Interner>::Ty,
87        span: <Self::Interner as Interner>::Span,
88    );
89
90    fn reset_opaque_types(&self);
91
92    fn fetch_eligible_assoc_item(
93        &self,
94        goal_trait_ref: ty::TraitRef<Self::Interner>,
95        trait_assoc_def_id: <Self::Interner as Interner>::DefId,
96        impl_def_id: <Self::Interner as Interner>::DefId,
97    ) -> Result<
98        Option<<Self::Interner as Interner>::DefId>,
99        <Self::Interner as Interner>::ErrorGuaranteed,
100    >;
101
102    fn is_transmutable(
103        &self,
104        dst: <Self::Interner as Interner>::Ty,
105        src: <Self::Interner as Interner>::Ty,
106        assume: <Self::Interner as Interner>::Const,
107    ) -> Result<Certainty, NoSolution>;
108}