From 628b530e92c1579f3924c37290ad59ac0512d2a0 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 16 Mar 2019 16:50:31 +0100 Subject: Some more Ty displaying cleanup --- crates/ra_hir/src/ty/primitive.rs | 64 +++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 33 deletions(-) (limited to 'crates/ra_hir/src/ty/primitive.rs') diff --git a/crates/ra_hir/src/ty/primitive.rs b/crates/ra_hir/src/ty/primitive.rs index 5741ca90d..30aeac48e 100644 --- a/crates/ra_hir/src/ty/primitive.rs +++ b/crates/ra_hir/src/ty/primitive.rs @@ -10,14 +10,6 @@ pub enum UncertainIntTy { } impl UncertainIntTy { - pub fn ty_to_string(&self) -> &'static str { - match *self { - UncertainIntTy::Unknown => "{integer}", - UncertainIntTy::Signed(ty) => ty.ty_to_string(), - UncertainIntTy::Unsigned(ty) => ty.ty_to_string(), - } - } - pub fn from_name(name: &Name) -> Option { if let Some(ty) = IntTy::from_name(name) { Some(UncertainIntTy::Signed(ty)) @@ -29,6 +21,16 @@ impl UncertainIntTy { } } +impl fmt::Display for UncertainIntTy { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + UncertainIntTy::Unknown => write!(f, "{{integer}}"), + UncertainIntTy::Signed(ty) => write!(f, "{}", ty), + UncertainIntTy::Unsigned(ty) => write!(f, "{}", ty), + } + } +} + #[derive(Debug, Clone, Eq, PartialEq, Hash, Copy)] pub enum UncertainFloatTy { Unknown, @@ -36,13 +38,6 @@ pub enum UncertainFloatTy { } impl UncertainFloatTy { - pub fn ty_to_string(&self) -> &'static str { - match *self { - UncertainFloatTy::Unknown => "{float}", - UncertainFloatTy::Known(ty) => ty.ty_to_string(), - } - } - pub fn from_name(name: &Name) -> Option { if let Some(ty) = FloatTy::from_name(name) { Some(UncertainFloatTy::Known(ty)) @@ -52,6 +47,15 @@ impl UncertainFloatTy { } } +impl fmt::Display for UncertainFloatTy { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + UncertainFloatTy::Unknown => write!(f, "{{float}}"), + UncertainFloatTy::Known(ty) => write!(f, "{}", ty), + } + } +} + #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)] pub enum IntTy { Isize, @@ -70,22 +74,19 @@ impl fmt::Debug for IntTy { 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 { + let s = match *self { IntTy::Isize => "isize", IntTy::I8 => "i8", IntTy::I16 => "i16", IntTy::I32 => "i32", IntTy::I64 => "i64", IntTy::I128 => "i128", - } + }; + write!(f, "{}", s) } +} +impl IntTy { pub fn from_name(name: &Name) -> Option { match name.as_known_name()? { KnownName::Isize => Some(IntTy::Isize), @@ -109,18 +110,21 @@ pub enum UintTy { U128, } -impl UintTy { - pub fn ty_to_string(&self) -> &'static str { - match *self { +impl fmt::Display for UintTy { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let s = match *self { UintTy::Usize => "usize", UintTy::U8 => "u8", UintTy::U16 => "u16", UintTy::U32 => "u32", UintTy::U64 => "u64", UintTy::U128 => "u128", - } + }; + write!(f, "{}", s) } +} +impl UintTy { pub fn from_name(name: &Name) -> Option { match name.as_known_name()? { KnownName::Usize => Some(UintTy::Usize), @@ -140,12 +144,6 @@ impl fmt::Debug for UintTy { } } -impl fmt::Display for UintTy { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.ty_to_string()) - } -} - #[derive(Clone, PartialEq, Eq, Hash, Copy, PartialOrd, Ord)] pub enum FloatTy { F32, -- cgit v1.2.3