aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-05-21 17:20:56 +0100
committerFlorian Diebold <[email protected]>2021-05-21 17:23:03 +0100
commit67f1a08fd8eff669a997950cac6c538dd96718b3 (patch)
tree2d19db9e808ae1b92c65675eade448f893ff4d7d /crates
parente9d1550001f79390284cf7f0e958981f387a0c58 (diff)
Some remaining cleanups
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/infer.rs4
-rw-r--r--crates/hir_ty/src/infer/coerce.rs20
-rw-r--r--crates/hir_ty/src/infer/unify.rs7
3 files changed, 13 insertions, 18 deletions
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs
index a137c0f92..f1cebbdb9 100644
--- a/crates/hir_ty/src/infer.rs
+++ b/crates/hir_ty/src/infer.rs
@@ -373,10 +373,6 @@ impl<'a> InferenceContext<'a> {
373 self.table.unify(ty1, ty2) 373 self.table.unify(ty1, ty2)
374 } 374 }
375 375
376 fn unify_inner(&mut self, ty1: &Ty, ty2: &Ty) -> InferResult {
377 self.table.unify_inner(ty1, ty2)
378 }
379
380 fn resolve_ty_shallow(&mut self, ty: &Ty) -> Ty { 376 fn resolve_ty_shallow(&mut self, ty: &Ty) -> Ty {
381 self.resolve_obligations_as_possible(); 377 self.resolve_obligations_as_possible();
382 self.table.resolve_ty_shallow(ty) 378 self.table.resolve_ty_shallow(ty)
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs
index 40b4db926..765a02b1c 100644
--- a/crates/hir_ty/src/infer/coerce.rs
+++ b/crates/hir_ty/src/infer/coerce.rs
@@ -146,7 +146,7 @@ impl<'a> InferenceContext<'a> {
146 } 146 }
147 _ => { 147 _ => {
148 // Otherwise, just use unification rules. 148 // Otherwise, just use unification rules.
149 self.unify_inner(&from_ty, to_ty) 149 self.table.try_unify(&from_ty, to_ty)
150 } 150 }
151 } 151 }
152 } 152 }
@@ -155,7 +155,7 @@ impl<'a> InferenceContext<'a> {
155 let (_is_ref, from_mt, from_inner) = match from_ty.kind(&Interner) { 155 let (_is_ref, from_mt, from_inner) = match from_ty.kind(&Interner) {
156 TyKind::Ref(mt, _, ty) => (true, mt, ty), 156 TyKind::Ref(mt, _, ty) => (true, mt, ty),
157 TyKind::Raw(mt, ty) => (false, mt, ty), 157 TyKind::Raw(mt, ty) => (false, mt, ty),
158 _ => return self.unify_inner(&from_ty, to_ty), 158 _ => return self.table.try_unify(&from_ty, to_ty),
159 }; 159 };
160 160
161 coerce_mutabilities(*from_mt, to_mt)?; 161 coerce_mutabilities(*from_mt, to_mt)?;
@@ -163,7 +163,7 @@ impl<'a> InferenceContext<'a> {
163 // Check that the types which they point at are compatible. 163 // Check that the types which they point at are compatible.
164 let from_raw = TyKind::Raw(to_mt, from_inner.clone()).intern(&Interner); 164 let from_raw = TyKind::Raw(to_mt, from_inner.clone()).intern(&Interner);
165 // FIXME: behavior differs based on is_ref once we're computing adjustments 165 // FIXME: behavior differs based on is_ref once we're computing adjustments
166 self.unify_inner(&from_raw, to_ty) 166 self.table.try_unify(&from_raw, to_ty)
167 } 167 }
168 168
169 /// Reborrows `&mut A` to `&mut B` and `&(mut) A` to `&B`. 169 /// Reborrows `&mut A` to `&mut B` and `&(mut) A` to `&B`.
@@ -174,7 +174,7 @@ impl<'a> InferenceContext<'a> {
174 TyKind::Ref(mt, _, _) => { 174 TyKind::Ref(mt, _, _) => {
175 coerce_mutabilities(*mt, to_mt)?; 175 coerce_mutabilities(*mt, to_mt)?;
176 } 176 }
177 _ => return self.unify_inner(&from_ty, to_ty), 177 _ => return self.table.try_unify(&from_ty, to_ty),
178 }; 178 };
179 179
180 // NOTE: this code is mostly copied and adapted from rustc, and 180 // NOTE: this code is mostly copied and adapted from rustc, and
@@ -228,7 +228,7 @@ impl<'a> InferenceContext<'a> {
228 // from `&mut T` to `&U`. 228 // from `&mut T` to `&U`.
229 let lt = static_lifetime(); // FIXME: handle lifetimes correctly, see rustc 229 let lt = static_lifetime(); // FIXME: handle lifetimes correctly, see rustc
230 let derefd_from_ty = TyKind::Ref(to_mt, lt, referent_ty).intern(&Interner); 230 let derefd_from_ty = TyKind::Ref(to_mt, lt, referent_ty).intern(&Interner);
231 match self.unify_inner(&derefd_from_ty, to_ty) { 231 match self.table.try_unify(&derefd_from_ty, to_ty) {
232 Ok(result) => { 232 Ok(result) => {
233 found = Some(result); 233 found = Some(result);
234 break; 234 break;
@@ -274,7 +274,7 @@ impl<'a> InferenceContext<'a> {
274 274
275 Ok(ok) 275 Ok(ok)
276 } 276 }
277 _ => self.unify_inner(&from_ty, to_ty), 277 _ => self.table.try_unify(&from_ty, to_ty),
278 } 278 }
279 } 279 }
280 280
@@ -299,10 +299,10 @@ impl<'a> InferenceContext<'a> {
299 { 299 {
300 let from_unsafe = 300 let from_unsafe =
301 TyKind::Function(safe_to_unsafe_fn_ty(from_fn_ptr.clone())).intern(&Interner); 301 TyKind::Function(safe_to_unsafe_fn_ty(from_fn_ptr.clone())).intern(&Interner);
302 return self.unify_inner(&from_unsafe, to_ty); 302 return self.table.try_unify(&from_unsafe, to_ty);
303 } 303 }
304 } 304 }
305 self.unify_inner(&from_ty, to_ty) 305 self.table.try_unify(&from_ty, to_ty)
306 } 306 }
307 307
308 /// Attempts to coerce from the type of a non-capturing closure into a 308 /// Attempts to coerce from the type of a non-capturing closure into a
@@ -323,9 +323,9 @@ impl<'a> InferenceContext<'a> {
323 // `unsafe fn(arg0,arg1,...) -> _` 323 // `unsafe fn(arg0,arg1,...) -> _`
324 let safety = fn_ty.sig.safety; 324 let safety = fn_ty.sig.safety;
325 let pointer_ty = coerce_closure_fn_ty(from_substs, safety); 325 let pointer_ty = coerce_closure_fn_ty(from_substs, safety);
326 self.unify_inner(&pointer_ty, to_ty) 326 self.table.try_unify(&pointer_ty, to_ty)
327 } 327 }
328 _ => self.unify_inner(&from_ty, to_ty), 328 _ => self.table.try_unify(&from_ty, to_ty),
329 } 329 }
330 } 330 }
331 331
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs
index 8674c1b0c..4987795e0 100644
--- a/crates/hir_ty/src/infer/unify.rs
+++ b/crates/hir_ty/src/infer/unify.rs
@@ -70,7 +70,7 @@ impl<T: HasInterner<Interner = Interner>> Canonicalized<T> {
70 let ty = ctx.normalize_associated_types_in(new_vars.apply(ty.clone(), &Interner)); 70 let ty = ctx.normalize_associated_types_in(new_vars.apply(ty.clone(), &Interner));
71 ctx.unify(var.assert_ty_ref(&Interner), &ty); 71 ctx.unify(var.assert_ty_ref(&Interner), &ty);
72 } else { 72 } else {
73 let _ = ctx.unify_inner(&var, &new_vars.apply(v.clone(), &Interner)); 73 let _ = ctx.try_unify(&var, &new_vars.apply(v.clone(), &Interner));
74 } 74 }
75 } 75 }
76 } 76 }
@@ -300,9 +300,8 @@ impl<'a> InferenceTable<'a> {
300 } 300 }
301 301
302 /// Unify two types and register new trait goals that arise from that. 302 /// Unify two types and register new trait goals that arise from that.
303 // TODO give these two functions better names
304 pub(crate) fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool { 303 pub(crate) fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool {
305 let result = if let Ok(r) = self.unify_inner(ty1, ty2) { 304 let result = if let Ok(r) = self.try_unify(ty1, ty2) {
306 r 305 r
307 } else { 306 } else {
308 return false; 307 return false;
@@ -313,7 +312,7 @@ impl<'a> InferenceTable<'a> {
313 312
314 /// Unify two types and return new trait goals arising from it, so the 313 /// Unify two types and return new trait goals arising from it, so the
315 /// caller needs to deal with them. 314 /// caller needs to deal with them.
316 pub(crate) fn unify_inner<T: Zip<Interner>>(&mut self, t1: &T, t2: &T) -> InferResult { 315 pub(crate) fn try_unify<T: Zip<Interner>>(&mut self, t1: &T, t2: &T) -> InferResult {
317 match self.var_unification_table.relate( 316 match self.var_unification_table.relate(
318 &Interner, 317 &Interner,
319 &self.db, 318 &self.db,