Skip to content

Commit

Permalink
Eliminate use of #[cfg_attr(not(doc), repr(transparent))]
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 14, 2023
1 parent ee8c9d3 commit 27411f9
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 28 deletions.
2 changes: 1 addition & 1 deletion library/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ where
/// ```
///
#[unstable(feature = "error_generic_member_access", issue = "99301")]
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
#[repr(transparent)]
pub struct Request<'a>(dyn Erased<'a> + 'a);

impl<'a> Request<'a> {
Expand Down
8 changes: 3 additions & 5 deletions library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ use crate::str;
#[rustc_has_incoherent_inherent_impls]
#[lang = "CStr"]
// `fn from` in `impl From<&CStr> for Box<CStr>` current implementation relies
// on `CStr` being layout-compatible with `[u8]`.
// However, `CStr` layout is considered an implementation detail and must not be relied upon. We
// want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under
// `cfg(doc)`. This is an ad-hoc implementation of attribute privacy.
#[cfg_attr(not(doc), repr(transparent))]
// on `CStr` being layout-compatible with `[u8]`. However, `CStr` layout is
// considered an implementation detail and must not be relied upon.
#[repr(transparent)]
pub struct CStr {
// FIXME: this should not be represented with a DST slice but rather with
// just a raw `c_char` along with some form of marker to make
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl fmt::Debug for c_void {
target_os = "uefi",
windows,
))]
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
#[repr(transparent)]
#[unstable(
feature = "c_variadic",
reason = "the `c_variadic` feature has not been properly tested on \
Expand Down Expand Up @@ -374,7 +374,7 @@ pub struct VaListImpl<'f> {
}

/// A wrapper for a `va_list`
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
#[repr(transparent)]
#[derive(Debug)]
#[unstable(
feature = "c_variadic",
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/task/wake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl fmt::Debug for Context<'_> {
///
/// [`Future::poll()`]: core::future::Future::poll
/// [`Poll::Pending`]: core::task::Poll::Pending
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/66401
#[repr(transparent)]
#[stable(feature = "futures_api", since = "1.36.0")]
pub struct Waker {
waker: RawWaker,
Expand Down
2 changes: 1 addition & 1 deletion library/portable-simd/crates/core_simd/src/masks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl_element! { isize }
/// The layout of this type is unspecified, and may change between platforms
/// and/or Rust versions, and code should not assume that it is equivalent to
/// `[T; LANES]`.
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
#[repr(transparent)]
pub struct Mask<T, const LANES: usize>(mask_impl::Mask<T, LANES>)
where
T: MaskElement,
Expand Down
10 changes: 4 additions & 6 deletions library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ impl crate::sealed::Sealed for OsString {}
/// [conversions]: super#conversions
#[cfg_attr(not(test), rustc_diagnostic_item = "OsStr")]
#[stable(feature = "rust1", since = "1.0.0")]
// `OsStr::from_inner` current implementation relies
// on `OsStr` being layout-compatible with `Slice`.
// However, `OsStr` layout is considered an implementation detail and must not be relied upon. We
// want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under
// `cfg(doc)`. This is an ad-hoc implementation of attribute privacy.
#[cfg_attr(not(doc), repr(transparent))]
// `OsStr::from_inner` current implementation relies on `OsStr` being layout-
// compatible with `Slice`. However, `OsStr` layout is considered an
// implementation detail and must not be relied upon.
#[repr(transparent)]
pub struct OsStr {
inner: Slice,
}
Expand Down
20 changes: 8 additions & 12 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,12 +1158,10 @@ impl FusedIterator for Ancestors<'_> {}
/// Which method works best depends on what kind of situation you're in.
#[cfg_attr(not(test), rustc_diagnostic_item = "PathBuf")]
#[stable(feature = "rust1", since = "1.0.0")]
// `PathBuf::as_mut_vec` current implementation relies
// on `PathBuf` being layout-compatible with `Vec<u8>`.
// However, `PathBuf` layout is considered an implementation detail and must not be relied upon. We
// want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under
// `cfg(doc)`. This is an ad-hoc implementation of attribute privacy.
#[cfg_attr(not(doc), repr(transparent))]
// `PathBuf::as_mut_vec` current implementation relies on `PathBuf` being
// layout-compatible with `Vec<u8>`. However, `PathBuf` layout is considered an
// implementation detail and must not be relied upon.
#[repr(transparent)]
pub struct PathBuf {
inner: OsString,
}
Expand Down Expand Up @@ -1983,12 +1981,10 @@ impl AsRef<OsStr> for PathBuf {
/// ```
#[cfg_attr(not(test), rustc_diagnostic_item = "Path")]
#[stable(feature = "rust1", since = "1.0.0")]
// `Path::new` current implementation relies
// on `Path` being layout-compatible with `OsStr`.
// However, `Path` layout is considered an implementation detail and must not be relied upon. We
// want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under
// `cfg(doc)`. This is an ad-hoc implementation of attribute privacy.
#[cfg_attr(not(doc), repr(transparent))]
// `Path::new` current implementation relies on `Path` being layout-compatible
// with `OsStr`. However, `Path` layout is considered an implementation detail
// and must not be relied upon.
#[repr(transparent)]
pub struct Path {
inner: OsStr,
}
Expand Down

0 comments on commit 27411f9

Please sign in to comment.