mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
rustdoc JSON: Don't apply #[repr] privacy heuristics
This commit is contained in:
@@ -774,20 +774,11 @@ pub(crate) fn attributes(&self, tcx: TyCtxt<'_>, cache: &Cache, is_json: bool) -
|
||||
.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 @@ pub(crate) fn attributes(&self, tcx: TyCtxt<'_>, cache: &Cache, is_json: bool) -
|
||||
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| {
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
/// 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.
|
||||
///
|
||||
|
||||
@@ -77,3 +77,7 @@ pub enum AlignedExplicitRepr {
|
||||
pub enum ReorderedAlignedExplicitRepr {
|
||||
First,
|
||||
}
|
||||
|
||||
//@ is "$.index[?(@.name=='Transparent')].attrs" '["#[repr(transparent)]"]'
|
||||
#[repr(transparent)]
|
||||
pub struct Transparent(i64);
|
||||
|
||||
@@ -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 ()>, ());
|
||||
Reference in New Issue
Block a user