diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2023-08-15 14:29:46 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-15 14:29:46 +0200 |
| commit | f527d56c086842ac177c65ed09cf875cf0139bc0 (patch) | |
| tree | 295a3e132ff1bdf3fcc336f5383ba2c3d9c22758 /library/std/src/sys | |
| parent | f0987ab45b22a1568dfb23e003b85c7524b65f26 (diff) | |
| parent | fe1a034f16adbed4302e4d27be96a7ec6fb27177 (diff) | |
Rollup merge of #114800 - RalfJung:transparent, r=cuviper
std: add some missing repr(transparent) For some types we don't want to stably guarantee this, so hide the `repr` from rustdoc. This nice approach was suggested by `@thomcc.`
Diffstat (limited to 'library/std/src/sys')
| -rw-r--r-- | library/std/src/sys/wasi/fd.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/library/std/src/sys/wasi/fd.rs b/library/std/src/sys/wasi/fd.rs index 1b50c2ea6dd..d7295a799da 100644 --- a/library/std/src/sys/wasi/fd.rs +++ b/library/std/src/sys/wasi/fd.rs @@ -16,14 +16,20 @@ pub struct WasiFd { fn iovec<'a>(a: &'a mut [IoSliceMut<'_>]) -> &'a [wasi::Iovec] { assert_eq!(mem::size_of::<IoSliceMut<'_>>(), mem::size_of::<wasi::Iovec>()); assert_eq!(mem::align_of::<IoSliceMut<'_>>(), mem::align_of::<wasi::Iovec>()); - // SAFETY: `IoSliceMut` and `IoVec` have exactly the same memory layout + // SAFETY: `IoSliceMut` and `IoVec` have exactly the same memory layout. + // We decorate our `IoSliceMut` with `repr(transparent)` (see `io.rs`), and + // `crate::io::IoSliceMut` is a `repr(transparent)` wrapper around our type, so this is + // guaranteed. unsafe { mem::transmute(a) } } fn ciovec<'a>(a: &'a [IoSlice<'_>]) -> &'a [wasi::Ciovec] { assert_eq!(mem::size_of::<IoSlice<'_>>(), mem::size_of::<wasi::Ciovec>()); assert_eq!(mem::align_of::<IoSlice<'_>>(), mem::align_of::<wasi::Ciovec>()); - // SAFETY: `IoSlice` and `CIoVec` have exactly the same memory layout + // SAFETY: `IoSlice` and `CIoVec` have exactly the same memory layout. + // We decorate our `IoSlice` with `repr(transparent)` (see `io.rs`), and + // `crate::io::IoSlice` is a `repr(transparent)` wrapper around our type, so this is + // guaranteed. unsafe { mem::transmute(a) } } |
