From 757ed2566701feba8fc67cae3d21a7423254efba Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 5 Dec 2023 21:50:14 -0800 Subject: [PATCH] Move Neg impl into the macro that generates Div and Rem --- library/core/src/num/nonzero.rs | 40 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index 9c396710fd4..b1dd766de31 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -253,15 +253,12 @@ macro_rules! nonzero_integer { } } - nonzero_integer_impl_div_rem!($Ty $signedness $Int); + nonzero_integer_signedness_dependent_impls!($Ty $signedness $Int); }; } -macro_rules! nonzero_integer_impl_div_rem { - ($Ty:ident signed $Int:ty) => { - // nothing for signed ints - }; - +macro_rules! nonzero_integer_signedness_dependent_impls { + // Impls for unsigned nonzero types only. ($Ty:ident unsigned $Int:ty) => { #[stable(feature = "nonzero_div", since = "1.51.0")] impl Div<$Ty> for $Int { @@ -288,6 +285,23 @@ macro_rules! nonzero_integer_impl_div_rem { } } }; + + // Impls for signed nonzero types only. + ($Ty:ident signed $Int:ty) => { + #[stable(feature = "signed_nonzero_neg", since = "1.71.0")] + impl Neg for $Ty { + type Output = $Ty; + + #[inline] + fn neg(self) -> $Ty { + // SAFETY: negation of nonzero cannot yield zero values. + unsafe { $Ty::new_unchecked(self.get().neg()) } + } + } + + forward_ref_unop! { impl Neg, neg for $Ty, + #[stable(feature = "signed_nonzero_neg", since = "1.71.0")] } + }; } // A bunch of methods for unsigned nonzero types only. @@ -921,20 +935,6 @@ macro_rules! nonzero_signed_operations { unsafe { $Ty::new_unchecked(result) } } } - - #[stable(feature = "signed_nonzero_neg", since = "1.71.0")] - impl Neg for $Ty { - type Output = $Ty; - - #[inline] - fn neg(self) -> $Ty { - // SAFETY: negation of nonzero cannot yield zero values. - unsafe { $Ty::new_unchecked(self.get().neg()) } - } - } - - forward_ref_unop! { impl Neg, neg for $Ty, - #[stable(feature = "signed_nonzero_neg", since = "1.71.0")] } )+ } }