diff options
| author | bors <bors@rust-lang.org> | 2022-04-04 09:40:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-04-04 09:40:33 +0000 |
| commit | 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c (patch) | |
| tree | 935260f3cad9ef2b64dab97a2ebc5bcc152200c3 /library/std/src/io/error/repr_bitpacked.rs | |
| parent | edbed409aaed33aa949e7044fbf39c366b0af92b (diff) | |
| parent | 31f4840af571ff0371c2189aed425b6821153b83 (diff) | |
| download | rust-1.60.0.tar.gz rust-1.60.0.zip | |
Auto merge of #95639 - pietroalbini:pa-1.60.0-stable, r=pietroalbini 1.60.0
Prepare 1.60.0 stable release This PR bumps the channel to stable, and backports the following PRs: * Miscellaneous release notes updates. * https://github.com/rust-lang/rust/pull/94817 * https://github.com/rust-lang/rust/pull/95256 r? `@ghost`
Diffstat (limited to 'library/std/src/io/error/repr_bitpacked.rs')
| -rw-r--r-- | library/std/src/io/error/repr_bitpacked.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/library/std/src/io/error/repr_bitpacked.rs b/library/std/src/io/error/repr_bitpacked.rs index 4301e941b3d..17d07ff5662 100644 --- a/library/std/src/io/error/repr_bitpacked.rs +++ b/library/std/src/io/error/repr_bitpacked.rs @@ -104,6 +104,7 @@ use super::{Custom, ErrorData, ErrorKind, SimpleMessage}; use alloc::boxed::Box; +use core::marker::PhantomData; use core::mem::{align_of, size_of}; use core::ptr::NonNull; @@ -114,8 +115,17 @@ const TAG_CUSTOM: usize = 0b01; const TAG_OS: usize = 0b10; const TAG_SIMPLE: usize = 0b11; +/// The internal representation. +/// +/// See the module docs for more, this is just a way to hack in a check that we +/// indeed are not unwind-safe. +/// +/// ```compile_fail,E0277 +/// fn is_unwind_safe<T: core::panic::UnwindSafe>() {} +/// is_unwind_safe::<std::io::Error>(); +/// ``` #[repr(transparent)] -pub(super) struct Repr(NonNull<()>); +pub(super) struct Repr(NonNull<()>, PhantomData<ErrorData<Box<Custom>>>); // All the types `Repr` stores internally are Send + Sync, and so is it. unsafe impl Send for Repr {} @@ -145,7 +155,7 @@ impl Repr { // box, and `TAG_CUSTOM` just... isn't zero -- it's `0b01`). Therefore, // `TAG_CUSTOM + p` isn't zero and so `tagged` can't be, and the // `new_unchecked` is safe. - let res = Self(unsafe { NonNull::new_unchecked(tagged) }); + let res = Self(unsafe { NonNull::new_unchecked(tagged) }, PhantomData); // quickly smoke-check we encoded the right thing (This generally will // only run in libstd's tests, unless the user uses -Zbuild-std) debug_assert!(matches!(res.data(), ErrorData::Custom(_)), "repr(custom) encoding failed"); @@ -156,7 +166,7 @@ impl Repr { pub(super) fn new_os(code: i32) -> Self { 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(utagged as *mut ()) }); + let res = Self(unsafe { NonNull::new_unchecked(utagged as *mut ()) }, PhantomData); // quickly smoke-check we encoded the right thing (This generally will // only run in libstd's tests, unless the user uses -Zbuild-std) debug_assert!( @@ -171,7 +181,7 @@ impl Repr { pub(super) fn new_simple(kind: ErrorKind) -> Self { 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(utagged as *mut ()) }); + let res = Self(unsafe { NonNull::new_unchecked(utagged as *mut ()) }, PhantomData); // quickly smoke-check we encoded the right thing (This generally will // only run in libstd's tests, unless the user uses -Zbuild-std) debug_assert!( @@ -185,7 +195,7 @@ impl Repr { #[inline] pub(super) const fn new_simple_message(m: &'static SimpleMessage) -> Self { // Safety: References are never null. - Self(unsafe { NonNull::new_unchecked(m as *const _ as *mut ()) }) + Self(unsafe { NonNull::new_unchecked(m as *const _ as *mut ()) }, PhantomData) } #[inline] |
