Skip to content

Commit feb9ac0

Browse files
committed
Clean up the fmt macro and format the tests
1 parent 84c5244 commit feb9ac0

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

library/core/src/num/nonzero.rs

+30-18
Original file line numberDiff line numberDiff line change
@@ -110,28 +110,40 @@ impl_zeroable_primitive!(
110110
pub struct NonZero<T: ZeroablePrimitive>(T::NonZeroInner);
111111

112112
macro_rules! impl_nonzero_fmt {
113-
($Trait:ident, $Feature:literal, $Since:literal) => {
114-
#[stable(feature = $Feature, since = $Since)]
115-
impl<T> fmt::$Trait for NonZero<T>
116-
where
117-
T: ZeroablePrimitive + fmt::$Trait,
118-
{
119-
#[inline]
120-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
121-
self.get().fmt(f)
113+
($(#[$Attribute:meta] $Trait:ident)*) => {
114+
$(
115+
#[$Attribute]
116+
impl<T> fmt::$Trait for NonZero<T>
117+
where
118+
T: ZeroablePrimitive + fmt::$Trait,
119+
{
120+
#[inline]
121+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
122+
self.get().fmt(f)
123+
}
122124
}
123-
}
125+
)*
124126
};
125127
}
126128

127-
impl_nonzero_fmt!(Debug, "nonzero", "1.28.0");
128-
impl_nonzero_fmt!(Display, "nonzero", "1.28.0");
129-
impl_nonzero_fmt!(Binary, "nonzero", "1.28.0");
130-
impl_nonzero_fmt!(Octal, "nonzero", "1.28.0");
131-
impl_nonzero_fmt!(LowerHex, "nonzero", "1.28.0");
132-
impl_nonzero_fmt!(UpperHex, "nonzero", "1.28.0");
133-
impl_nonzero_fmt!(LowerExp, "nonzero_fmt_exp", "CURRENT_RUSTC_VERSION");
134-
impl_nonzero_fmt!(UpperExp, "nonzero_fmt_exp", "CURRENT_RUSTC_VERSION");
129+
impl_nonzero_fmt! {
130+
#[stable(feature = "nonzero", since = "1.28.0")]
131+
Debug
132+
#[stable(feature = "nonzero", since = "1.28.0")]
133+
Display
134+
#[stable(feature = "nonzero", since = "1.28.0")]
135+
Binary
136+
#[stable(feature = "nonzero", since = "1.28.0")]
137+
Octal
138+
#[stable(feature = "nonzero", since = "1.28.0")]
139+
LowerHex
140+
#[stable(feature = "nonzero", since = "1.28.0")]
141+
UpperHex
142+
#[stable(feature = "nonzero_fmt_exp", since = "CURRENT_RUSTC_VERSION")]
143+
LowerExp
144+
#[stable(feature = "nonzero_fmt_exp", since = "CURRENT_RUSTC_VERSION")]
145+
UpperExp
146+
}
135147

136148
macro_rules! impl_nonzero_auto_trait {
137149
(unsafe $Trait:ident) => {

library/core/tests/nonzero.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,10 @@ fn test_signed_nonzero_neg() {
358358
#[test]
359359
fn test_nonzero_fmt() {
360360
let i = format!("{0}, {0:?}, {0:x}, {0:X}, {0:#x}, {0:#X}, {0:o}, {0:b}, {0:e}, {0:E}", 42);
361-
let nz = format!("{0}, {0:?}, {0:x}, {0:X}, {0:#x}, {0:#X}, {0:o}, {0:b}, {0:e}, {0:E}", NonZero::new(42).unwrap());
361+
let nz = format!(
362+
"{0}, {0:?}, {0:x}, {0:X}, {0:#x}, {0:#X}, {0:o}, {0:b}, {0:e}, {0:E}",
363+
NonZero::new(42).unwrap()
364+
);
362365

363366
assert_eq!(i, nz);
364-
}
367+
}

0 commit comments

Comments
 (0)