diff options
author | Marcus Klaas de Vries <[email protected]> | 2019-01-14 18:30:21 +0000 |
---|---|---|
committer | Marcus Klaas de Vries <[email protected]> | 2019-01-14 18:30:21 +0000 |
commit | a9a6a50c759302e8a8d59bf6c53c72ec804324b3 (patch) | |
tree | ecd22d01bca8bfb2419732621140c3271277973d /crates/ra_hir/src/ty.rs | |
parent | 606d66a714bb8fe07f35a6af83d04ab576b9a0e1 (diff) |
Fixup tests
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index de5ec5b46..b6577ee5e 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -111,7 +111,7 @@ impl UnifyValue for TypeVarValue { | |||
111 | /// values for general types, and for integer and float variables. The latter | 111 | /// values for general types, and for integer and float variables. The latter |
112 | /// two are used for inference of literal values (e.g. `100` could be one of | 112 | /// two are used for inference of literal values (e.g. `100` could be one of |
113 | /// several integer types). | 113 | /// several integer types). |
114 | #[derive(Clone, PartialEq, Eq, Hash, Debug)] | 114 | #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] |
115 | pub enum InferTy { | 115 | pub enum InferTy { |
116 | TypeVar(TypeVarId), | 116 | TypeVar(TypeVarId), |
117 | IntVar(TypeVarId), | 117 | IntVar(TypeVarId), |
@@ -119,6 +119,12 @@ pub enum InferTy { | |||
119 | } | 119 | } |
120 | 120 | ||
121 | impl InferTy { | 121 | impl InferTy { |
122 | fn to_inner(self) -> TypeVarId { | ||
123 | match self { | ||
124 | InferTy::TypeVar(ty) | InferTy::IntVar(ty) | InferTy::FloatVar(ty) => ty, | ||
125 | } | ||
126 | } | ||
127 | |||
122 | fn fallback_value(self) -> Ty { | 128 | fn fallback_value(self) -> Ty { |
123 | match self { | 129 | match self { |
124 | InferTy::TypeVar(..) => Ty::Unknown, | 130 | InferTy::TypeVar(..) => Ty::Unknown, |
@@ -326,18 +332,19 @@ impl Ty { | |||
326 | path: &Path, | 332 | path: &Path, |
327 | ) -> Cancelable<Self> { | 333 | ) -> Cancelable<Self> { |
328 | if let Some(name) = path.as_ident() { | 334 | if let Some(name) = path.as_ident() { |
329 | if let Some(KnownName::Bool) = name.as_known_name() { | 335 | if let Some(int_ty) = primitive::UncertainIntTy::from_name(name) { |
330 | return Ok(Ty::Bool); | ||
331 | } else if let Some(KnownName::Char) = name.as_known_name() { | ||
332 | return Ok(Ty::Char); | ||
333 | } else if let Some(KnownName::Str) = name.as_known_name() { | ||
334 | return Ok(Ty::Str); | ||
335 | } else if let Some(int_ty) = primitive::UncertainIntTy::from_name(name) { | ||
336 | return Ok(Ty::Int(int_ty)); | 336 | return Ok(Ty::Int(int_ty)); |
337 | } else if let Some(float_ty) = primitive::UncertainFloatTy::from_name(name) { | 337 | } else if let Some(float_ty) = primitive::UncertainFloatTy::from_name(name) { |
338 | return Ok(Ty::Float(float_ty)); | 338 | return Ok(Ty::Float(float_ty)); |
339 | } else if name.as_known_name() == Some(KnownName::SelfType) { | 339 | } else if name.as_known_name() == Some(KnownName::SelfType) { |
340 | return Ty::from_hir_opt(db, module, None, impl_block.map(|i| i.target_type())); | 340 | return Ty::from_hir_opt(db, module, None, impl_block.map(|i| i.target_type())); |
341 | } else if let Some(known) = name.as_known_name() { | ||
342 | match known { | ||
343 | KnownName::Bool => return Ok(Ty::Bool), | ||
344 | KnownName::Char => return Ok(Ty::Char), | ||
345 | KnownName::Str => return Ok(Ty::Str), | ||
346 | _ => {} | ||
347 | } | ||
341 | } | 348 | } |
342 | } | 349 | } |
343 | 350 | ||
@@ -793,10 +800,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
793 | /// known type. | 800 | /// known type. |
794 | fn resolve_ty_as_possible(&mut self, ty: Ty) -> Ty { | 801 | fn resolve_ty_as_possible(&mut self, ty: Ty) -> Ty { |
795 | ty.fold(&mut |ty| match ty { | 802 | ty.fold(&mut |ty| match ty { |
796 | Ty::Infer(InferTy::TypeVar(tv)) | 803 | Ty::Infer(tv) => { |
797 | | Ty::Infer(InferTy::IntVar(tv)) | 804 | let inner = tv.to_inner(); |
798 | | Ty::Infer(InferTy::FloatVar(tv)) => { | 805 | if let Some(known_ty) = self.var_unification_table.probe_value(inner).known() { |
799 | if let Some(known_ty) = self.var_unification_table.probe_value(tv).known() { | ||
800 | // known_ty may contain other variables that are known by now | 806 | // known_ty may contain other variables that are known by now |
801 | self.resolve_ty_as_possible(known_ty.clone()) | 807 | self.resolve_ty_as_possible(known_ty.clone()) |
802 | } else { | 808 | } else { |
@@ -811,8 +817,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
811 | /// otherwise, return ty. | 817 | /// otherwise, return ty. |
812 | fn resolve_ty_shallow<'b>(&mut self, ty: &'b Ty) -> Cow<'b, Ty> { | 818 | fn resolve_ty_shallow<'b>(&mut self, ty: &'b Ty) -> Cow<'b, Ty> { |
813 | match ty { | 819 | match ty { |
814 | Ty::Infer(InferTy::TypeVar(tv)) => { | 820 | Ty::Infer(tv) => { |
815 | match self.var_unification_table.probe_value(*tv).known() { | 821 | let inner = tv.to_inner(); |
822 | match self.var_unification_table.probe_value(inner).known() { | ||
816 | Some(known_ty) => { | 823 | Some(known_ty) => { |
817 | // The known_ty can't be a type var itself | 824 | // The known_ty can't be a type var itself |
818 | Cow::Owned(known_ty.clone()) | 825 | Cow::Owned(known_ty.clone()) |
@@ -828,16 +835,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
828 | /// replaced by Ty::Unknown. | 835 | /// replaced by Ty::Unknown. |
829 | fn resolve_ty_completely(&mut self, ty: Ty) -> Ty { | 836 | fn resolve_ty_completely(&mut self, ty: Ty) -> Ty { |
830 | ty.fold(&mut |ty| match ty { | 837 | ty.fold(&mut |ty| match ty { |
831 | Ty::Infer(i) => { | 838 | Ty::Infer(tv) => { |
832 | let tv = match i { | 839 | let inner = tv.to_inner(); |
833 | InferTy::TypeVar(tv) | InferTy::IntVar(tv) | InferTy::FloatVar(tv) => tv, | 840 | if let Some(known_ty) = self.var_unification_table.probe_value(inner).known() { |
834 | }; | ||
835 | |||
836 | if let Some(known_ty) = self.var_unification_table.probe_value(tv).known() { | ||
837 | // known_ty may contain other variables that are known by now | 841 | // known_ty may contain other variables that are known by now |
838 | self.resolve_ty_completely(known_ty.clone()) | 842 | self.resolve_ty_completely(known_ty.clone()) |
839 | } else { | 843 | } else { |
840 | i.fallback_value() | 844 | tv.fallback_value() |
841 | } | 845 | } |
842 | } | 846 | } |
843 | _ => ty, | 847 | _ => ty, |