1use rustc_hir::def_id::DefId;
3use rustc_middle::traits::ObligationCause;
4use rustc_middle::ty::relate::RelateResult;
5use rustc_middle::ty::relate::combine::PredicateEmittingRelation;
6use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
7use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
8
9use super::{BoundRegionConversionTime, InferCtxt, RegionVariableOrigin, SubregionOrigin};
10
11impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
12 type Interner = TyCtxt<'tcx>;
13
14 fn cx(&self) -> TyCtxt<'tcx> {
15 self.tcx
16 }
17
18 fn next_trait_solver(&self) -> bool {
19 self.next_trait_solver
20 }
21
22 fn typing_mode(&self) -> ty::TypingMode<'tcx> {
23 self.typing_mode()
24 }
25
26 fn universe(&self) -> ty::UniverseIndex {
27 self.universe()
28 }
29
30 fn create_next_universe(&self) -> ty::UniverseIndex {
31 self.create_next_universe()
32 }
33
34 fn universe_of_ty(&self, vid: ty::TyVid) -> Option<ty::UniverseIndex> {
35 match self.probe_ty_var(vid) {
36 Err(universe) => Some(universe),
37 Ok(_) => None,
38 }
39 }
40
41 fn universe_of_lt(&self, lt: ty::RegionVid) -> Option<ty::UniverseIndex> {
42 match self.inner.borrow_mut().unwrap_region_constraints().probe_value(lt) {
43 Err(universe) => Some(universe),
44 Ok(_) => None,
45 }
46 }
47
48 fn universe_of_ct(&self, ct: ty::ConstVid) -> Option<ty::UniverseIndex> {
49 match self.probe_const_var(ct) {
50 Err(universe) => Some(universe),
51 Ok(_) => None,
52 }
53 }
54
55 fn root_ty_var(&self, var: ty::TyVid) -> ty::TyVid {
56 self.root_var(var)
57 }
58
59 fn root_const_var(&self, var: ty::ConstVid) -> ty::ConstVid {
60 self.root_const_var(var)
61 }
62
63 fn opportunistic_resolve_ty_var(&self, vid: ty::TyVid) -> Ty<'tcx> {
64 match self.probe_ty_var(vid) {
65 Ok(ty) => ty,
66 Err(_) => Ty::new_var(self.tcx, self.root_var(vid)),
67 }
68 }
69
70 fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> Ty<'tcx> {
71 self.opportunistic_resolve_int_var(vid)
72 }
73
74 fn opportunistic_resolve_float_var(&self, vid: ty::FloatVid) -> Ty<'tcx> {
75 self.opportunistic_resolve_float_var(vid)
76 }
77
78 fn opportunistic_resolve_ct_var(&self, vid: ty::ConstVid) -> ty::Const<'tcx> {
79 match self.probe_const_var(vid) {
80 Ok(ct) => ct,
81 Err(_) => ty::Const::new_var(self.tcx, self.root_const_var(vid)),
82 }
83 }
84
85 fn opportunistic_resolve_lt_var(&self, vid: ty::RegionVid) -> ty::Region<'tcx> {
86 self.inner.borrow_mut().unwrap_region_constraints().opportunistic_resolve_var(self.tcx, vid)
87 }
88
89 fn next_region_infer(&self) -> ty::Region<'tcx> {
90 self.next_region_var(RegionVariableOrigin::MiscVariable(DUMMY_SP))
91 }
92
93 fn next_ty_infer(&self) -> Ty<'tcx> {
94 self.next_ty_var(DUMMY_SP)
95 }
96
97 fn next_const_infer(&self) -> ty::Const<'tcx> {
98 self.next_const_var(DUMMY_SP)
99 }
100
101 fn fresh_args_for_item(&self, def_id: DefId) -> ty::GenericArgsRef<'tcx> {
102 self.fresh_args_for_item(DUMMY_SP, def_id)
103 }
104
105 fn instantiate_binder_with_infer<T: TypeFoldable<TyCtxt<'tcx>> + Copy>(
106 &self,
107 value: ty::Binder<'tcx, T>,
108 ) -> T {
109 self.instantiate_binder_with_fresh_vars(
110 DUMMY_SP,
111 BoundRegionConversionTime::HigherRankedType,
112 value,
113 )
114 }
115
116 fn enter_forall<T: TypeFoldable<TyCtxt<'tcx>>, U>(
117 &self,
118 value: ty::Binder<'tcx, T>,
119 f: impl FnOnce(T) -> U,
120 ) -> U {
121 self.enter_forall(value, f)
122 }
123
124 fn equate_ty_vids_raw(&self, a: rustc_type_ir::TyVid, b: rustc_type_ir::TyVid) {
125 self.inner.borrow_mut().type_variables().equate(a, b);
126 }
127
128 fn equate_int_vids_raw(&self, a: rustc_type_ir::IntVid, b: rustc_type_ir::IntVid) {
129 self.inner.borrow_mut().int_unification_table().union(a, b);
130 }
131
132 fn equate_float_vids_raw(&self, a: rustc_type_ir::FloatVid, b: rustc_type_ir::FloatVid) {
133 self.inner.borrow_mut().float_unification_table().union(a, b);
134 }
135
136 fn equate_const_vids_raw(&self, a: rustc_type_ir::ConstVid, b: rustc_type_ir::ConstVid) {
137 self.inner.borrow_mut().const_unification_table().union(a, b);
138 }
139
140 fn instantiate_ty_var_raw<R: PredicateEmittingRelation<Self>>(
141 &self,
142 relation: &mut R,
143 target_is_expected: bool,
144 target_vid: rustc_type_ir::TyVid,
145 instantiation_variance: rustc_type_ir::Variance,
146 source_ty: Ty<'tcx>,
147 ) -> RelateResult<'tcx, ()> {
148 self.instantiate_ty_var(
149 relation,
150 target_is_expected,
151 target_vid,
152 instantiation_variance,
153 source_ty,
154 )
155 }
156
157 fn instantiate_int_var_raw(
158 &self,
159 vid: rustc_type_ir::IntVid,
160 value: rustc_type_ir::IntVarValue,
161 ) {
162 self.inner.borrow_mut().int_unification_table().union_value(vid, value);
163 }
164
165 fn instantiate_float_var_raw(
166 &self,
167 vid: rustc_type_ir::FloatVid,
168 value: rustc_type_ir::FloatVarValue,
169 ) {
170 self.inner.borrow_mut().float_unification_table().union_value(vid, value);
171 }
172
173 fn instantiate_const_var_raw<R: PredicateEmittingRelation<Self>>(
174 &self,
175 relation: &mut R,
176 target_is_expected: bool,
177 target_vid: rustc_type_ir::ConstVid,
178 source_ct: ty::Const<'tcx>,
179 ) -> RelateResult<'tcx, ()> {
180 self.instantiate_const_var(relation, target_is_expected, target_vid, source_ct)
181 }
182
183 fn set_tainted_by_errors(&self, e: ErrorGuaranteed) {
184 self.set_tainted_by_errors(e)
185 }
186
187 fn shallow_resolve(&self, ty: Ty<'tcx>) -> Ty<'tcx> {
188 self.shallow_resolve(ty)
189 }
190 fn shallow_resolve_const(&self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
191 self.shallow_resolve_const(ct)
192 }
193
194 fn resolve_vars_if_possible<T>(&self, value: T) -> T
195 where
196 T: TypeFoldable<TyCtxt<'tcx>>,
197 {
198 self.resolve_vars_if_possible(value)
199 }
200
201 fn probe<T>(&self, probe: impl FnOnce() -> T) -> T {
202 self.probe(|_| probe())
203 }
204
205 fn sub_regions(&self, sub: ty::Region<'tcx>, sup: ty::Region<'tcx>, span: Span) {
206 self.inner.borrow_mut().unwrap_region_constraints().make_subregion(
207 SubregionOrigin::RelateRegionParamBound(span, None),
208 sub,
209 sup,
210 );
211 }
212
213 fn equate_regions(&self, a: ty::Region<'tcx>, b: ty::Region<'tcx>, span: Span) {
214 self.inner.borrow_mut().unwrap_region_constraints().make_eqregion(
215 SubregionOrigin::RelateRegionParamBound(span, None),
216 a,
217 b,
218 );
219 }
220
221 fn register_ty_outlives(&self, ty: Ty<'tcx>, r: ty::Region<'tcx>, span: Span) {
222 self.register_region_obligation_with_cause(ty, r, &ObligationCause::dummy_with_span(span));
223 }
224}