diff options
| author | Markus Reiter <me@reitermark.us> | 2024-03-02 19:44:35 +0100 |
|---|---|---|
| committer | Markus Reiter <me@reitermark.us> | 2024-03-14 17:34:57 +0100 |
| commit | bc532a6307b498eb050e9553c186bf63369c4690 (patch) | |
| tree | e66e76d1c3331e7d53622971aad890fd8d6104d2 | |
| parent | b5c11d1e381fa855b03a5ea2d3a6aa74f8972fea (diff) | |
| download | rust-bc532a6307b498eb050e9553c186bf63369c4690.tar.gz rust-bc532a6307b498eb050e9553c186bf63369c4690.zip | |
Hide implementation details for `NonZero` auto traits.
| -rw-r--r-- | library/core/src/num/nonzero.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index 89d2b4f7dc1..1f7a4e276f5 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -4,8 +4,9 @@ use crate::cmp::Ordering; use crate::fmt; use crate::hash::{Hash, Hasher}; use crate::intrinsics; -use crate::marker::StructuralPartialEq; +use crate::marker::{Freeze, StructuralPartialEq}; use crate::ops::{BitOr, BitOrAssign, Div, Neg, Rem}; +use crate::panic::{RefUnwindSafe, UnwindSafe}; use crate::ptr; use crate::str::FromStr; @@ -129,6 +130,26 @@ impl_nonzero_fmt!(Octal); impl_nonzero_fmt!(LowerHex); impl_nonzero_fmt!(UpperHex); +macro_rules! impl_nonzero_auto_trait { + (unsafe $Trait:ident) => { + #[stable(feature = "nonzero", since = "1.28.0")] + unsafe impl<T> $Trait for NonZero<T> where T: ZeroablePrimitive + $Trait {} + }; + ($Trait:ident) => { + #[stable(feature = "nonzero", since = "1.28.0")] + impl<T> $Trait for NonZero<T> where T: ZeroablePrimitive + $Trait {} + }; +} + +// Implement auto-traits manually based on `T` to avoid docs exposing +// the `ZeroablePrimitive::NonZeroInner` implementation detail. +impl_nonzero_auto_trait!(unsafe Freeze); +impl_nonzero_auto_trait!(RefUnwindSafe); +impl_nonzero_auto_trait!(unsafe Send); +impl_nonzero_auto_trait!(unsafe Sync); +impl_nonzero_auto_trait!(Unpin); +impl_nonzero_auto_trait!(UnwindSafe); + #[stable(feature = "nonzero", since = "1.28.0")] impl<T> Clone for NonZero<T> where |
