rustc_next_trait_solver/
delegate.rs

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