From d09e5a3d9e57c631860ef195fad29f002569ae4d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 12 Nov 2019 15:09:25 +0300 Subject: Move definition of exprs to hir_def --- crates/ra_hir/src/ty/infer/expr.rs | 4 ++-- crates/ra_hir/src/ty/lower.rs | 38 +++++++++++++++++++++++++++++++++----- crates/ra_hir/src/ty/primitive.rs | 26 -------------------------- 3 files changed, 35 insertions(+), 33 deletions(-) (limited to 'crates/ra_hir/src/ty') 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> { Ty::apply_one(TypeCtor::Ref(Mutability::Shared), slice_type) } Literal::Char(..) => Ty::simple(TypeCtor::Char), - Literal::Int(_v, ty) => Ty::simple(TypeCtor::Int(*ty)), - Literal::Float(_v, ty) => Ty::simple(TypeCtor::Float(*ty)), + Literal::Int(_v, ty) => Ty::simple(TypeCtor::Int((*ty).into())), + Literal::Float(_v, ty) => Ty::simple(TypeCtor::Float((*ty).into())), }, }; // 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::{ generics::{GenericDef, WherePredicate}, resolve::{Resolver, TypeNs}, ty::{ - primitive::{FloatTy, IntTy}, + primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy}, Adt, }, util::make_mut_slice, @@ -657,13 +657,41 @@ fn type_for_builtin(def: BuiltinType) -> Ty { BuiltinType::Char => TypeCtor::Char, BuiltinType::Bool => TypeCtor::Bool, BuiltinType::Str => TypeCtor::Str, - BuiltinType::Int(BuiltinInt { signedness, bitness }) => { - TypeCtor::Int(IntTy { signedness, bitness }.into()) - } - BuiltinType::Float(BuiltinFloat { bitness }) => TypeCtor::Float(FloatTy { bitness }.into()), + BuiltinType::Int(t) => TypeCtor::Int(IntTy::from(t).into()), + BuiltinType::Float(t) => TypeCtor::Float(FloatTy::from(t).into()), }) } +impl From for IntTy { + fn from(t: BuiltinInt) -> Self { + IntTy { signedness: t.signedness, bitness: t.bitness } + } +} + +impl From for FloatTy { + fn from(t: BuiltinFloat) -> Self { + FloatTy { bitness: t.bitness } + } +} + +impl From> for UncertainIntTy { + fn from(t: Option) -> Self { + match t { + None => UncertainIntTy::Unknown, + Some(t) => UncertainIntTy::Known(t.into()), + } + } +} + +impl From> for UncertainFloatTy { + fn from(t: Option) -> Self { + match t { + None => UncertainFloatTy::Unknown, + Some(t) => UncertainFloatTy::Known(t.into()), + } + } +} + fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> FnSig { let struct_data = db.struct_data(def.id.into()); 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 { (Signedness::Unsigned, IntBitness::X128) => "u128", } } - - pub(crate) fn from_suffix(suffix: &str) -> Option { - match suffix { - "isize" => Some(IntTy::isize()), - "i8" => Some(IntTy::i8()), - "i16" => Some(IntTy::i16()), - "i32" => Some(IntTy::i32()), - "i64" => Some(IntTy::i64()), - "i128" => Some(IntTy::i128()), - "usize" => Some(IntTy::usize()), - "u8" => Some(IntTy::u8()), - "u16" => Some(IntTy::u16()), - "u32" => Some(IntTy::u32()), - "u64" => Some(IntTy::u64()), - "u128" => Some(IntTy::u128()), - _ => None, - } - } } #[derive(Copy, Clone, PartialEq, Eq, Hash)] @@ -181,12 +163,4 @@ impl FloatTy { FloatBitness::X64 => "f64", } } - - pub(crate) fn from_suffix(suffix: &str) -> Option { - match suffix { - "f32" => Some(FloatTy::f32()), - "f64" => Some(FloatTy::f64()), - _ => None, - } - } } -- cgit v1.2.3