mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 02:03:53 +00:00
Move Neg impl into the macro that generates Div and Rem
This commit is contained in:
parent
f846ed53e4
commit
757ed25667
@ -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")] }
|
||||
)+
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user