rustc_next_trait_solver/
delegate.rs1use std::fmt::Debug;
2use std::ops::Deref;
3
4use rustc_type_ir::solve::{
5 Certainty, ComputeGoalFastPathOutcome, FetchEligibleAssocItemResponse, Goal, NoSolution,
6 VisibleForLeakCheck,
7};
8use rustc_type_ir::{self as ty, CanonicalizerState, InferCtxtLike, Interner, TypeFoldable};
9
10pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
27 type Infcx: InferCtxtLike<Interner = Self::Interner>;
28 type Interner: Interner;
29 fn cx(&self) -> Self::Interner {
30 (**self).cx()
31 }
32
33 fn build_with_canonical<V>(
34 cx: Self::Interner,
35 canonical: &ty::CanonicalQueryInput<Self::Interner, V>,
36 ) -> (Self, V, ty::CanonicalVarValues<Self::Interner>)
37 where
38 V: TypeFoldable<Self::Interner>;
39
40 fn compute_goal_fast_path(
41 &self,
42 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
43 span: <Self::Interner as Interner>::Span,
44 ) -> ComputeGoalFastPathOutcome<Self::Interner>;
45
46 fn fresh_var_for_kind(
47 &self,
48 arg: <Self::Interner as Interner>::GenericArg,
49 span: <Self::Interner as Interner>::Span,
50 universe: ty::UniverseIndex,
51 ) -> <Self::Interner as Interner>::GenericArg;
52
53 fn leak_check(&self, max_input_universe: ty::UniverseIndex) -> Result<(), NoSolution>;
55
56 fn evaluate_const<E: Debug>(
60 &self,
61 param_env: <Self::Interner as Interner>::ParamEnv,
62 alias_const: ty::AliasConst<Self::Interner>,
63 normalize_ty: impl FnOnce(
64 ty::Unnormalized<Self::Interner, <Self::Interner as Interner>::Ty>,
65 ) -> Result<<Self::Interner as Interner>::Ty, E>,
66 ) -> Result<Option<<Self::Interner as Interner>::Const>, E>;
67
68 fn well_formed_goals(
70 &self,
71 param_env: <Self::Interner as Interner>::ParamEnv,
72 term: <Self::Interner as Interner>::Term,
73 ) -> Option<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>>;
74
75 fn make_deduplicated_region_constraints(
76 &self,
77 ) -> Vec<(ty::RegionConstraint<Self::Interner>, VisibleForLeakCheck)>;
78
79 fn instantiate_canonical<V>(
80 &self,
81 canonical: ty::Canonical<Self::Interner, V>,
82 values: ty::CanonicalVarValues<Self::Interner>,
83 ) -> V
84 where
85 V: TypeFoldable<Self::Interner>;
86
87 fn instantiate_canonical_var(
88 &self,
89 kind: ty::CanonicalVarKind<Self::Interner>,
90 span: <Self::Interner as Interner>::Span,
91 var_values: &[<Self::Interner as Interner>::GenericArg],
92 universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
93 ) -> <Self::Interner as Interner>::GenericArg;
94
95 fn add_item_bounds_for_hidden_type(
96 &self,
97 def_id: <Self::Interner as Interner>::OpaqueTyId,
98 args: <Self::Interner as Interner>::GenericArgs,
99 param_env: <Self::Interner as Interner>::ParamEnv,
100 hidden_ty: <Self::Interner as Interner>::Ty,
101 goals: &mut Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>,
102 );
103
104 fn fetch_eligible_assoc_item(
105 &self,
106 goal_trait_ref: ty::TraitRef<Self::Interner>,
107 trait_assoc_def_id: <Self::Interner as Interner>::TraitAssocTermId,
108 impl_def_id: <Self::Interner as Interner>::ImplId,
109 ) -> FetchEligibleAssocItemResponse<Self::Interner>;
110
111 fn is_transmutable(
112 &self,
113 src: <Self::Interner as Interner>::Ty,
114 dst: <Self::Interner as Interner>::Ty,
115 assume: <Self::Interner as Interner>::Const,
116 ) -> Result<Certainty, NoSolution>;
117
118 fn obtain_canonicalizer_state(&self) -> CanonicalizerState<Self::Interner> {
121 Default::default()
122 }
123
124 fn release_canonicalizer_state(&self, _: CanonicalizerState<Self::Interner>) {}
127
128 fn emit_next_solver_overflow_fcw(
129 &self,
130 goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
131 span: <Self::Interner as Interner>::Span,
132 );
133}