diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2025-01-10 22:41:48 +0100 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2025-01-10 23:23:10 +0100 |
| commit | 9ab77f1ccb6baa931afeacf54594a4a2c7754332 (patch) | |
| tree | 484f2e2151651f82091313605592878edd7296da /library/std/src/io/error | |
| parent | 336209eef13882bd1e211b24779584cb7ef911eb (diff) | |
| download | rust-9ab77f1ccb6baa931afeacf54594a4a2c7754332.tar.gz rust-9ab77f1ccb6baa931afeacf54594a4a2c7754332.zip | |
Use `NonNull::without_provenance` within the standard library
This API removes the need for several `unsafe` blocks, and leads to clearer code.
Diffstat (limited to 'library/std/src/io/error')
| -rw-r--r-- | library/std/src/io/error/repr_bitpacked.rs | 7 |
1 files changed, 4 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 |
