@@ -253,15 +253,12 @@ macro_rules! nonzero_integer {
253253 }
254254 }
255255
256- nonzero_integer_impl_div_rem !( $Ty $signedness $Int) ;
256+ nonzero_integer_signedness_dependent_impls !( $Ty $signedness $Int) ;
257257 } ;
258258}
259259
260- macro_rules! nonzero_integer_impl_div_rem {
261- ( $Ty: ident signed $Int: ty) => {
262- // nothing for signed ints
263- } ;
264-
260+ macro_rules! nonzero_integer_signedness_dependent_impls {
261+ // Impls for unsigned nonzero types only.
265262 ( $Ty: ident unsigned $Int: ty) => {
266263 #[ stable( feature = "nonzero_div" , since = "1.51.0" ) ]
267264 impl Div <$Ty> for $Int {
@@ -288,6 +285,23 @@ macro_rules! nonzero_integer_impl_div_rem {
288285 }
289286 }
290287 } ;
288+
289+ // Impls for signed nonzero types only.
290+ ( $Ty: ident signed $Int: ty) => {
291+ #[ stable( feature = "signed_nonzero_neg" , since = "1.71.0" ) ]
292+ impl Neg for $Ty {
293+ type Output = $Ty;
294+
295+ #[ inline]
296+ fn neg( self ) -> $Ty {
297+ // SAFETY: negation of nonzero cannot yield zero values.
298+ unsafe { $Ty:: new_unchecked( self . get( ) . neg( ) ) }
299+ }
300+ }
301+
302+ forward_ref_unop! { impl Neg , neg for $Ty,
303+ #[ stable( feature = "signed_nonzero_neg" , since = "1.71.0" ) ] }
304+ } ;
291305}
292306
293307// A bunch of methods for unsigned nonzero types only.
@@ -921,20 +935,6 @@ macro_rules! nonzero_signed_operations {
921935 unsafe { $Ty:: new_unchecked( result) }
922936 }
923937 }
924-
925- #[ stable( feature = "signed_nonzero_neg" , since = "1.71.0" ) ]
926- impl Neg for $Ty {
927- type Output = $Ty;
928-
929- #[ inline]
930- fn neg( self ) -> $Ty {
931- // SAFETY: negation of nonzero cannot yield zero values.
932- unsafe { $Ty:: new_unchecked( self . get( ) . neg( ) ) }
933- }
934- }
935-
936- forward_ref_unop! { impl Neg , neg for $Ty,
937- #[ stable( feature = "signed_nonzero_neg" , since = "1.71.0" ) ] }
938938 ) +
939939 }
940940}
0 commit comments