File tree Expand file tree Collapse file tree 5 files changed +22
-2
lines changed Expand file tree Collapse file tree 5 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,9 @@ use crate::str;
8888// When attribute privacy is implemented, `CStr` should be annotated as `#[repr(transparent)]`.
8989// Anyway, `CStr` representation and layout are considered implementation detail, are
9090// not documented and must not be relied upon.
91+ // For now we just hide this from rustdoc, technically making our doc test builds rely on
92+ // unspecified layout assumptions. We are std, so we can get away with that.
93+ #[ cfg_attr( not( doc) , repr( transparent) ) ]
9194pub struct CStr {
9295 // FIXME: this should not be represented with a DST slice but rather with
9396 // just a raw `c_char` along with some form of marker to make
Original file line number Diff line number Diff line change @@ -116,6 +116,9 @@ impl crate::sealed::Sealed for OsString {}
116116// When attribute privacy is implemented, `OsStr` should be annotated as `#[repr(transparent)]`.
117117// Anyway, `OsStr` representation and layout are considered implementation details, are
118118// not documented and must not be relied upon.
119+ // For now we just hide this from rustdoc, technically making our doc test builds rely on
120+ // unspecified layout assumptions. We are std, so we can get away with that.
121+ #[ cfg_attr( not( doc) , repr( transparent) ) ]
119122pub struct OsStr {
120123 inner : Slice ,
121124}
Original file line number Diff line number Diff line change @@ -1164,6 +1164,9 @@ impl FusedIterator for Ancestors<'_> {}
11641164// When attribute privacy is implemented, `PathBuf` should be annotated as `#[repr(transparent)]`.
11651165// Anyway, `PathBuf` representation and layout are considered implementation detail, are
11661166// not documented and must not be relied upon.
1167+ // For now we just hide this from rustdoc, technically making our doc test builds rely on
1168+ // unspecified layout assumptions. We are std, so we can get away with that.
1169+ #[ cfg_attr( not( doc) , repr( transparent) ) ]
11671170pub struct PathBuf {
11681171 inner : OsString ,
11691172}
@@ -1989,6 +1992,9 @@ impl AsRef<OsStr> for PathBuf {
19891992// When attribute privacy is implemented, `Path` should be annotated as `#[repr(transparent)]`.
19901993// Anyway, `Path` representation and layout are considered implementation detail, are
19911994// not documented and must not be relied upon.
1995+ // For now we just hide this from rustdoc, technically making our doc test builds rely on
1996+ // unspecified layout assumptions. We are std, so we can get away with that.
1997+ #[ cfg_attr( not( doc) , repr( transparent) ) ]
19921998pub struct Path {
19931999 inner : OsStr ,
19942000}
Original file line number Diff line number Diff line change @@ -16,14 +16,20 @@ pub struct WasiFd {
1616fn iovec < ' a > ( a : & ' a mut [ IoSliceMut < ' _ > ] ) -> & ' a [ wasi:: Iovec ] {
1717 assert_eq ! ( mem:: size_of:: <IoSliceMut <' _>>( ) , mem:: size_of:: <wasi:: Iovec >( ) ) ;
1818 assert_eq ! ( mem:: align_of:: <IoSliceMut <' _>>( ) , mem:: align_of:: <wasi:: Iovec >( ) ) ;
19- // SAFETY: `IoSliceMut` and `IoVec` have exactly the same memory layout
19+ // SAFETY: `IoSliceMut` and `IoVec` have exactly the same memory layout.
20+ // We decorate our `IoSliceMut` with `repr(transparent)` (see `io.rs`), and
21+ // `crate::io::IoSliceMut` is a `repr(transparent)` wrapper around our type, so this is
22+ // guaranteed.
2023 unsafe { mem:: transmute ( a) }
2124}
2225
2326fn ciovec < ' a > ( a : & ' a [ IoSlice < ' _ > ] ) -> & ' a [ wasi:: Ciovec ] {
2427 assert_eq ! ( mem:: size_of:: <IoSlice <' _>>( ) , mem:: size_of:: <wasi:: Ciovec >( ) ) ;
2528 assert_eq ! ( mem:: align_of:: <IoSlice <' _>>( ) , mem:: align_of:: <wasi:: Ciovec >( ) ) ;
26- // SAFETY: `IoSlice` and `CIoVec` have exactly the same memory layout
29+ // SAFETY: `IoSlice` and `CIoVec` have exactly the same memory layout.
30+ // We decorate our `IoSlice` with `repr(transparent)` (see `io.rs`), and
31+ // `crate::io::IoSlice` is a `repr(transparent)` wrapper around our type, so this is
32+ // guaranteed.
2733 unsafe { mem:: transmute ( a) }
2834}
2935
Original file line number Diff line number Diff line change @@ -459,6 +459,7 @@ impl Wtf8Buf {
459459 /// Converts this `Wtf8Buf` into a boxed `Wtf8`.
460460 #[ inline]
461461 pub fn into_box ( self ) -> Box < Wtf8 > {
462+ // SAFETY: relies on `Wtf8` being `repr(transparent)`.
462463 unsafe { mem:: transmute ( self . bytes . into_boxed_slice ( ) ) }
463464 }
464465
@@ -511,6 +512,7 @@ impl Extend<CodePoint> for Wtf8Buf {
511512/// Similar to `&str`, but can additionally contain surrogate code points
512513/// if they’re not in a surrogate pair.
513514#[ derive( Eq , Ord , PartialEq , PartialOrd ) ]
515+ #[ repr( transparent) ]
514516pub struct Wtf8 {
515517 bytes : [ u8 ] ,
516518}
You can’t perform that action at this time.
0 commit comments