Skip to content

Commit b994f47

Browse files
committed
Hide implementation details for NonZero auto traits.
1 parent 3673ebf commit b994f47

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

library/core/src/num/nonzero.rs

+16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::marker::StructuralPartialEq;
88
use crate::ops::{BitOr, BitOrAssign, Div, Neg, Rem};
99
use crate::ptr;
1010
use crate::str::FromStr;
11+
use crate::panic::{RefUnwindSafe, UnwindSafe};
1112

1213
use super::from_str_radix;
1314
use super::{IntErrorKind, ParseIntError};
@@ -129,6 +130,21 @@ impl_nonzero_fmt!(Octal);
129130
impl_nonzero_fmt!(LowerHex);
130131
impl_nonzero_fmt!(UpperHex);
131132

133+
macro_rules! impl_nonzero_auto_trait {
134+
($Trait:ident) => {
135+
#[stable(feature = "nonzero", since = "1.28.0")]
136+
unsafe impl<T> $Trait for NonZero<T> where T: ZeroablePrimitive + $Trait {}
137+
};
138+
}
139+
140+
// Implement auto-traits manually based on `T` to avoid docs exposing
141+
// the `ZeroablePrimitive::NonZeroInner` implementation detail.
142+
impl_nonzero_auto_trait!(RefUnwindSafe);
143+
impl_nonzero_auto_trait!(Send);
144+
impl_nonzero_auto_trait!(Sync);
145+
impl_nonzero_auto_trait!(Unpin);
146+
impl_nonzero_auto_trait!(UnwindSafe);
147+
132148
#[stable(feature = "nonzero", since = "1.28.0")]
133149
impl<T> Clone for NonZero<T>
134150
where

0 commit comments

Comments
 (0)