diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-01-11 01:55:09 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-11 01:55:09 -0500 |
| commit | 46222ce6f804c1e3d1ffbeb2029bfd513e42f34f (patch) | |
| tree | 333c05ff5fd5e341276356b7b8ce00d37d2be59d /library/std/src | |
| parent | 538d5dcbf539a9159c3999a0ae968d836fb72776 (diff) | |
| parent | 9ab77f1ccb6baa931afeacf54594a4a2c7754332 (diff) | |
| download | rust-46222ce6f804c1e3d1ffbeb2029bfd513e42f34f.tar.gz rust-46222ce6f804c1e3d1ffbeb2029bfd513e42f34f.zip | |
Rollup merge of #135347 - samueltardieu:push-qvyxtxsqyxyr, r=jhpratt
Use `NonNull::without_provenance` within the standard library This API removes the need for several `unsafe` blocks, and leads to clearer code. It uses feature `nonnull_provenance` (#135243). Close #135343
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/io/error/repr_bitpacked.rs | 7 | ||||
| -rw-r--r-- | library/std/src/lib.rs | 1 |
2 files changed, 5 insertions, 3 deletions
diff --git a/library/std/src/io/error/repr_bitpacked.rs b/library/std/src/io/error/repr_bitpacked.rs index f958a938646..716da37168d 100644 --- a/library/std/src/io/error/repr_bitpacked.rs +++ b/library/std/src/io/error/repr_bitpacked.rs @@ -103,7 +103,8 @@ //! the time. use core::marker::PhantomData; -use core::ptr::{self, NonNull}; +use core::num::NonZeroUsize; +use core::ptr::NonNull; use super::{Custom, ErrorData, ErrorKind, RawOsError, SimpleMessage}; @@ -176,7 +177,7 @@ impl Repr { let utagged = ((code as usize) << 32) | TAG_OS; // Safety: `TAG_OS` is not zero, so the result of the `|` is not 0. let res = Self( - unsafe { NonNull::new_unchecked(ptr::without_provenance_mut(utagged)) }, + NonNull::without_provenance(unsafe { NonZeroUsize::new_unchecked(utagged) }), PhantomData, ); // quickly smoke-check we encoded the right thing (This generally will @@ -193,7 +194,7 @@ impl Repr { let utagged = ((kind as usize) << 32) | TAG_SIMPLE; // Safety: `TAG_SIMPLE` is not zero, so the result of the `|` is not 0. let res = Self( - unsafe { NonNull::new_unchecked(ptr::without_provenance_mut(utagged)) }, + NonNull::without_provenance(unsafe { NonZeroUsize::new_unchecked(utagged) }), PhantomData, ); // quickly smoke-check we encoded the right thing (This generally will diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 022bbab1012..5c12236617c 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -342,6 +342,7 @@ #![feature(lazy_get)] #![feature(maybe_uninit_slice)] #![feature(maybe_uninit_write_slice)] +#![feature(nonnull_provenance)] #![feature(panic_can_unwind)] #![feature(panic_internals)] #![feature(pin_coerce_unsized_trait)] |
