Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Correctly handle associated items of a trait inside a #[doc(hidden)] item #111095

Merged

Conversation

GuillaumeGomez
Copy link
Member

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels May 2, 2023
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the fix-assoc-item-trait-inside-hidden branch from f541f34 to 6998692 Compare May 2, 2023 12:45
@GuillaumeGomez
Copy link
Member Author

Fixed fmt issue.

@notriddle
Copy link
Contributor

notriddle commented May 2, 2023

I don't think this entirely fixes the problem.

It fixes the case where you specifically inline a trait from a hidden module, but these two test cases both fail:

Test case for inlining a module that inherits hiddenness
#![crate_name = "foo"]

// @!has 'foo/hidden/index.html'
// @!has 'foo/hidden/inner/index.html'
// @!has 'foo/hidden/inner/trait.Foo.html'
#[doc(hidden)]
pub mod hidden {
    pub mod inner {
        pub trait Foo {
            /// Hello, world!
            fn test();
        }
    }
}

// @has 'foo/visible/index.html'
// @has 'foo/visible/trait.Foo.html'
#[doc(inline)]
pub use hidden::inner as visible;

// @has 'foo/struct.Bar.html'
// @count - '//*[@id="impl-Foo-for-Bar"]' 1
pub struct Bar;

impl visible::Foo for Bar {
    fn test() {}
}
Test case for inlining an item that's two levels deep
#![crate_name = "foo"]

// @!has 'foo/hidden/index.html'
// @!has 'foo/hidden/inner/index.html'
// @!has 'foo/hidden/inner/trait.Foo.html'
#[doc(hidden)]
pub mod hidden {
    pub mod inner {
        pub trait Foo {
            /// Hello, world!
            fn test();
        }
    }
}

// @has 'foo/trait.Foo.html'
#[doc(inline)]
pub use hidden::inner::Foo;

// @has 'foo/struct.Bar.html'
// @count - '//*[@id="impl-Foo-for-Bar"]' 1
pub struct Bar;

impl Foo for Bar {
    fn test() {}
}

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented May 3, 2023

@notriddle In the two tests you provided, you're underlining a limitation of this fix (which is great!) and another existing bug. I don't think they have the same origin though but I'll try to fix both here as well. After a lot of investigations, I'm still wondering whether or not we should store all reexports and then when we encounter an item that is inside a #[doc(hidden)] path and is re-exported, to check how it is re-exported. I'm still trying to find another way though because that'd be quite bad performance-wise...

@GuillaumeGomez GuillaumeGomez force-pushed the fix-assoc-item-trait-inside-hidden branch from 6998692 to f664bb9 Compare May 5, 2023 13:34
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the fix-assoc-item-trait-inside-hidden branch from f664bb9 to c9faa4b Compare May 5, 2023 14:00
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the fix-assoc-item-trait-inside-hidden branch from c9faa4b to ac85277 Compare May 5, 2023 16:02
@GuillaumeGomez
Copy link
Member Author

@notriddle The first failing test you gave actually allowed me to uncover another bug: reexported modules were not handled in rustdoc. So that's two bugs fixed with this PR.

For the extra files created, since the bug already exists, I'll fix it in a follow-up PR. I opened the issue for it here: #111249

Copy link
Contributor

@notriddle notriddle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems better.

inherits_doc_hidden's stop_at parameter seems like a more complete fix. #[doc(hidden)] is recursively applied, so it makes sense that a bug fix for it should impact the way the recursion is done and not just check one level. Thank you!

I have nits, but the approach seems sound.

src/librustdoc/passes/strip_hidden.rs Outdated Show resolved Hide resolved
src/librustdoc/passes/strip_hidden.rs Outdated Show resolved Hide resolved
local_def_id: LocalDefId,
name: Symbol,
import_id: Option<LocalDefId>,
renamed: Option<Symbol>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are name and renamed both needed? It seems like name is completely ignored if renamed is Some.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered if I should pass the "computed" name or if I should do it in the function. In the end I picked this approach because it's not possible to pass the "non-computed" name since you need to pass both name and renamed.

@GuillaumeGomez GuillaumeGomez force-pushed the fix-assoc-item-trait-inside-hidden branch from ac85277 to 8de4308 Compare May 5, 2023 19:33
@GuillaumeGomez
Copy link
Member Author

Updated!

@notriddle
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 9, 2023

📌 Commit 8de4308 has been approved by notriddle

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 9, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request May 10, 2023
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#110673 (Make alias bounds sound in the new solver (take 2))
 - rust-lang#110747 (Encode types in SMIR)
 - rust-lang#111095 (Correctly handle associated items of a trait inside a `#[doc(hidden)]` item)
 - rust-lang#111381 (Keep encoding attributes for closures)
 - rust-lang#111408 (Fix incorrect implication of transmuting slices)
 - rust-lang#111410 (Switch to `EarlyBinder` for `thir_abstract_const` query)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d117b41 into rust-lang:master May 10, 2023
@rustbot rustbot added this to the 1.71.0 milestone May 10, 2023
@GuillaumeGomez GuillaumeGomez deleted the fix-assoc-item-trait-inside-hidden branch May 10, 2023 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustdoc: Missing method signatures in trait docs
5 participants