diff options
author | Aleksey Kladov <[email protected]> | 2019-11-12 12:09:25 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-12 12:09:25 +0000 |
commit | d09e5a3d9e57c631860ef195fad29f002569ae4d (patch) | |
tree | d4dbccf4df1609f86fcc1cb52fc366f3af3a25f6 /crates/ra_hir/src/ty | |
parent | f5e1b0f97c9e46b5186f99d744f4587b2aee397e (diff) |
Move definition of exprs to hir_def
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/infer/expr.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 38 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/primitive.rs | 26 |
3 files changed, 35 insertions, 33 deletions
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs index 4af1d65ee..6d9792391 100644 --- a/crates/ra_hir/src/ty/infer/expr.rs +++ b/crates/ra_hir/src/ty/infer/expr.rs | |||
@@ -452,8 +452,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
452 | Ty::apply_one(TypeCtor::Ref(Mutability::Shared), slice_type) | 452 | Ty::apply_one(TypeCtor::Ref(Mutability::Shared), slice_type) |
453 | } | 453 | } |
454 | Literal::Char(..) => Ty::simple(TypeCtor::Char), | 454 | Literal::Char(..) => Ty::simple(TypeCtor::Char), |
455 | Literal::Int(_v, ty) => Ty::simple(TypeCtor::Int(*ty)), | 455 | Literal::Int(_v, ty) => Ty::simple(TypeCtor::Int((*ty).into())), |
456 | Literal::Float(_v, ty) => Ty::simple(TypeCtor::Float(*ty)), | 456 | Literal::Float(_v, ty) => Ty::simple(TypeCtor::Float((*ty).into())), |
457 | }, | 457 | }, |
458 | }; | 458 | }; |
459 | // use a new type variable if we got Ty::Unknown here | 459 | // use a new type variable if we got Ty::Unknown here |
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 52d24e24d..1832fcf50 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs | |||
@@ -25,7 +25,7 @@ use crate::{ | |||
25 | generics::{GenericDef, WherePredicate}, | 25 | generics::{GenericDef, WherePredicate}, |
26 | resolve::{Resolver, TypeNs}, | 26 | resolve::{Resolver, TypeNs}, |
27 | ty::{ | 27 | ty::{ |
28 | primitive::{FloatTy, IntTy}, | 28 | primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy}, |
29 | Adt, | 29 | Adt, |
30 | }, | 30 | }, |
31 | util::make_mut_slice, | 31 | util::make_mut_slice, |
@@ -657,13 +657,41 @@ fn type_for_builtin(def: BuiltinType) -> Ty { | |||
657 | BuiltinType::Char => TypeCtor::Char, | 657 | BuiltinType::Char => TypeCtor::Char, |
658 | BuiltinType::Bool => TypeCtor::Bool, | 658 | BuiltinType::Bool => TypeCtor::Bool, |
659 | BuiltinType::Str => TypeCtor::Str, | 659 | BuiltinType::Str => TypeCtor::Str, |
660 | BuiltinType::Int(BuiltinInt { signedness, bitness }) => { | 660 | BuiltinType::Int(t) => TypeCtor::Int(IntTy::from(t).into()), |
661 | TypeCtor::Int(IntTy { signedness, bitness }.into()) | 661 | BuiltinType::Float(t) => TypeCtor::Float(FloatTy::from(t).into()), |
662 | } | ||
663 | BuiltinType::Float(BuiltinFloat { bitness }) => TypeCtor::Float(FloatTy { bitness }.into()), | ||
664 | }) | 662 | }) |
665 | } | 663 | } |
666 | 664 | ||
665 | impl From<BuiltinInt> for IntTy { | ||
666 | fn from(t: BuiltinInt) -> Self { | ||
667 | IntTy { signedness: t.signedness, bitness: t.bitness } | ||
668 | } | ||
669 | } | ||
670 | |||
671 | impl From<BuiltinFloat> for FloatTy { | ||
672 | fn from(t: BuiltinFloat) -> Self { | ||
673 | FloatTy { bitness: t.bitness } | ||
674 | } | ||
675 | } | ||
676 | |||
677 | impl From<Option<BuiltinInt>> for UncertainIntTy { | ||
678 | fn from(t: Option<BuiltinInt>) -> Self { | ||
679 | match t { | ||
680 | None => UncertainIntTy::Unknown, | ||
681 | Some(t) => UncertainIntTy::Known(t.into()), | ||
682 | } | ||
683 | } | ||
684 | } | ||
685 | |||
686 | impl From<Option<BuiltinFloat>> for UncertainFloatTy { | ||
687 | fn from(t: Option<BuiltinFloat>) -> Self { | ||
688 | match t { | ||
689 | None => UncertainFloatTy::Unknown, | ||
690 | Some(t) => UncertainFloatTy::Known(t.into()), | ||
691 | } | ||
692 | } | ||
693 | } | ||
694 | |||
667 | fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> FnSig { | 695 | fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> FnSig { |
668 | let struct_data = db.struct_data(def.id.into()); | 696 | let struct_data = db.struct_data(def.id.into()); |
669 | let fields = match struct_data.variant_data.fields() { | 697 | let fields = match struct_data.variant_data.fields() { |
diff --git a/crates/ra_hir/src/ty/primitive.rs b/crates/ra_hir/src/ty/primitive.rs index 1749752f1..7362de4c3 100644 --- a/crates/ra_hir/src/ty/primitive.rs +++ b/crates/ra_hir/src/ty/primitive.rs | |||
@@ -129,24 +129,6 @@ impl IntTy { | |||
129 | (Signedness::Unsigned, IntBitness::X128) => "u128", | 129 | (Signedness::Unsigned, IntBitness::X128) => "u128", |
130 | } | 130 | } |
131 | } | 131 | } |
132 | |||
133 | pub(crate) fn from_suffix(suffix: &str) -> Option<IntTy> { | ||
134 | match suffix { | ||
135 | "isize" => Some(IntTy::isize()), | ||
136 | "i8" => Some(IntTy::i8()), | ||
137 | "i16" => Some(IntTy::i16()), | ||
138 | "i32" => Some(IntTy::i32()), | ||
139 | "i64" => Some(IntTy::i64()), | ||
140 | "i128" => Some(IntTy::i128()), | ||
141 | "usize" => Some(IntTy::usize()), | ||
142 | "u8" => Some(IntTy::u8()), | ||
143 | "u16" => Some(IntTy::u16()), | ||
144 | "u32" => Some(IntTy::u32()), | ||
145 | "u64" => Some(IntTy::u64()), | ||
146 | "u128" => Some(IntTy::u128()), | ||
147 | _ => None, | ||
148 | } | ||
149 | } | ||
150 | } | 132 | } |
151 | 133 | ||
152 | #[derive(Copy, Clone, PartialEq, Eq, Hash)] | 134 | #[derive(Copy, Clone, PartialEq, Eq, Hash)] |
@@ -181,12 +163,4 @@ impl FloatTy { | |||
181 | FloatBitness::X64 => "f64", | 163 | FloatBitness::X64 => "f64", |
182 | } | 164 | } |
183 | } | 165 | } |
184 | |||
185 | pub(crate) fn from_suffix(suffix: &str) -> Option<FloatTy> { | ||
186 | match suffix { | ||
187 | "f32" => Some(FloatTy::f32()), | ||
188 | "f64" => Some(FloatTy::f64()), | ||
189 | _ => None, | ||
190 | } | ||
191 | } | ||
192 | } | 166 | } |