Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate use of #[cfg_attr(not(doc), repr(...))] #116743

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 7 additions & 7 deletions library/core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ mod c_long_definition {
// be UB.
#[doc = include_str!("c_void.md")]
#[lang = "c_void"]
#[cfg_attr(not(doc), repr(u8))] // work around https://github.com/rust-lang/rust/issues/90435
#[repr(u8)]
Copy link
Member

@fmease fmease Oct 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this will still show up in the docs, my PR only affects repr(transparent). Further, it doesn't take into account #[doc(hidden)] (in this case on variants). Arguably, rustdoc should hide #[repr(u8)] and respect doc(hidden). I can send a PR right away.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we keep non-transparent reprs for enums though? It's useful, especially repr(c) ones for FFI.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure, but in this case both variants are doc(hidden). I plan on hiding those reprs if all variants are hidden.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

#[stable(feature = "core_c_void", since = "1.30.0")]
pub enum c_void {
#[unstable(
Expand Down 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 @@ -297,7 +297,7 @@ impl<'f> fmt::Debug for VaListImpl<'f> {
not(target_os = "uefi"),
not(windows),
))]
#[cfg_attr(not(doc), repr(C))] // work around https://github.com/rust-lang/rust/issues/66401
#[repr(C)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, repr(C) is still going to show up in the docs :| Let me update rustdoc to handle that as well.

#[derive(Debug)]
#[unstable(
feature = "c_variadic",
Expand All @@ -317,7 +317,7 @@ pub struct VaListImpl<'f> {

/// PowerPC ABI implementation of a `va_list`.
#[cfg(all(target_arch = "powerpc", not(target_os = "uefi"), not(windows)))]
#[cfg_attr(not(doc), repr(C))] // work around https://github.com/rust-lang/rust/issues/66401
#[repr(C)]
#[derive(Debug)]
#[unstable(
feature = "c_variadic",
Expand All @@ -337,7 +337,7 @@ pub struct VaListImpl<'f> {

/// s390x ABI implementation of a `va_list`.
#[cfg(target_arch = "s390x")]
#[cfg_attr(not(doc), repr(C))] // work around https://github.com/rust-lang/rust/issues/66401
#[repr(C)]
#[derive(Debug)]
#[unstable(
feature = "c_variadic",
Expand All @@ -356,7 +356,7 @@ pub struct VaListImpl<'f> {

/// x86_64 ABI implementation of a `va_list`.
#[cfg(all(target_arch = "x86_64", not(target_os = "uefi"), not(windows)))]
#[cfg_attr(not(doc), repr(C))] // work around https://github.com/rust-lang/rust/issues/66401
#[repr(C)]
#[derive(Debug)]
#[unstable(
feature = "c_variadic",
Expand All @@ -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
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