Skip to content

Commit bebb9ea

Browse files
authored
Rollup merge of rust-lang#121850 - reitermarkus:generic-nonzero-unsafe-trait, r=Nilstrieb
Make `ZeroablePrimitive` trait unsafe. Tracking issue: rust-lang#120257 r? `@dtolnay`
2 parents f1871c3 + 2cb31dc commit bebb9ea

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

core/src/num/nonzero.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ mod private {
2424
/// A marker trait for primitive types which can be zero.
2525
///
2626
/// This is an implementation detail for <code>[NonZero]\<T></code> which may disappear or be replaced at any time.
27+
///
28+
/// # Safety
29+
///
30+
/// Types implementing this trait must be primitves that are valid when zeroed.
2731
#[unstable(
2832
feature = "nonzero_internals",
2933
reason = "implementation detail which may disappear or be replaced at any time",
3034
issue = "none"
3135
)]
3236
#[const_trait]
33-
pub trait ZeroablePrimitive: Sized + Copy + private::Sealed {}
37+
pub unsafe trait ZeroablePrimitive: Sized + Copy + private::Sealed {}
3438

3539
macro_rules! impl_zeroable_primitive {
3640
($primitive:ty) => {
@@ -46,7 +50,7 @@ macro_rules! impl_zeroable_primitive {
4650
reason = "implementation detail which may disappear or be replaced at any time",
4751
issue = "none"
4852
)]
49-
impl const ZeroablePrimitive for $primitive {}
53+
unsafe impl const ZeroablePrimitive for $primitive {}
5054
};
5155
}
5256

0 commit comments

Comments
 (0)