Refactor floating macro and nofloat panic message

This commit is contained in:
zlfn 2024-10-15 18:39:30 +09:00
parent 0637517da6
commit 99af761632
3 changed files with 60 additions and 58 deletions

View File

@ -196,7 +196,8 @@ where
} }
macro_rules! floating { macro_rules! floating {
($ty:ident) => { ($($ty:ident)*) => {
$(
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Debug for $ty { impl Debug for $ty {
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result { fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
@ -224,11 +225,11 @@ macro_rules! floating {
float_to_exponential_common(fmt, self, true) float_to_exponential_common(fmt, self, true)
} }
} }
)*
}; };
} }
floating! { f32 } floating! { f32 f64 }
floating! { f64 }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Debug for f16 { impl Debug for f16 {

View File

@ -1,18 +1,17 @@
use crate::fmt::{Debug, Formatter, Result}; use crate::fmt::{Debug, Formatter, Result};
macro_rules! floating { macro_rules! floating {
($ty:ident) => { ($($ty:ident)*) => {
$(
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Debug for $ty { impl Debug for $ty {
#[inline] #[inline]
fn fmt(&self, _fmt: &mut Formatter<'_>) -> Result { fn fmt(&self, _fmt: &mut Formatter<'_>) -> Result {
panic!("floating point support is turned off"); panic!("floating point fmt support is turned off");
} }
} }
)*
}; };
} }
floating! { f16 } floating! { f16 f32 f64 f128 }
floating! { f32 }
floating! { f64 }
floating! { f128 }

View File

@ -169,7 +169,8 @@ integer! { i64, u64 }
integer! { i128, u128 } integer! { i128, u128 }
macro_rules! impl_Debug { macro_rules! impl_Debug {
($($T:ident)*) => {$( ($($T:ident)*) => {
$(
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for $T { impl fmt::Debug for $T {
#[inline] #[inline]
@ -183,7 +184,8 @@ macro_rules! impl_Debug {
} }
} }
} }
)*}; )*
};
} }
// 2 digit decimal look up table // 2 digit decimal look up table