about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-03-01 17:51:33 +0100
committerGitHub <noreply@github.com>2024-03-01 17:51:33 +0100
commit68dd5e65a985edc5cc3466b373b2e3f4bb062cb3 (patch)
tree6fbeca05e57e260e6a3b29f628a6a1879818d4e7
parent96e3777a9f35965a6303bf68951983f5387976de (diff)
parentf6d2607163bb043c772b0dc502b89048e204aaa6 (diff)
downloadrust-68dd5e65a985edc5cc3466b373b2e3f4bb062cb3.tar.gz
rust-68dd5e65a985edc5cc3466b373b2e3f4bb062cb3.zip
Rollup merge of #121850 - reitermarkus:generic-nonzero-unsafe-trait, r=Nilstrieb
Make `ZeroablePrimitive` trait unsafe.

Tracking issue: https://github.com/rust-lang/rust/issues/120257

r? `@dtolnay`
-rw-r--r--library/core/src/num/nonzero.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs
index 295b88361cf..9e34c0d240d 100644
--- a/library/core/src/num/nonzero.rs
+++ b/library/core/src/num/nonzero.rs
@@ -24,13 +24,17 @@ mod private {
 /// A marker trait for primitive types which can be zero.
 ///
 /// This is an implementation detail for <code>[NonZero]\<T></code> which may disappear or be replaced at any time.
+///
+/// # Safety
+///
+/// Types implementing this trait must be primitves that are valid when zeroed.
 #[unstable(
     feature = "nonzero_internals",
     reason = "implementation detail which may disappear or be replaced at any time",
     issue = "none"
 )]
 #[const_trait]
-pub trait ZeroablePrimitive: Sized + Copy + private::Sealed {}
+pub unsafe trait ZeroablePrimitive: Sized + Copy + private::Sealed {}
 
 macro_rules! impl_zeroable_primitive {
     ($primitive:ty) => {
@@ -46,7 +50,7 @@ macro_rules! impl_zeroable_primitive {
             reason = "implementation detail which may disappear or be replaced at any time",
             issue = "none"
         )]
-        impl const ZeroablePrimitive for $primitive {}
+        unsafe impl const ZeroablePrimitive for $primitive {}
     };
 }