|
18 | 18 | //! On success, the LUB/GLB operations return the appropriate bound. The
|
19 | 19 | //! return value of `Equate` or `Sub` shouldn't really be used.
|
20 | 20 |
|
21 |
| -use rustc_middle::bug; |
22 |
| -use rustc_middle::infer::unify_key::EffectVarValue; |
23 | 21 | use rustc_middle::traits::solve::Goal;
|
24 |
| -use rustc_middle::ty::error::{ExpectedFound, TypeError}; |
25 |
| -use rustc_middle::ty::{self, InferConst, IntType, Ty, TyCtxt, TypeVisitableExt, UintType, Upcast}; |
26 |
| -pub use rustc_next_trait_solver::relate::combine::*; |
27 |
| -use tracing::debug; |
| 22 | +pub use rustc_middle::ty::relate::combine::*; |
| 23 | +use rustc_middle::ty::{self, TyCtxt, Upcast}; |
28 | 24 |
|
| 25 | +use super::StructurallyRelateAliases; |
29 | 26 | use super::glb::Glb;
|
30 | 27 | use super::lub::Lub;
|
31 | 28 | use super::type_relating::TypeRelating;
|
32 |
| -use super::{RelateResult, StructurallyRelateAliases}; |
33 |
| -use crate::infer::{DefineOpaqueTypes, InferCtxt, TypeTrace, relate}; |
| 29 | +use crate::infer::{DefineOpaqueTypes, InferCtxt, TypeTrace}; |
34 | 30 | use crate::traits::{Obligation, PredicateObligation};
|
35 | 31 |
|
36 | 32 | #[derive(Clone)]
|
@@ -67,222 +63,6 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
|
67 | 63 | }
|
68 | 64 | }
|
69 | 65 |
|
70 |
| -impl<'tcx> InferCtxt<'tcx> { |
71 |
| - pub fn super_combine_tys<R>( |
72 |
| - &self, |
73 |
| - relation: &mut R, |
74 |
| - a: Ty<'tcx>, |
75 |
| - b: Ty<'tcx>, |
76 |
| - ) -> RelateResult<'tcx, Ty<'tcx>> |
77 |
| - where |
78 |
| - R: PredicateEmittingRelation<InferCtxt<'tcx>>, |
79 |
| - { |
80 |
| - debug!("super_combine_tys::<{}>({:?}, {:?})", std::any::type_name::<R>(), a, b); |
81 |
| - debug_assert!(!a.has_escaping_bound_vars()); |
82 |
| - debug_assert!(!b.has_escaping_bound_vars()); |
83 |
| - |
84 |
| - match (a.kind(), b.kind()) { |
85 |
| - (&ty::Error(e), _) | (_, &ty::Error(e)) => { |
86 |
| - self.set_tainted_by_errors(e); |
87 |
| - return Ok(Ty::new_error(self.tcx, e)); |
88 |
| - } |
89 |
| - |
90 |
| - // Relate integral variables to other types |
91 |
| - (&ty::Infer(ty::IntVar(a_id)), &ty::Infer(ty::IntVar(b_id))) => { |
92 |
| - self.inner.borrow_mut().int_unification_table().union(a_id, b_id); |
93 |
| - Ok(a) |
94 |
| - } |
95 |
| - (&ty::Infer(ty::IntVar(v_id)), &ty::Int(v)) => { |
96 |
| - self.unify_integral_variable(v_id, IntType(v)); |
97 |
| - Ok(b) |
98 |
| - } |
99 |
| - (&ty::Int(v), &ty::Infer(ty::IntVar(v_id))) => { |
100 |
| - self.unify_integral_variable(v_id, IntType(v)); |
101 |
| - Ok(a) |
102 |
| - } |
103 |
| - (&ty::Infer(ty::IntVar(v_id)), &ty::Uint(v)) => { |
104 |
| - self.unify_integral_variable(v_id, UintType(v)); |
105 |
| - Ok(b) |
106 |
| - } |
107 |
| - (&ty::Uint(v), &ty::Infer(ty::IntVar(v_id))) => { |
108 |
| - self.unify_integral_variable(v_id, UintType(v)); |
109 |
| - Ok(a) |
110 |
| - } |
111 |
| - |
112 |
| - // Relate floating-point variables to other types |
113 |
| - (&ty::Infer(ty::FloatVar(a_id)), &ty::Infer(ty::FloatVar(b_id))) => { |
114 |
| - self.inner.borrow_mut().float_unification_table().union(a_id, b_id); |
115 |
| - Ok(a) |
116 |
| - } |
117 |
| - (&ty::Infer(ty::FloatVar(v_id)), &ty::Float(v)) => { |
118 |
| - self.unify_float_variable(v_id, ty::FloatVarValue::Known(v)); |
119 |
| - Ok(b) |
120 |
| - } |
121 |
| - (&ty::Float(v), &ty::Infer(ty::FloatVar(v_id))) => { |
122 |
| - self.unify_float_variable(v_id, ty::FloatVarValue::Known(v)); |
123 |
| - Ok(a) |
124 |
| - } |
125 |
| - |
126 |
| - // We don't expect `TyVar` or `Fresh*` vars at this point with lazy norm. |
127 |
| - (ty::Alias(..), ty::Infer(ty::TyVar(_))) | (ty::Infer(ty::TyVar(_)), ty::Alias(..)) |
128 |
| - if self.next_trait_solver() => |
129 |
| - { |
130 |
| - bug!( |
131 |
| - "We do not expect to encounter `TyVar` this late in combine \ |
132 |
| - -- they should have been handled earlier" |
133 |
| - ) |
134 |
| - } |
135 |
| - (_, ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))) |
136 |
| - | (ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)), _) |
137 |
| - if self.next_trait_solver() => |
138 |
| - { |
139 |
| - bug!("We do not expect to encounter `Fresh` variables in the new solver") |
140 |
| - } |
141 |
| - |
142 |
| - (_, ty::Alias(..)) | (ty::Alias(..), _) if self.next_trait_solver() => { |
143 |
| - match relation.structurally_relate_aliases() { |
144 |
| - StructurallyRelateAliases::Yes => { |
145 |
| - relate::structurally_relate_tys(relation, a, b) |
146 |
| - } |
147 |
| - StructurallyRelateAliases::No => { |
148 |
| - relation.register_alias_relate_predicate(a, b); |
149 |
| - Ok(a) |
150 |
| - } |
151 |
| - } |
152 |
| - } |
153 |
| - |
154 |
| - // All other cases of inference are errors |
155 |
| - (&ty::Infer(_), _) | (_, &ty::Infer(_)) => { |
156 |
| - Err(TypeError::Sorts(ExpectedFound::new(true, a, b))) |
157 |
| - } |
158 |
| - |
159 |
| - // During coherence, opaque types should be treated as *possibly* |
160 |
| - // equal to any other type (except for possibly itself). This is an |
161 |
| - // extremely heavy hammer, but can be relaxed in a forwards-compatible |
162 |
| - // way later. |
163 |
| - (&ty::Alias(ty::Opaque, _), _) | (_, &ty::Alias(ty::Opaque, _)) if self.intercrate => { |
164 |
| - relation.register_predicates([ty::Binder::dummy(ty::PredicateKind::Ambiguous)]); |
165 |
| - Ok(a) |
166 |
| - } |
167 |
| - |
168 |
| - _ => relate::structurally_relate_tys(relation, a, b), |
169 |
| - } |
170 |
| - } |
171 |
| - |
172 |
| - pub fn super_combine_consts<R>( |
173 |
| - &self, |
174 |
| - relation: &mut R, |
175 |
| - a: ty::Const<'tcx>, |
176 |
| - b: ty::Const<'tcx>, |
177 |
| - ) -> RelateResult<'tcx, ty::Const<'tcx>> |
178 |
| - where |
179 |
| - R: PredicateEmittingRelation<InferCtxt<'tcx>>, |
180 |
| - { |
181 |
| - debug!("super_combine_consts::<{}>({:?}, {:?})", std::any::type_name::<R>(), a, b); |
182 |
| - debug_assert!(!a.has_escaping_bound_vars()); |
183 |
| - debug_assert!(!b.has_escaping_bound_vars()); |
184 |
| - |
185 |
| - if a == b { |
186 |
| - return Ok(a); |
187 |
| - } |
188 |
| - |
189 |
| - let a = self.shallow_resolve_const(a); |
190 |
| - let b = self.shallow_resolve_const(b); |
191 |
| - |
192 |
| - match (a.kind(), b.kind()) { |
193 |
| - ( |
194 |
| - ty::ConstKind::Infer(InferConst::Var(a_vid)), |
195 |
| - ty::ConstKind::Infer(InferConst::Var(b_vid)), |
196 |
| - ) => { |
197 |
| - self.inner.borrow_mut().const_unification_table().union(a_vid, b_vid); |
198 |
| - Ok(a) |
199 |
| - } |
200 |
| - |
201 |
| - ( |
202 |
| - ty::ConstKind::Infer(InferConst::EffectVar(a_vid)), |
203 |
| - ty::ConstKind::Infer(InferConst::EffectVar(b_vid)), |
204 |
| - ) => { |
205 |
| - self.inner.borrow_mut().effect_unification_table().union(a_vid, b_vid); |
206 |
| - Ok(a) |
207 |
| - } |
208 |
| - |
209 |
| - // All other cases of inference with other variables are errors. |
210 |
| - ( |
211 |
| - ty::ConstKind::Infer(InferConst::Var(_) | InferConst::EffectVar(_)), |
212 |
| - ty::ConstKind::Infer(_), |
213 |
| - ) |
214 |
| - | ( |
215 |
| - ty::ConstKind::Infer(_), |
216 |
| - ty::ConstKind::Infer(InferConst::Var(_) | InferConst::EffectVar(_)), |
217 |
| - ) => { |
218 |
| - bug!( |
219 |
| - "tried to combine ConstKind::Infer/ConstKind::Infer(InferConst::Var): {a:?} and {b:?}" |
220 |
| - ) |
221 |
| - } |
222 |
| - |
223 |
| - (ty::ConstKind::Infer(InferConst::Var(vid)), _) => { |
224 |
| - self.instantiate_const_var(relation, true, vid, b)?; |
225 |
| - Ok(b) |
226 |
| - } |
227 |
| - |
228 |
| - (_, ty::ConstKind::Infer(InferConst::Var(vid))) => { |
229 |
| - self.instantiate_const_var(relation, false, vid, a)?; |
230 |
| - Ok(a) |
231 |
| - } |
232 |
| - |
233 |
| - (ty::ConstKind::Infer(InferConst::EffectVar(vid)), _) => { |
234 |
| - Ok(self.unify_effect_variable(vid, b)) |
235 |
| - } |
236 |
| - |
237 |
| - (_, ty::ConstKind::Infer(InferConst::EffectVar(vid))) => { |
238 |
| - Ok(self.unify_effect_variable(vid, a)) |
239 |
| - } |
240 |
| - |
241 |
| - (ty::ConstKind::Unevaluated(..), _) | (_, ty::ConstKind::Unevaluated(..)) |
242 |
| - if self.tcx.features().generic_const_exprs || self.next_trait_solver() => |
243 |
| - { |
244 |
| - match relation.structurally_relate_aliases() { |
245 |
| - StructurallyRelateAliases::No => { |
246 |
| - relation.register_predicates([if self.next_trait_solver() { |
247 |
| - ty::PredicateKind::AliasRelate( |
248 |
| - a.into(), |
249 |
| - b.into(), |
250 |
| - ty::AliasRelationDirection::Equate, |
251 |
| - ) |
252 |
| - } else { |
253 |
| - ty::PredicateKind::ConstEquate(a, b) |
254 |
| - }]); |
255 |
| - |
256 |
| - Ok(b) |
257 |
| - } |
258 |
| - StructurallyRelateAliases::Yes => { |
259 |
| - relate::structurally_relate_consts(relation, a, b) |
260 |
| - } |
261 |
| - } |
262 |
| - } |
263 |
| - _ => relate::structurally_relate_consts(relation, a, b), |
264 |
| - } |
265 |
| - } |
266 |
| - |
267 |
| - #[inline(always)] |
268 |
| - fn unify_integral_variable(&self, vid: ty::IntVid, val: ty::IntVarValue) { |
269 |
| - self.inner.borrow_mut().int_unification_table().union_value(vid, val); |
270 |
| - } |
271 |
| - |
272 |
| - #[inline(always)] |
273 |
| - fn unify_float_variable(&self, vid: ty::FloatVid, val: ty::FloatVarValue) { |
274 |
| - self.inner.borrow_mut().float_unification_table().union_value(vid, val); |
275 |
| - } |
276 |
| - |
277 |
| - fn unify_effect_variable(&self, vid: ty::EffectVid, val: ty::Const<'tcx>) -> ty::Const<'tcx> { |
278 |
| - self.inner |
279 |
| - .borrow_mut() |
280 |
| - .effect_unification_table() |
281 |
| - .union_value(vid, EffectVarValue::Known(val)); |
282 |
| - val |
283 |
| - } |
284 |
| -} |
285 |
| - |
286 | 66 | impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
|
287 | 67 | pub fn tcx(&self) -> TyCtxt<'tcx> {
|
288 | 68 | self.infcx.tcx
|
|
0 commit comments