about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-05-23 13:34:19 +0200
committerGitHub <noreply@github.com>2025-05-23 13:34:19 +0200
commit893494c90fe449ff223dae62149cd5fb1c03f957 (patch)
treebb4cf80d507ad47a9a76a00cff00f64bebac9c37
parentdfa3110ed4c40e0744a71cb3964c4161f3457ae2 (diff)
parent98bd1a6a3a56951b2fe676988d8cb005a6b752c5 (diff)
downloadrust-893494c90fe449ff223dae62149cd5fb1c03f957.tar.gz
rust-893494c90fe449ff223dae62149cd5fb1c03f957.zip
Rollup merge of #141126 - fmease:rev-rjson-priv-repr, r=aDotInTheVoid
rustdoc JSON: Don't apply `#[repr]` privacy heuristics

Split out from #116882.
Context: https://github.com/rust-lang/rust/pull/116882#issuecomment-2888349161.
Partially reverts #138018.

cc `@obi1kenobi`
r? aDotInTheVoid or rustdoc
-rw-r--r--src/librustdoc/clean/types.rs22
-rw-r--r--src/rustdoc-json-types/lib.rs2
-rw-r--r--tests/rustdoc-json/attrs/repr_combination.rs4
-rw-r--r--tests/rustdoc-json/attrs/repr_transparent.rs37
4 files changed, 12 insertions, 53 deletions
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index e45f28444fe..07ecd98f775 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -774,20 +774,11 @@ impl Item {
             .filter_map(|attr| {
                 if is_json {
                     match attr {
-                        hir::Attribute::Parsed(AttributeKind::Deprecation { .. }) => {
-                            // rustdoc-json stores this in `Item::deprecation`, so we
-                            // don't want it it `Item::attrs`.
-                            None
-                        }
-                        rustc_hir::Attribute::Parsed(
-                            rustc_attr_data_structures::AttributeKind::Repr(..),
-                        ) => {
-                            // We have separate pretty-printing logic for `#[repr(..)]` attributes.
-                            // For example, there are circumstances where `#[repr(transparent)]`
-                            // is applied but should not be publicly shown in rustdoc
-                            // because it isn't public API.
-                            None
-                        }
+                        // rustdoc-json stores this in `Item::deprecation`, so we
+                        // don't want it it `Item::attrs`.
+                        hir::Attribute::Parsed(AttributeKind::Deprecation { .. }) => None,
+                        // We have separate pretty-printing logic for `#[repr(..)]` attributes.
+                        hir::Attribute::Parsed(AttributeKind::Repr(..)) => None,
                         _ => Some({
                             let mut s = rustc_hir_pretty::attribute_to_string(&tcx, attr);
                             assert_eq!(s.pop(), Some('\n'));
@@ -820,7 +811,8 @@ impl Item {
             if repr.transparent() {
                 // Render `repr(transparent)` iff the non-1-ZST field is public or at least one
                 // field is public in case all fields are 1-ZST fields.
-                let render_transparent = cache.document_private
+                let render_transparent = is_json
+                    || cache.document_private
                     || adt
                         .all_fields()
                         .find(|field| {
diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs
index 0b8a9065294..c091c955ed5 100644
--- a/src/rustdoc-json-types/lib.rs
+++ b/src/rustdoc-json-types/lib.rs
@@ -30,7 +30,7 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
 /// This integer is incremented with every breaking change to the API,
 /// and is returned along with the JSON blob as [`Crate::format_version`].
 /// Consuming code should assert that this value matches the format version(s) that it supports.
-pub const FORMAT_VERSION: u32 = 45;
+pub const FORMAT_VERSION: u32 = 46;
 
 /// The root of the emitted JSON blob.
 ///
diff --git a/tests/rustdoc-json/attrs/repr_combination.rs b/tests/rustdoc-json/attrs/repr_combination.rs
index 0e8e2ef0d83..6fe29c5eac0 100644
--- a/tests/rustdoc-json/attrs/repr_combination.rs
+++ b/tests/rustdoc-json/attrs/repr_combination.rs
@@ -77,3 +77,7 @@ pub enum AlignedExplicitRepr {
 pub enum ReorderedAlignedExplicitRepr {
     First,
 }
+
+//@ is "$.index[?(@.name=='Transparent')].attrs" '["#[repr(transparent)]"]'
+#[repr(transparent)]
+pub struct Transparent(i64);
diff --git a/tests/rustdoc-json/attrs/repr_transparent.rs b/tests/rustdoc-json/attrs/repr_transparent.rs
deleted file mode 100644
index 1e634ca901d..00000000000
--- a/tests/rustdoc-json/attrs/repr_transparent.rs
+++ /dev/null
@@ -1,37 +0,0 @@
-#![no_std]
-
-// Rustdoc JSON *only* includes `#[repr(transparent)]`
-// if the transparency is public API:
-// - if a non-1-ZST field exists, it has to be public
-// - otherwise, all fields are 1-ZST and at least one of them is public
-//
-// More info: https://doc.rust-lang.org/nomicon/other-reprs.html#reprtransparent
-
-// Here, the non-1-ZST field is public.
-// We expect `#[repr(transparent)]` in the attributes.
-//
-//@ is "$.index[?(@.name=='Transparent')].attrs" '["#[repr(transparent)]"]'
-#[repr(transparent)]
-pub struct Transparent(pub i64);
-
-// Here the non-1-ZST field isn't public, so the attribute isn't included.
-//
-//@ has "$.index[?(@.name=='TransparentNonPub')]"
-//@ is "$.index[?(@.name=='TransparentNonPub')].attrs" '[]'
-#[repr(transparent)]
-pub struct TransparentNonPub(i64);
-
-// Only 1-ZST fields here, and one of them is public.
-// We expect `#[repr(transparent)]` in the attributes.
-//
-//@ is "$.index[?(@.name=='AllZst')].attrs" '["#[repr(transparent)]"]'
-#[repr(transparent)]
-pub struct AllZst<'a>(pub core::marker::PhantomData<&'a ()>, ());
-
-// Only 1-ZST fields here but none of them are public.
-// The attribute isn't included.
-//
-//@ has "$.index[?(@.name=='AllZstNotPublic')]"
-//@ is "$.index[?(@.name=='AllZstNotPublic')].attrs" '[]'
-#[repr(transparent)]
-pub struct AllZstNotPublic<'a>(core::marker::PhantomData<&'a ()>, ());