From dbfed2c43ec0ceb6c8215786917fc49af5cf511c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 19 May 2024 20:12:37 -0400 Subject: [PATCH 1/2] Add failing test for cross-crate enum in type alias --- tests/rustdoc/auxiliary/cross_crate_generic_typedef.rs | 5 +++++ tests/rustdoc/typedef-inner-variants.rs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/tests/rustdoc/auxiliary/cross_crate_generic_typedef.rs b/tests/rustdoc/auxiliary/cross_crate_generic_typedef.rs index f4e020b3b9599..d85129a69fc6e 100644 --- a/tests/rustdoc/auxiliary/cross_crate_generic_typedef.rs +++ b/tests/rustdoc/auxiliary/cross_crate_generic_typedef.rs @@ -3,3 +3,8 @@ pub struct InlineOne { } pub type InlineU64 = InlineOne; + +pub enum GenericEnum { + Variant(T), + Variant2(T, T), +} diff --git a/tests/rustdoc/typedef-inner-variants.rs b/tests/rustdoc/typedef-inner-variants.rs index d87a1cb6facbf..0e65fdaf2afdc 100644 --- a/tests/rustdoc/typedef-inner-variants.rs +++ b/tests/rustdoc/typedef-inner-variants.rs @@ -117,3 +117,10 @@ pub type HighlyGenericAABB = HighlyGenericStruct; // @count - '//*[@id="variants"]' 0 // @count - '//*[@id="fields"]' 1 pub use cross_crate_generic_typedef::InlineU64; + +// @has 'inner_variants/type.InlineEnum.html' +// @count - '//*[@id="aliased-type"]' 1 +// @count - '//*[@id="variants"]' 1 +// @count - '//*[@id="fields"]' 0 +// @count - '//*[@class="variant"]' 2 +pub type InlineEnum = cross_crate_generic_typedef::GenericEnum; From 090dbb12f90a3d22183a7250ccad080a8e6d706c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 19 May 2024 20:12:56 -0400 Subject: [PATCH 2/2] Don't strip items with inherited visibility in AliasedNonLocalStripper --- src/librustdoc/passes/strip_aliased_non_local.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/passes/strip_aliased_non_local.rs b/src/librustdoc/passes/strip_aliased_non_local.rs index 848cbd5ed99fc..ac7d422ec800f 100644 --- a/src/librustdoc/passes/strip_aliased_non_local.rs +++ b/src/librustdoc/passes/strip_aliased_non_local.rs @@ -46,8 +46,13 @@ impl<'tcx> DocFolder for NonLocalStripper<'tcx> { // the field and not the one given by the user for the currrent crate. // // FIXME(#125009): Not-local should probably consider same Cargo workspace - if !i.def_id().map_or(true, |did| did.is_local()) { - if i.visibility(self.tcx) != Some(Visibility::Public) || i.is_doc_hidden() { + if let Some(def_id) = i.def_id() + && !def_id.is_local() + { + if i.is_doc_hidden() + // Default to *not* stripping items with inherited visibility. + || i.visibility(self.tcx).map_or(false, |viz| viz != Visibility::Public) + { return Some(strip_item(i)); } }