Skip to content

Commit 7cfeeb7

Browse files
committed
Refactor floating! macro and nofloat panic message
1 parent 0637517 commit 7cfeeb7

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

library/core/src/fmt/float.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -196,39 +196,40 @@ where
196196
}
197197

198198
macro_rules! floating {
199-
($ty:ident) => {
200-
#[stable(feature = "rust1", since = "1.0.0")]
201-
impl Debug for $ty {
202-
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
203-
float_to_general_debug(fmt, self)
199+
($($ty:ident)*) => (
200+
$(
201+
#[stable(feature = "rust1", since = "1.0.0")]
202+
impl Debug for $ty {
203+
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
204+
float_to_general_debug(fmt, self)
205+
}
204206
}
205-
}
206207

207-
#[stable(feature = "rust1", since = "1.0.0")]
208-
impl Display for $ty {
209-
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
210-
float_to_decimal_display(fmt, self)
208+
#[stable(feature = "rust1", since = "1.0.0")]
209+
impl Display for $ty {
210+
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
211+
float_to_decimal_display(fmt, self)
212+
}
211213
}
212-
}
213214

214-
#[stable(feature = "rust1", since = "1.0.0")]
215-
impl LowerExp for $ty {
216-
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
217-
float_to_exponential_common(fmt, self, false)
215+
#[stable(feature = "rust1", since = "1.0.0")]
216+
impl LowerExp for $ty {
217+
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
218+
float_to_exponential_common(fmt, self, false)
219+
}
218220
}
219-
}
220221

221-
#[stable(feature = "rust1", since = "1.0.0")]
222-
impl UpperExp for $ty {
223-
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
224-
float_to_exponential_common(fmt, self, true)
222+
#[stable(feature = "rust1", since = "1.0.0")]
223+
impl UpperExp for $ty {
224+
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
225+
float_to_exponential_common(fmt, self, true)
226+
}
225227
}
226-
}
227-
};
228+
)*
229+
)
228230
}
229231

230-
floating! { f32 }
231-
floating! { f64 }
232+
floating! { f32 f64 }
232233

233234
#[stable(feature = "rust1", since = "1.0.0")]
234235
impl Debug for f16 {

library/core/src/fmt/nofloat.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
use crate::fmt::{Debug, Formatter, Result};
22

33
macro_rules! floating {
4-
($ty:ident) => {
4+
($($ty:ident)*) => (
5+
$(
56
#[stable(feature = "rust1", since = "1.0.0")]
67
impl Debug for $ty {
78
#[inline]
89
fn fmt(&self, _fmt: &mut Formatter<'_>) -> Result {
9-
panic!("floating point support is turned off");
10+
panic!("floating point fmt support is turned off");
1011
}
11-
}
12-
};
12+
})*
13+
)
1314
}
1415

15-
floating! { f16 }
16-
floating! { f32 }
17-
floating! { f64 }
18-
floating! { f128 }
16+
floating! { f16 f32 f64 f128 }

0 commit comments

Comments
 (0)