rustdoc: Correctly handle reexports when --document-private-items is used - #161362
rustdoc: Correctly handle reexports when --document-private-items is used#161362GuillaumeGomez wants to merge 2 commits into
Conversation
| //@ hasraw - "Mod1Public" | ||
| //@ !hasraw - "Mod1Private" | ||
| //@ !hasraw - "mod2" | ||
| //@ hasraw - "Mod1Private" |
There was a problem hiding this comment.
Fun fact: this test was added in 2016 in #37773. :)
This comment has been minimized.
This comment has been minimized.
bdb8873 to
9baaae5
Compare
This comment has been minimized.
This comment has been minimized.
9baaae5 to
7d595c2
Compare
| // a `pub(...)` part with its `vis_span` field. | ||
| let is_pub = tcx.visibility(def_id).is_public() | ||
| || (self.cx.document_private() | ||
| && (!matches!(item.kind, hir::ItemKind::Use(..)) || !item.vis_span.is_empty())); |
There was a problem hiding this comment.
I don't like this hack. I think we would be better of checking if the visibility of the use item is different from where the use item is defined.
I'm thinking of something like this:
let parent_module = tcx.parent_module_from_def_id(def_id);
let is_exported = tcx.visibility(def_id) != Visibility::Restricted(parent_module.to_mod_id());
// or maybe call Visibility::greater_thanThere was a problem hiding this comment.
That's... strange. With this code:
pub(crate) mod foo {
pub(crate) use self::x::Y;
#[doc(hidden)]
mod x {
struct Y;
}
}It means we would not see Y. I think the only thing we want to care about is whether it's a reexport or not. And the only way to see that is if there is a pub(), which we know with vis_span. Not a trick imo.
There was a problem hiding this comment.
It means we would not see
Y
I think we would, parent_module should be mod foo and tcx.visibility(def_id) should be CRATE_DEF_ID and those do not match, implying that there is a pub(...) token. It's possible my logic is wrong and should be adjusted, but I think something like that should work.
And the only way to see that is if there is a
pub(), which we know withvis_span. Not a trick imo.
Spans can be arbitrarily manipulated by proc-macros, a proc-macro could assign a empty span to the pub(...) tokens and your check would be bypassed. We should never rely on spans for correctness.
There was a problem hiding this comment.
Fair point. I'll test locally and we'll see if use without visibility are correctly handled.
|
I was wondering if this was a breaking change, but our documentation clearly states:
as such, this seems clearly like a bug fix. |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
Fixes #159109.
This PR makes the (private) reexport work like the public ones when the
--document-private-itemsoption is used. I still differentiate between imports (use) and reexports (pub(...) use) in this PR as I don't think we should display imports.r? @Urgau