From 185483794ec496b7a46d0c0c5e5a059a47caa8c4 Mon Sep 17 00:00:00 2001 From: Jamie Hill-Daniel Date: Sat, 10 Jan 2026 15:46:12 +0000 Subject: [PATCH] rustdoc: Always document `#[repr(transparent)]` if `#[rustc_pub_transparent]` is applied MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: León Orell Valerian Liehr --- src/librustdoc/html/render/mod.rs | 10 ++++++++-- tests/rustdoc-html/repr.rs | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 152a61beef405..eddf3e4873039 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -3083,10 +3083,16 @@ fn repr_attribute<'tcx>( (cache.document_private || field.vis.is_public()) && is_visible(field.did) }; + // The transparent repr is public if + // - the non-1-ZST field is public and visible or + // - at least one field is public and visible if *all* fields are 1-ZSTs or + // - the item is annotated with internal attribute `#[rustc_pub_transparent]` if repr.transparent() { - // The transparent repr is public iff the non-1-ZST field is public and visible or - // – in case all fields are 1-ZST fields — at least one field is public and visible. let is_public = 'is_public: { + if hir::find_attr!(tcx, def_id, AttributeKind::RustcPubTransparent(_)) { + break 'is_public true; + } + // `#[repr(transparent)]` can only be applied to structs and single-variant enums. let var = adt.variant(rustc_abi::FIRST_VARIANT); // the first and only variant diff --git a/tests/rustdoc-html/repr.rs b/tests/rustdoc-html/repr.rs index 1e8fad6ec0a66..6e80abb855d7f 100644 --- a/tests/rustdoc-html/repr.rs +++ b/tests/rustdoc-html/repr.rs @@ -1,5 +1,6 @@ // Test the rendering of `#[repr]` on ADTs. #![feature(repr_simd)] // only used for the `ReprSimd` test case +#![feature(rustc_attrs)] // only used for the `RustcPubTransparent` test case // Check the "local case" (HIR cleaning) // @@ -147,6 +148,16 @@ pub enum ReprTransparentEnumHidden1ZstField { }, } +// Regression test for . +//@ has 'repr/struct.RustcPubTransparent.html' +//@ has - '//*[@class="rust item-decl"]//*[@class="code-attribute"]' '#[repr(transparent)]' +#[repr(transparent)] // public... +#[rustc_pub_transparent] // ...since this attribute was applied +pub struct RustcPubTransparent { + // ...despite this field being private + field: u64, +} + struct Marker; // 1-ZST // Check the "extern case" (middle cleaning) //