rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.56k stars 12.74k forks source link

[CODE IMPROVEMENT] handle `doc(hidden)` differently in rustdoc #129415

Open GuillaumeGomez opened 2 months ago

GuillaumeGomez commented 2 months ago

Currently, the handle of doc(hidden) in rustdoc is very complex and needs to go through multiple strip passes which are all very fine-tuned, making the whole very fragile and difficult to keep up with.

Instead of these passes, we could instead check whether or not an item is doc hidden directly when rendering them. With a top-down approach, if an item is doc(hidden), none of its children will be rendered either.

Gonna give it a try in the few weeks to see how much of it is actually doable.

fmease commented 2 months ago

when rendering them

Doesn't this imply doc(hidden) items will then show up in Rustdoc JSON?

I agree however that we should handle doc(hidden) "in the same pass" if possible (rn iirc, we strip some when ... stripping (in the visitor) and strip some elsewhere like trait assoc items (namely in collect_trait_impls)).

Btw, if we stripped doc(hidden) items before cleaning the HIR and middle::ty that may lead to a perf gain and mem decrease.

GuillaumeGomez commented 2 months ago

The same logic can be applied to rustdoc JSON I suppose.

Btw, if we stripped doc(hidden) items before cleaning the HIR and middle::ty that may lead to a perf gain and mem decrease.

Indeed, but we can't do that because of reexports. :3

GuillaumeGomez commented 2 months ago

Now that I think about it, I think it's fine to strip items when we convert them into clean: if it's a reexport, nothing prevents us from inlining if needed since we still have the reexported item DefId.