|
56 | 56 | //!
|
57 | 57 | //! Conceptually you might think of this more like:
|
58 | 58 | //!
|
59 |
| -//! ```ignore |
| 59 | +//! ```ignore (exposition-only) |
60 | 60 | //! union Repr {
|
61 | 61 | //! // holds integer (Simple/Os) variants, and
|
62 | 62 | //! // provides access to the tag bits.
|
@@ -159,7 +159,7 @@ impl Repr {
|
159 | 159 |
|
160 | 160 | #[inline]
|
161 | 161 | pub(super) const fn new_simple_message(m: &'static SimpleMessage) -> Self {
|
162 |
| - // Safety: We're a Repr, decode_repr is fine. |
| 162 | + // Safety: References are never null. |
163 | 163 | Self(unsafe { NonNull::new_unchecked(m as *const _ as *mut ()) })
|
164 | 164 | }
|
165 | 165 |
|
@@ -213,7 +213,7 @@ where
|
213 | 213 | TAG_SIMPLE => {
|
214 | 214 | let kind_bits = (bits >> 32) as u32;
|
215 | 215 | let kind = kind_from_prim(kind_bits).unwrap_or_else(|| {
|
216 |
| - debug_assert!(false, "Invalid io::error::Repr bits: `Repr({:#016x})`", bits); |
| 216 | + debug_assert!(false, "Invalid io::error::Repr bits: `Repr({:#018x})`", bits); |
217 | 217 | // This means the `ptr` passed in was not valid, which voilates
|
218 | 218 | // the unsafe contract of `decode_repr`.
|
219 | 219 | //
|
@@ -299,8 +299,11 @@ fn kind_from_prim(ek: u32) -> Option<ErrorKind> {
|
299 | 299 | }
|
300 | 300 |
|
301 | 301 | // Some static checking to alert us if a change breaks any of the assumptions
|
302 |
| -// that our encoding relies on. If any of these are hit on a platform that |
303 |
| -// libstd supports, we should just make sure `repr_unpacked.rs` is used. |
| 302 | +// that our encoding relies on for correctness and soundness. (Some of these are |
| 303 | +// a bit overly thorough/cautious, admittedly) |
| 304 | +// |
| 305 | +// If any of these are hit on a platform that libstd supports, we should just |
| 306 | +// make sure `repr_unpacked.rs` is used instead. |
304 | 307 | macro_rules! static_assert {
|
305 | 308 | ($condition:expr) => {
|
306 | 309 | const _: [(); 0] = [(); (!$condition) as usize];
|
@@ -332,6 +335,11 @@ static_assert!(TAG_SIMPLE != 0);
|
332 | 335 | static_assert!(TAG_SIMPLE_MESSAGE == 0);
|
333 | 336 |
|
334 | 337 | // Check that the point of all of this still holds.
|
| 338 | +// |
| 339 | +// We'd check against `io::Error`, but *technically* it's allowed to vary, |
| 340 | +// as it's not `#[repr(transparent)]`/`#[repr(C)]`. We could add that, but |
| 341 | +// the `#[repr()]` would show up in rustdoc, which might be seen as a stable |
| 342 | +// commitment. |
335 | 343 | static_assert!(size_of::<Repr>() == 8);
|
336 | 344 | static_assert!(size_of::<Option<Repr>>() == 8);
|
337 | 345 | static_assert!(size_of::<Result<(), Repr>>() == 8);
|
|
0 commit comments