From 7c2dd85a32e320fd412a720ea5b847c66bf246ae Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 28 Feb 2021 10:58:34 +0100 Subject: Use chalk_ir::Scalar directly --- crates/hir_ty/src/primitive.rs | 147 ++++++++++++----------------------------- 1 file changed, 41 insertions(+), 106 deletions(-) (limited to 'crates/hir_ty/src/primitive.rs') diff --git a/crates/hir_ty/src/primitive.rs b/crates/hir_ty/src/primitive.rs index e727c9581..2449addfb 100644 --- a/crates/hir_ty/src/primitive.rs +++ b/crates/hir_ty/src/primitive.rs @@ -3,128 +3,63 @@ //! * during type inference, they can be uncertain (ie, `let x = 92;`) //! * they don't belong to any particular crate. -use std::fmt; - +pub use chalk_ir::{FloatTy, IntTy, UintTy}; pub use hir_def::builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint}; -/// Different signed int types. -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum IntTy { - Isize, - I8, - I16, - I32, - I64, - I128, -} - -/// Different unsigned int types. -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum UintTy { - Usize, - U8, - U16, - U32, - U64, - U128, -} - -impl fmt::Display for IntTy { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.ty_to_string()) - } -} - -impl IntTy { - pub fn ty_to_string(self) -> &'static str { - match self { - IntTy::Isize => "isize", - IntTy::I8 => "i8", - IntTy::I16 => "i16", - IntTy::I32 => "i32", - IntTy::I64 => "i64", - IntTy::I128 => "i128", - } - } -} - -impl fmt::Display for UintTy { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.ty_to_string()) - } -} - -impl UintTy { - pub fn ty_to_string(self) -> &'static str { - match self { - UintTy::Usize => "usize", - UintTy::U8 => "u8", - UintTy::U16 => "u16", - UintTy::U32 => "u32", - UintTy::U64 => "u64", - UintTy::U128 => "u128", - } - } -} - -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum FloatTy { - F32, - F64, -} - -impl fmt::Debug for FloatTy { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Display::fmt(self, f) +pub fn int_ty_to_string(ty: IntTy) -> &'static str { + match ty { + IntTy::Isize => "isize", + IntTy::I8 => "i8", + IntTy::I16 => "i16", + IntTy::I32 => "i32", + IntTy::I64 => "i64", + IntTy::I128 => "i128", } } -impl fmt::Display for FloatTy { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.ty_to_string()) +pub fn uint_ty_to_string(ty: UintTy) -> &'static str { + match ty { + UintTy::Usize => "usize", + UintTy::U8 => "u8", + UintTy::U16 => "u16", + UintTy::U32 => "u32", + UintTy::U64 => "u64", + UintTy::U128 => "u128", } } -impl FloatTy { - pub fn ty_to_string(self) -> &'static str { - match self { - FloatTy::F32 => "f32", - FloatTy::F64 => "f64", - } +pub fn float_ty_to_string(ty: FloatTy) -> &'static str { + match ty { + FloatTy::F32 => "f32", + FloatTy::F64 => "f64", } } -impl From for IntTy { - fn from(t: BuiltinInt) -> Self { - match t { - BuiltinInt::Isize => Self::Isize, - BuiltinInt::I8 => Self::I8, - BuiltinInt::I16 => Self::I16, - BuiltinInt::I32 => Self::I32, - BuiltinInt::I64 => Self::I64, - BuiltinInt::I128 => Self::I128, - } +pub(super) fn int_ty_from_builtin(t: BuiltinInt) -> IntTy { + match t { + BuiltinInt::Isize => IntTy::Isize, + BuiltinInt::I8 => IntTy::I8, + BuiltinInt::I16 => IntTy::I16, + BuiltinInt::I32 => IntTy::I32, + BuiltinInt::I64 => IntTy::I64, + BuiltinInt::I128 => IntTy::I128, } } -impl From for UintTy { - fn from(t: BuiltinUint) -> Self { - match t { - BuiltinUint::Usize => Self::Usize, - BuiltinUint::U8 => Self::U8, - BuiltinUint::U16 => Self::U16, - BuiltinUint::U32 => Self::U32, - BuiltinUint::U64 => Self::U64, - BuiltinUint::U128 => Self::U128, - } +pub(super) fn uint_ty_from_builtin(t: BuiltinUint) -> UintTy { + match t { + BuiltinUint::Usize => UintTy::Usize, + BuiltinUint::U8 => UintTy::U8, + BuiltinUint::U16 => UintTy::U16, + BuiltinUint::U32 => UintTy::U32, + BuiltinUint::U64 => UintTy::U64, + BuiltinUint::U128 => UintTy::U128, } } -impl From for FloatTy { - fn from(t: BuiltinFloat) -> Self { - match t { - BuiltinFloat::F32 => Self::F32, - BuiltinFloat::F64 => Self::F64, - } +pub(super) fn float_ty_from_builtin(t: BuiltinFloat) -> FloatTy { + match t { + BuiltinFloat::F32 => FloatTy::F32, + BuiltinFloat::F64 => FloatTy::F64, } } -- cgit v1.2.3