Skip to content

Commit 8d162fb

Browse files
authored
Rollup merge of rust-lang#107680 - dtolnay:docrepr, r=Amanieu
Hide repr attribute from doc of types without guaranteed repr Rustdoc has an undesirable behavior of blindly copying `repr` into the documentation of structs and enums, even when there is no particular repr that the type guarantees to its users. This is a source of confusion for standard library users who assume the fact that a repr is documented means it must be something the standard library promises they can rely on (in transmutes, or FFI). Some issues on the topic of rustdoc's incorrect handling of `repr`: - rust-lang#66401 - rust-lang#90435 In places, the standard library currently works around this confusing rustdoc behavior by just omitting `repr(transparent)` altogether even where it should be required if equivalent code were being written outside of the standard library. See rust-lang#61969. IMO that is even more confusing, even for standard library maintainers — see rust-lang#105018 (comment). It's also not something that works for other reprs like `C` or `u8` which cannot just be omitted even in standard library code. This PR tries a different approach for some types that are being currently incorrectly documented with a repr. > **Warning** > This PR does not imply that every type that still has a `repr` attribute in its docs after this PR is now public for users to rely on. This PR only tries to reduce harm from this longstanding rustdoc issue.
2 parents 9239760 + e7963a6 commit 8d162fb

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

library/core/src/any.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ where
866866
///
867867
/// A data provider provides values by calling this type's provide methods.
868868
#[unstable(feature = "provide_any", issue = "96024")]
869-
#[repr(transparent)]
869+
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
870870
pub struct Demand<'a>(dyn Erased<'a> + 'a);
871871

872872
impl<'a> Demand<'a> {

library/core/src/ffi/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ mod c_long_definition {
203203
// be UB.
204204
#[doc = include_str!("c_void.md")]
205205
#[cfg_attr(not(bootstrap), lang = "c_void")]
206-
#[repr(u8)]
206+
#[cfg_attr(not(doc), repr(u8))] // work around https://github.com/rust-lang/rust/issues/90435
207207
#[stable(feature = "core_c_void", since = "1.30.0")]
208208
pub enum c_void {
209209
#[unstable(
@@ -244,7 +244,7 @@ impl fmt::Debug for c_void {
244244
target_os = "uefi",
245245
windows,
246246
))]
247-
#[repr(transparent)]
247+
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
248248
#[unstable(
249249
feature = "c_variadic",
250250
reason = "the `c_variadic` feature has not been properly tested on \
@@ -296,7 +296,7 @@ impl<'f> fmt::Debug for VaListImpl<'f> {
296296
not(target_os = "uefi"),
297297
not(windows),
298298
))]
299-
#[repr(C)]
299+
#[cfg_attr(not(doc), repr(C))] // work around https://github.com/rust-lang/rust/issues/66401
300300
#[derive(Debug)]
301301
#[unstable(
302302
feature = "c_variadic",
@@ -316,7 +316,7 @@ pub struct VaListImpl<'f> {
316316

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

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

356356
/// x86_64 ABI implementation of a `va_list`.
357357
#[cfg(all(target_arch = "x86_64", not(target_os = "uefi"), not(windows)))]
358-
#[repr(C)]
358+
#[cfg_attr(not(doc), repr(C))] // work around https://github.com/rust-lang/rust/issues/66401
359359
#[derive(Debug)]
360360
#[unstable(
361361
feature = "c_variadic",
@@ -373,7 +373,7 @@ pub struct VaListImpl<'f> {
373373
}
374374

375375
/// A wrapper for a `va_list`
376-
#[repr(transparent)]
376+
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
377377
#[derive(Debug)]
378378
#[unstable(
379379
feature = "c_variadic",

library/core/src/task/wake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl fmt::Debug for Context<'_> {
232232
///
233233
/// [`Future::poll()`]: core::future::Future::poll
234234
/// [`Poll::Pending`]: core::task::Poll::Pending
235-
#[repr(transparent)]
235+
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/66401
236236
#[stable(feature = "futures_api", since = "1.36.0")]
237237
pub struct Waker {
238238
waker: RawWaker,

library/portable-simd/crates/core_simd/src/masks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl_element! { isize }
8888
/// The layout of this type is unspecified, and may change between platforms
8989
/// and/or Rust versions, and code should not assume that it is equivalent to
9090
/// `[T; LANES]`.
91-
#[repr(transparent)]
91+
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
9292
pub struct Mask<T, const LANES: usize>(mask_impl::Mask<T, LANES>)
9393
where
9494
T: MaskElement,

0 commit comments

Comments
 (0)