@@ -4,8 +4,9 @@ use crate::cmp::Ordering;
44use crate :: fmt;
55use crate :: hash:: { Hash , Hasher } ;
66use crate :: intrinsics;
7- use crate :: marker:: StructuralPartialEq ;
7+ use crate :: marker:: { Freeze , StructuralPartialEq } ;
88use crate :: ops:: { BitOr , BitOrAssign , Div , Neg , Rem } ;
9+ use crate :: panic:: { RefUnwindSafe , UnwindSafe } ;
910use crate :: ptr;
1011use crate :: str:: FromStr ;
1112
@@ -129,6 +130,26 @@ impl_nonzero_fmt!(Octal);
129130impl_nonzero_fmt ! ( LowerHex ) ;
130131impl_nonzero_fmt ! ( UpperHex ) ;
131132
133+ macro_rules! impl_nonzero_auto_trait {
134+ ( unsafe $Trait: ident) => {
135+ #[ stable( feature = "nonzero" , since = "1.28.0" ) ]
136+ unsafe impl <T > $Trait for NonZero <T > where T : ZeroablePrimitive + $Trait { }
137+ } ;
138+ ( $Trait: ident) => {
139+ #[ stable( feature = "nonzero" , since = "1.28.0" ) ]
140+ impl <T > $Trait for NonZero <T > where T : ZeroablePrimitive + $Trait { }
141+ } ;
142+ }
143+
144+ // Implement auto-traits manually based on `T` to avoid docs exposing
145+ // the `ZeroablePrimitive::NonZeroInner` implementation detail.
146+ impl_nonzero_auto_trait ! ( unsafe Freeze ) ;
147+ impl_nonzero_auto_trait ! ( RefUnwindSafe ) ;
148+ impl_nonzero_auto_trait ! ( unsafe Send ) ;
149+ impl_nonzero_auto_trait ! ( unsafe Sync ) ;
150+ impl_nonzero_auto_trait ! ( Unpin ) ;
151+ impl_nonzero_auto_trait ! ( UnwindSafe ) ;
152+
132153#[ stable( feature = "nonzero" , since = "1.28.0" ) ]
133154impl < T > Clone for NonZero < T >
134155where
0 commit comments