1use derive_where::derive_where;
2#[cfg(feature = "nightly")]
3use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable};
4use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic};
5
6use crate::fold::TypeFoldable;
7use crate::relate::RelateResult;
8use crate::relate::combine::PredicateEmittingRelation;
9use crate::{self as ty, Interner};
10
11#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)]
22#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
23#[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable, HashStable_NoContext))]
24pub enum TypingMode<I: Interner> {
25 Coherence,
37 Analysis { defining_opaque_types: I::DefiningOpaqueTypes },
66 PostBorrowckAnalysis { defined_opaque_types: I::DefiningOpaqueTypes },
72 PostAnalysis,
81}
82
83impl<I: Interner> TypingMode<I> {
84 pub fn non_body_analysis() -> TypingMode<I> {
86 TypingMode::Analysis { defining_opaque_types: Default::default() }
87 }
88
89 pub fn analysis_in_body(cx: I, body_def_id: I::LocalDefId) -> TypingMode<I> {
92 TypingMode::Analysis { defining_opaque_types: cx.opaque_types_defined_by(body_def_id) }
93 }
94
95 pub fn post_borrowck_analysis(cx: I, body_def_id: I::LocalDefId) -> TypingMode<I> {
96 TypingMode::PostBorrowckAnalysis {
97 defined_opaque_types: cx.opaque_types_defined_by(body_def_id),
98 }
99 }
100}
101
102pub trait InferCtxtLike: Sized {
103 type Interner: Interner;
104 fn cx(&self) -> Self::Interner;
105
106 fn next_trait_solver(&self) -> bool {
111 true
112 }
113
114 fn typing_mode(&self) -> TypingMode<Self::Interner>;
115
116 fn universe(&self) -> ty::UniverseIndex;
117 fn create_next_universe(&self) -> ty::UniverseIndex;
118
119 fn universe_of_ty(&self, ty: ty::TyVid) -> Option<ty::UniverseIndex>;
120 fn universe_of_lt(&self, lt: ty::RegionVid) -> Option<ty::UniverseIndex>;
121 fn universe_of_ct(&self, ct: ty::ConstVid) -> Option<ty::UniverseIndex>;
122
123 fn root_ty_var(&self, var: ty::TyVid) -> ty::TyVid;
124 fn root_const_var(&self, var: ty::ConstVid) -> ty::ConstVid;
125
126 fn opportunistic_resolve_ty_var(&self, vid: ty::TyVid) -> <Self::Interner as Interner>::Ty;
127 fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> <Self::Interner as Interner>::Ty;
128 fn opportunistic_resolve_float_var(
129 &self,
130 vid: ty::FloatVid,
131 ) -> <Self::Interner as Interner>::Ty;
132 fn opportunistic_resolve_ct_var(
133 &self,
134 vid: ty::ConstVid,
135 ) -> <Self::Interner as Interner>::Const;
136 fn opportunistic_resolve_lt_var(
137 &self,
138 vid: ty::RegionVid,
139 ) -> <Self::Interner as Interner>::Region;
140
141 fn next_region_infer(&self) -> <Self::Interner as Interner>::Region;
142 fn next_ty_infer(&self) -> <Self::Interner as Interner>::Ty;
143 fn next_const_infer(&self) -> <Self::Interner as Interner>::Const;
144 fn fresh_args_for_item(
145 &self,
146 def_id: <Self::Interner as Interner>::DefId,
147 ) -> <Self::Interner as Interner>::GenericArgs;
148
149 fn instantiate_binder_with_infer<T: TypeFoldable<Self::Interner> + Copy>(
150 &self,
151 value: ty::Binder<Self::Interner, T>,
152 ) -> T;
153
154 fn enter_forall<T: TypeFoldable<Self::Interner> + Copy, U>(
155 &self,
156 value: ty::Binder<Self::Interner, T>,
157 f: impl FnOnce(T) -> U,
158 ) -> U;
159
160 fn equate_ty_vids_raw(&self, a: ty::TyVid, b: ty::TyVid);
161 fn equate_int_vids_raw(&self, a: ty::IntVid, b: ty::IntVid);
162 fn equate_float_vids_raw(&self, a: ty::FloatVid, b: ty::FloatVid);
163 fn equate_const_vids_raw(&self, a: ty::ConstVid, b: ty::ConstVid);
164
165 fn instantiate_ty_var_raw<R: PredicateEmittingRelation<Self>>(
166 &self,
167 relation: &mut R,
168 target_is_expected: bool,
169 target_vid: ty::TyVid,
170 instantiation_variance: ty::Variance,
171 source_ty: <Self::Interner as Interner>::Ty,
172 ) -> RelateResult<Self::Interner, ()>;
173 fn instantiate_int_var_raw(&self, vid: ty::IntVid, value: ty::IntVarValue);
174 fn instantiate_float_var_raw(&self, vid: ty::FloatVid, value: ty::FloatVarValue);
175 fn instantiate_const_var_raw<R: PredicateEmittingRelation<Self>>(
176 &self,
177 relation: &mut R,
178 target_is_expected: bool,
179 target_vid: ty::ConstVid,
180 source_ct: <Self::Interner as Interner>::Const,
181 ) -> RelateResult<Self::Interner, ()>;
182
183 fn set_tainted_by_errors(&self, e: <Self::Interner as Interner>::ErrorGuaranteed);
184
185 fn shallow_resolve(
186 &self,
187 ty: <Self::Interner as Interner>::Ty,
188 ) -> <Self::Interner as Interner>::Ty;
189 fn shallow_resolve_const(
190 &self,
191 ty: <Self::Interner as Interner>::Const,
192 ) -> <Self::Interner as Interner>::Const;
193
194 fn resolve_vars_if_possible<T>(&self, value: T) -> T
195 where
196 T: TypeFoldable<Self::Interner>;
197
198 fn probe<T>(&self, probe: impl FnOnce() -> T) -> T;
199
200 fn sub_regions(
201 &self,
202 sub: <Self::Interner as Interner>::Region,
203 sup: <Self::Interner as Interner>::Region,
204 span: <Self::Interner as Interner>::Span,
205 );
206
207 fn equate_regions(
208 &self,
209 a: <Self::Interner as Interner>::Region,
210 b: <Self::Interner as Interner>::Region,
211 span: <Self::Interner as Interner>::Span,
212 );
213
214 fn register_ty_outlives(
215 &self,
216 ty: <Self::Interner as Interner>::Ty,
217 r: <Self::Interner as Interner>::Region,
218 span: <Self::Interner as Interner>::Span,
219 );
220}