Skip to content

Re-exports of hidden items are inconsistent #137342

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
lolbinarycat opened this issue Feb 20, 2025 · 25 comments
Open

Re-exports of hidden items are inconsistent #137342

lolbinarycat opened this issue Feb 20, 2025 · 25 comments
Assignees
Labels
C-bug Category: This is a bug. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@lolbinarycat
Copy link
Contributor

lolbinarycat commented Feb 20, 2025

example

If an item in a hidden module is reexported, it will be automatically inlined, but if the item itself is hidden (and in a non-hidden module), it will show as a regular reexport, with a link to a normally hidden page.

This also makes the item not show in the "all items" list, despite being publicly reachable.

@lolbinarycat lolbinarycat added C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 20, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 20, 2025
@xizheyin
Copy link
Contributor

Has anyone started this issue already? Maybe I could try it. @lolbinarycat

@lolbinarycat
Copy link
Contributor Author

@xizheyin do you have any experience working on rustdoc? this is not a trivial issue.

@lolbinarycat lolbinarycat added the E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. label Feb 22, 2025
@xizheyin
Copy link
Contributor

I have previously used librustdoc to create a small tool,but I only utilized a part of theclean/module. I took a look at the rest of librustdoc's code and got a general understanding of its structure.I'm not sure if I underestimated the difficulty.

@lolbinarycat
Copy link
Contributor Author

I imagine it's an issue with the pass that removes doc(hidden) items. It might require a bit of refactoring to solve this issue in a performant way.

@xizheyin
Copy link
Contributor

Ok, I'll take a deeper look. If the bug isn't particularly urgent.

@xizheyin
Copy link
Contributor

@rustbot claim

@xizheyin
Copy link
Contributor

xizheyin commented Feb 24, 2025

I have tried to inline hidden_self_reexport as the discussion. Is that right? @lolbinarycat

Update:
It conflicts with the existing logic. What would be a better solution to this issue? Hide them all?

@lolbinarycat
Copy link
Contributor Author

@xizheyin i don't have the final say on what the "right" way to fix it is, but if it was up to me, all 4 functions would be inlined.

figuring out how to do this efficiently without introducing new bugs is the hard part.

@xizheyin
Copy link
Contributor

@xizheyin i don't have the final say on what the "right" way to fix it is, but if it was up to me, all 4 functions would be inlined.

yeah,that is what i have done. But it may conflict with the existing testcase.

@lolbinarycat
Copy link
Contributor Author

@xizheyin if you look inside the testcase that's failing, you'll see it link to issue #109449

if you follow the links from that issue, you'll find pr #112304

that pr contains a section explaining what the intended behavior is. from my reading it seems to indicate that hidden_self_reexport should actually be hidden, while the others are visible. it may be worth waiting to see what t-rustdoc thinks.

@lolbinarycat
Copy link
Contributor Author

@GuillaumeGomez is my understanding of the intended behavior here correct? is this a regression?

@GuillaumeGomez
Copy link
Member

The rules are described here.

In particular:

If an item has #[doc(hidden)], it won't be inlined (nor visible in the generated documentation):

@xizheyin
Copy link
Contributor

So hidden_self_reexport shouldn't be visible?

@lolbinarycat
Copy link
Contributor Author

@GuillaumeGomez please look at the linked example. hidden_self_reexport actually contains a link to hidden_self_reexport_inline. This defiantly seems like a bug, but I'm not sure what the intended behavior actually is.

@GuillaumeGomez
Copy link
Member

Hum I think it's a case that we didn't check. The docs say it's not supposed to be visible, even with doc(inline). So if it's visible, then it's definitely a bug.

So yes, hidden_self_reexport shouldn't be visible.

@xizheyin
Copy link
Contributor

OK, let me try to fix it.

@lolbinarycat
Copy link
Contributor Author

@GuillaumeGomez Wait, hidden items shouldn't be visible, even when explicitly inlined? This isn't entirly clear from reading the docs, but I guess that's what's meant by "(because the re-export itself and its attributes are ignored)".

If that's the case, then shouldn't hidden_self_reexport_inline also be hidden?

@GuillaumeGomez
Copy link
Member

Hum, the reexport itself is not doc hidden. So I'd tend to say yes but unclear.

@lolbinarycat
Copy link
Contributor Author

Sounds like the docs also need some clarification.

@GuillaumeGomez
Copy link
Member

Both are welcome.

@xizheyin
Copy link
Contributor

After I finish the code, and test it the outputs is

