about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2023-12-05 21:50:14 -0800
committerDavid Tolnay <dtolnay@gmail.com>2024-01-14 12:45:09 -0800
commit757ed2566701feba8fc67cae3d21a7423254efba (patch)
tree0960847b903bad80f4c6f01360ac393d48ce472a
parentf846ed53e41a18fbb900e794467351fda5ffbb80 (diff)
downloadrust-757ed2566701feba8fc67cae3d21a7423254efba.tar.gz
rust-757ed2566701feba8fc67cae3d21a7423254efba.zip
Move Neg impl into the macro that generates Div and Rem
-rw-r--r--library/core/src/num/nonzero.rs40
1 files 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")] }
         )+
     }
 }