From 70dd70b1fcbbbe2e60849412412ef05e7d31eb0a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 13 Nov 2019 09:56:33 +0300 Subject: Reduce duplication between uncertain floats & ints --- crates/ra_hir/src/ty/primitive.rs | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 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 7362de4c3..47789db87 100644 --- a/crates/ra_hir/src/ty/primitive.rs +++ b/crates/ra_hir/src/ty/primitive.rs @@ -4,44 +4,38 @@ use std::fmt; pub use hir_def::builtin_type::{FloatBitness, IntBitness, Signedness}; -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub enum UncertainIntTy { +#[derive(Clone, Copy, Eq, PartialEq, Hash, Debug)] +pub enum Uncertain { Unknown, - Known(IntTy), + Known(T), } -impl From for UncertainIntTy { +impl From for Uncertain { fn from(ty: IntTy) -> Self { - UncertainIntTy::Known(ty) + Uncertain::Known(ty) } } -impl fmt::Display for UncertainIntTy { +impl fmt::Display for Uncertain { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - UncertainIntTy::Unknown => write!(f, "{{integer}}"), - UncertainIntTy::Known(ty) => write!(f, "{}", ty), + Uncertain::Unknown => write!(f, "{{integer}}"), + Uncertain::Known(ty) => write!(f, "{}", ty), } } } -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub enum UncertainFloatTy { - Unknown, - Known(FloatTy), -} - -impl From for UncertainFloatTy { +impl From for Uncertain { fn from(ty: FloatTy) -> Self { - UncertainFloatTy::Known(ty) + Uncertain::Known(ty) } } -impl fmt::Display for UncertainFloatTy { +impl fmt::Display for Uncertain { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - UncertainFloatTy::Unknown => write!(f, "{{float}}"), - UncertainFloatTy::Known(ty) => write!(f, "{}", ty), + Uncertain::Unknown => write!(f, "{{float}}"), + Uncertain::Known(ty) => write!(f, "{}", ty), } } } -- cgit v1.2.3