Skip to content

Commit 98bd1a6

Browse files
committed
rustdoc JSON: Don't apply #[repr] privacy heuristics
1 parent e3892a4 commit 98bd1a6

File tree

4 files changed

+12
-53
lines changed

4 files changed

+12
-53
lines changed

src/librustdoc/clean/types.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -774,20 +774,11 @@ impl Item {
774774
.filter_map(|attr| {
775775
if is_json {
776776
match attr {
777-
hir::Attribute::Parsed(AttributeKind::Deprecation { .. }) => {
778-
// rustdoc-json stores this in `Item::deprecation`, so we
779-
// don't want it it `Item::attrs`.
780-
None
781-
}
782-
rustc_hir::Attribute::Parsed(
783-
rustc_attr_data_structures::AttributeKind::Repr(..),
784-
) => {
785-
// We have separate pretty-printing logic for `#[repr(..)]` attributes.
786-
// For example, there are circumstances where `#[repr(transparent)]`
787-
// is applied but should not be publicly shown in rustdoc
788-
// because it isn't public API.
789-
None
790-
}
777+
// rustdoc-json stores this in `Item::deprecation`, so we
778+
// don't want it it `Item::attrs`.
779+
hir::Attribute::Parsed(AttributeKind::Deprecation { .. }) => None,
780+
// We have separate pretty-printing logic for `#[repr(..)]` attributes.
781+
hir::Attribute::Parsed(AttributeKind::Repr(..)) => None,
791782
_ => Some({
792783
let mut s = rustc_hir_pretty::attribute_to_string(&tcx, attr);
793784
assert_eq!(s.pop(), Some('\n'));
@@ -820,7 +811,8 @@ impl Item {
820811
if repr.transparent() {
821812
// Render `repr(transparent)` iff the non-1-ZST field is public or at least one
822813
// field is public in case all fields are 1-ZST fields.
823-
let render_transparent = cache.document_private
814+
let render_transparent = is_json
815+
|| cache.document_private
824816
|| adt
825817
.all_fields()
826818
.find(|field| {

src/rustdoc-json-types/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
3030
/// This integer is incremented with every breaking change to the API,
3131
/// and is returned along with the JSON blob as [`Crate::format_version`].
3232
/// Consuming code should assert that this value matches the format version(s) that it supports.
33-
pub const FORMAT_VERSION: u32 = 45;
33+
pub const FORMAT_VERSION: u32 = 46;
3434

3535
/// The root of the emitted JSON blob.
3636
///

tests/rustdoc-json/attrs/repr_combination.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,7 @@ pub enum AlignedExplicitRepr {
7777
pub enum ReorderedAlignedExplicitRepr {
7878
First,
7979
}
80+
81+
//@ is "$.index[?(@.name=='Transparent')].attrs" '["#[repr(transparent)]"]'
82+
#[repr(transparent)]
83+
pub struct Transparent(i64);

tests/rustdoc-json/attrs/repr_transparent.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)