diff options
author | Florian Diebold <[email protected]> | 2021-05-16 14:56:27 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-05-21 16:48:34 +0100 |
commit | a78f0076abbbf61f7b68ce5c323639037c8a72de (patch) | |
tree | f2a5f46b348c6b32e6860523a4ed06547fbf4ea2 /crates | |
parent | 1250ddc5cf58ff0a6bbf7c07e5bd9f7cc7db5a09 (diff) |
Make resolve_ty_shallow return Ty
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_ty/src/infer.rs | 4 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/coerce.rs | 8 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/unify.rs | 9 |
3 files changed, 7 insertions, 14 deletions
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index 97e7c5f8c..8cfc84b86 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs | |||
@@ -13,8 +13,6 @@ | |||
13 | //! to certain types. To record this, we use the union-find implementation from | 13 | //! to certain types. To record this, we use the union-find implementation from |
14 | //! the `ena` crate, which is extracted from rustc. | 14 | //! the `ena` crate, which is extracted from rustc. |
15 | 15 | ||
16 | use std::borrow::Cow; | ||
17 | |||
18 | use std::ops::Index; | 16 | use std::ops::Index; |
19 | use std::sync::Arc; | 17 | use std::sync::Arc; |
20 | 18 | ||
@@ -384,7 +382,7 @@ impl<'a> InferenceContext<'a> { | |||
384 | self.table.resolve_ty_as_possible(ty) | 382 | self.table.resolve_ty_as_possible(ty) |
385 | } | 383 | } |
386 | 384 | ||
387 | fn resolve_ty_shallow<'b>(&mut self, ty: &'b Ty) -> Cow<'b, Ty> { | 385 | fn resolve_ty_shallow(&mut self, ty: &Ty) -> Ty { |
388 | self.table.resolve_ty_shallow(ty) | 386 | self.table.resolve_ty_shallow(ty) |
389 | } | 387 | } |
390 | 388 | ||
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index 911343cb9..c85c088f7 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs | |||
@@ -23,7 +23,7 @@ impl<'a> InferenceContext<'a> { | |||
23 | if to_ty.is_unknown() { | 23 | if to_ty.is_unknown() { |
24 | return true; | 24 | return true; |
25 | } | 25 | } |
26 | let from_ty = self.resolve_ty_shallow(from_ty).into_owned(); | 26 | let from_ty = self.resolve_ty_shallow(from_ty); |
27 | let to_ty = self.resolve_ty_shallow(to_ty); | 27 | let to_ty = self.resolve_ty_shallow(to_ty); |
28 | match self.coerce_inner(from_ty, &to_ty) { | 28 | match self.coerce_inner(from_ty, &to_ty) { |
29 | Ok(_result) => { | 29 | Ok(_result) => { |
@@ -46,9 +46,7 @@ impl<'a> InferenceContext<'a> { | |||
46 | /// least upper bound. | 46 | /// least upper bound. |
47 | pub(super) fn coerce_merge_branch(&mut self, ty1: &Ty, ty2: &Ty) -> Ty { | 47 | pub(super) fn coerce_merge_branch(&mut self, ty1: &Ty, ty2: &Ty) -> Ty { |
48 | let ty1 = self.resolve_ty_shallow(ty1); | 48 | let ty1 = self.resolve_ty_shallow(ty1); |
49 | let ty1 = ty1.as_ref(); | ||
50 | let ty2 = self.resolve_ty_shallow(ty2); | 49 | let ty2 = self.resolve_ty_shallow(ty2); |
51 | let ty2 = ty2.as_ref(); | ||
52 | // Special case: two function types. Try to coerce both to | 50 | // Special case: two function types. Try to coerce both to |
53 | // pointers to have a chance at getting a match. See | 51 | // pointers to have a chance at getting a match. See |
54 | // https://github.com/rust-lang/rust/blob/7b805396bf46dce972692a6846ce2ad8481c5f85/src/librustc_typeck/check/coercion.rs#L877-L916 | 52 | // https://github.com/rust-lang/rust/blob/7b805396bf46dce972692a6846ce2ad8481c5f85/src/librustc_typeck/check/coercion.rs#L877-L916 |
@@ -80,9 +78,9 @@ impl<'a> InferenceContext<'a> { | |||
80 | // type is a type variable and the new one is `!`, trying it the other | 78 | // type is a type variable and the new one is `!`, trying it the other |
81 | // way around first would mean we make the type variable `!`, instead of | 79 | // way around first would mean we make the type variable `!`, instead of |
82 | // just marking it as possibly diverging. | 80 | // just marking it as possibly diverging. |
83 | if self.coerce(ty2, ty1) { | 81 | if self.coerce(&ty2, &ty1) { |
84 | ty1.clone() | 82 | ty1.clone() |
85 | } else if self.coerce(ty1, ty2) { | 83 | } else if self.coerce(&ty1, &ty2) { |
86 | ty2.clone() | 84 | ty2.clone() |
87 | } else { | 85 | } else { |
88 | // TODO record a type mismatch | 86 | // TODO record a type mismatch |
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 75e04e8b5..278127c69 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! Unification and canonicalization logic. | 1 | //! Unification and canonicalization logic. |
2 | 2 | ||
3 | use std::{borrow::Cow, fmt, mem, sync::Arc}; | 3 | use std::{fmt, mem, sync::Arc}; |
4 | 4 | ||
5 | use chalk_ir::{ | 5 | use chalk_ir::{ |
6 | cast::Cast, fold::Fold, interner::HasInterner, zip::Zip, FloatTy, IntTy, TyVariableKind, | 6 | cast::Cast, fold::Fold, interner::HasInterner, zip::Zip, FloatTy, IntTy, TyVariableKind, |
@@ -340,11 +340,8 @@ impl<'a> InferenceTable<'a> { | |||
340 | 340 | ||
341 | /// If `ty` is a type variable with known type, returns that type; | 341 | /// If `ty` is a type variable with known type, returns that type; |
342 | /// otherwise, return ty. | 342 | /// otherwise, return ty. |
343 | // FIXME this could probably just return Ty | 343 | pub(crate) fn resolve_ty_shallow(&mut self, ty: &Ty) -> Ty { |
344 | pub(crate) fn resolve_ty_shallow<'b>(&mut self, ty: &'b Ty) -> Cow<'b, Ty> { | 344 | self.var_unification_table.normalize_ty_shallow(&Interner, ty).unwrap_or_else(|| ty.clone()) |
345 | self.var_unification_table | ||
346 | .normalize_ty_shallow(&Interner, ty) | ||
347 | .map_or(Cow::Borrowed(ty), Cow::Owned) | ||
348 | } | 345 | } |
349 | 346 | ||
350 | /// Resolves the type as far as currently possible, replacing type variables | 347 | /// Resolves the type as far as currently possible, replacing type variables |