Skip to content

Commit 3a50315

Browse files
authored
Rollup merge of rust-lang#125300 - compiler-errors:dont-strip-inherited-viz, r=fmease
rustdoc: Don't strip items with inherited visibility in `AliasedNonLocalStripper` Enum variants return `None` in `Item::visibility`, which fails the comparison to `Some(Visibility::Public)`. This means that all enums in type aliases are being stripped, leading to this in the `rustc_middle` docs: <img width="474" alt="image" src="https://github.com/rust-lang/rust/assets/3674314/83704d94-a571-4c28-acbd-ca51c4efd46e"> This regressed in rust-lang#124939 (comment). This switches the `AliasedNonLocalStripper` to not strip items with `None` as their visibility.
2 parents d1da238 + 090dbb1 commit 3a50315

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/librustdoc/passes/strip_aliased_non_local.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ impl<'tcx> DocFolder for NonLocalStripper<'tcx> {
4646
// the field and not the one given by the user for the currrent crate.
4747
//
4848
// FIXME(#125009): Not-local should probably consider same Cargo workspace
49-
if !i.def_id().map_or(true, |did| did.is_local()) {
50-
if i.visibility(self.tcx) != Some(Visibility::Public) || i.is_doc_hidden() {
49+
if let Some(def_id) = i.def_id()
50+
&& !def_id.is_local()
51+
{
52+
if i.is_doc_hidden()
53+
// Default to *not* stripping items with inherited visibility.
54+
|| i.visibility(self.tcx).map_or(false, |viz| viz != Visibility::Public)
55+
{
5156
return Some(strip_item(i));
5257
}
5358
}

tests/rustdoc/auxiliary/cross_crate_generic_typedef.rs

+5
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ pub struct InlineOne<A> {
33
}
44

55
pub type InlineU64 = InlineOne<u64>;
6+
7+
pub enum GenericEnum<T> {
8+
Variant(T),
9+
Variant2(T, T),
10+
}

tests/rustdoc/typedef-inner-variants.rs

+7
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,10 @@ pub type HighlyGenericAABB<A, B> = HighlyGenericStruct<A, A, B, B>;
117117
// @count - '//*[@id="variants"]' 0
118118
// @count - '//*[@id="fields"]' 1
119119
pub use cross_crate_generic_typedef::InlineU64;
120+
121+
// @has 'inner_variants/type.InlineEnum.html'
122+
// @count - '//*[@id="aliased-type"]' 1
123+
// @count - '//*[@id="variants"]' 1
124+
// @count - '//*[@id="fields"]' 0
125+
// @count - '//*[@class="variant"]' 2
126+
pub type InlineEnum = cross_crate_generic_typedef::GenericEnum<i32>;

0 commit comments

Comments
 (0)