failures:
    [rustdoc] tests/rustdoc/attributes-inlining-108281.rs
    [rustdoc] tests/rustdoc/file-creation-111249.rs
    [rustdoc] tests/rustdoc/inline-private-with-intermediate-doc-hidden.rs
    [rustdoc] tests/rustdoc/reexport-attr-merge.rs
    [rustdoc] tests/rustdoc/reexport-doc-hidden-inside-private.rs
    [rustdoc] tests/rustdoc/reexport-doc-hidden.rs
    [rustdoc] tests/rustdoc/reexport-trait-from-hidden-111064-2.rs
    [rustdoc] tests/rustdoc/reexport-hidden-macro.rs
    [rustdoc] tests/rustdoc/reexport-of-doc-hidden.rs
    [rustdoc] tests/rustdoc/redirect.rs

test result: FAILED. 723 passed; 10 failed; 4 ignored; 0 measured; 0 filtered out; finished in 25.91s

10 previous testcases failed. Here is an example:

// Regression test for <https://github.com/rust-lang/rust/issues/108281>.
// It ensures that the attributes on the first reexport are not duplicated.

#![crate_name = "foo"]

//@ has 'foo/index.html'

#[doc(hidden)]
pub fn bar() {}
mod sub {
    pub fn public() {}
}

//@ matches - '//dd' '^Displayed$'
/// Displayed
#[doc(inline)]
pub use crate::bar as Bar;
//@ matches - '//dd' '^Hello\sDisplayed$'
#[doc(inline)]
/// Hello
pub use crate::Bar as Bar2;

//@ matches - '//dd' '^Public$'
/// Public
pub use crate::sub::public as Public;

By the logic we discussed, pub use crate::bar as Bar; shouldn't be displayed. So do I need to modify these testcases?
@GuillaumeGomez @lolbinarycat

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented Feb 27, 2025

Seems like the logic is that doc(inline) allows doc(hidden) items. What a mess. Well, if it's the current behaviour we're supposed to keep it. Gonna send a PR to update the rustdoc book.

So back to your example, what's weird is that if you have a reexport of a reexport of a hidden item, it's inlined whereas it shouldn't.

@xizheyin
Copy link
Contributor

I have two modification logics

  1. hide an item that is not marked as doc(inline) and whose import source is doc(hidden), i.e. hidden_self_reexport
  2. hide an item that is marked as doc(inline) but the source is doc(hidden), i.e. hidden_self_reexport_inline

When I use both logic 1 and 2, 10 testcases failed; when I use only logic 1, only 5 testcases failed.
Which logic should I use? Should I just use logic 1? @GuillaumeGomez

@xizheyin
Copy link
Contributor

When I use only logic 1, it failed the testcases as below:

#[macro_export]
#[doc(hidden)]
macro_rules! foo {
    () => {};
}

//@ has 'foo/index.html'
//@ has - '//*[@id="reexport.Macro"]/code' 'pub use crate::foo as Macro;'
pub use crate::foo as Macro;
//@ has - '//*[@id="reexport.Macro2"]/code' 'pub use crate::foo as Macro2;'
pub use crate::foo as Macro2;
//@ has - '//*[@id="reexport.Boo"]/code' 'pub use crate::Bar as Boo;'
pub use crate::Bar as Boo;
//@ has - '//*[@id="reexport.Boo2"]/code' 'pub use crate::Bar as Boo2;'
pub use crate::Bar as Boo2;

@GuillaumeGomez
Copy link
Member

It should be 1 normally. If you use doc(inline) on doc(hidden), you should still have pub use X as Y.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 1, 2025
…iddle

Add missing case explanation for doc inlined re-export of doc hidden item

This case was not covered in the rustdoc book as uncovered in rust-lang#137342.

r? `@notriddle`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 1, 2025
…iddle

Add missing case explanation for doc inlined re-export of doc hidden item

This case was not covered in the rustdoc book as uncovered in rust-lang#137342.

r? ``@notriddle``
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 1, 2025
Rollup merge of rust-lang#137719 - GuillaumeGomez:missing-doc, r=notriddle

Add missing case explanation for doc inlined re-export of doc hidden item

This case was not covered in the rustdoc book as uncovered in rust-lang#137342.

r? ``@notriddle``
@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 1, 2025
jhpratt added a commit to jhpratt/rust that referenced this issue Mar 4, 2025
tgross35 added a commit to tgross35/rust that referenced this issue Mar 4, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Mar 4, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Mar 5, 2025
jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 5, 2025
jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 5, 2025
jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 5, 2025
compiler-errors added a commit to compiler-errors/rust that referenced this issue Mar 6, 2025
Noratrieb added a commit to Noratrieb/rust that referenced this issue Mar 6, 2025
compiler-errors added a commit to compiler-errors/rust that referenced this issue Mar 6, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 7, 2025
Rollup merge of rust-lang#137534 - xizheyin:issue-137342, r=GuillaumeGomez

[rustdoc] hide item that is not marked as doc(inline) and whose src is doc(hidden)

Part of rust-lang#137342

![image](https://github.com/user-attachments/assets/68b4649a-a64a-43b2-8a73-6ac92b486e9e)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants