@@ -253,15 +253,12 @@ macro_rules! nonzero_integer {
253
253
}
254
254
}
255
255
256
- nonzero_integer_impl_div_rem !( $Ty $signedness $Int) ;
256
+ nonzero_integer_signedness_dependent_impls !( $Ty $signedness $Int) ;
257
257
} ;
258
258
}
259
259
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.
265
262
( $Ty: ident unsigned $Int: ty) => {
266
263
#[ stable( feature = "nonzero_div" , since = "1.51.0" ) ]
267
264
impl Div <$Ty> for $Int {
@@ -288,6 +285,23 @@ macro_rules! nonzero_integer_impl_div_rem {
288
285
}
289
286
}
290
287
} ;
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
+ } ;
291
305
}
292
306
293
307
// A bunch of methods for unsigned nonzero types only.
@@ -921,20 +935,6 @@ macro_rules! nonzero_signed_operations {
921
935
unsafe { $Ty:: new_unchecked( result) }
922
936
}
923
937
}
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" ) ] }
938
938
) +
939
939
}
940
940
}
0 commit comments