Skip to content

Commit

Permalink
Rollup merge of rust-lang#125300 - compiler-errors:dont-strip-inherit…
Browse files Browse the repository at this point in the history
…ed-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.
  • Loading branch information
matthiaskrgr authored May 20, 2024
2 parents d1da238 + 090dbb1 commit 3a50315
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/librustdoc/passes/strip_aliased_non_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/rustdoc/auxiliary/cross_crate_generic_typedef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ pub struct InlineOne<A> {
}

pub type InlineU64 = InlineOne<u64>;

pub enum GenericEnum<T> {
Variant(T),
Variant2(T, T),
}
7 changes: 7 additions & 0 deletions tests/rustdoc/typedef-inner-variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,10 @@ pub type HighlyGenericAABB<A, B> = HighlyGenericStruct<A, A, B, B>;
// @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<i32>;

0 comments on commit 3a50315

Please sign in to comment.