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

rustdoc: do something about reexported items #15723

Open
SimonSapin opened this issue Jul 16, 2014 · 10 comments
Open

rustdoc: do something about reexported items #15723

SimonSapin opened this issue Jul 16, 2014 · 10 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@SimonSapin
Copy link
Contributor

Update: This issue was first filed with the title "rustdoc shouldn’t document reexports separately", but that might not be the desired solution.


For example, the StrSlice trait is currently documented in three different places:

http://doc.rust-lang.org/std/str/trait.StrSlice.html
http://doc.rust-lang.org/collections/str/trait.StrSlice.html
http://doc.rust-lang.org/core/str/trait.StrSlice.html

It really is the same trait, but in the documentation they appear as distinct.

I think that, when module A contains a pub use B::C; statement:

  • rustdoc should not create a new documentation page for A::C
  • Instead, the documentation for A should link to the original documentation for B::C
  • In addition, the documentation for B::C should list all the known name it is re-exported as (in this case A::C).

It gets more complicated when A and B are not in the same source repository, but IMO still worth pursuing. Sphinx does support cross-references to other repos.

@alexcrichton
Copy link
Member

It was a very explicit design decision, and there is quite a lot of support, to inline documentation across crates, creating new pages. The whole point of the std facade was to make it exactly appear as if there were no facade, requiring inlining of documentation.

That being said, it could be the case that rustdoc could do a better job of presenting that information, which is what I believe this bug should be about rather than preventing inlining.

@SimonSapin
Copy link
Contributor Author

Ok, maybe the solution is not the one I suggested, but I hope you agree there is an issue when, for example, a search gives three times as many results as there really are distinct items:

http://doc.rust-lang.org/std/?search=char_at

Results for char_at

std::str::StrSlice::char_at Plucks the character starting at the ith byte of a string.
std::str::StrSlice::char_at_reverse Plucks the character ending at the ith byte of a string.
collections::str::StrSlice::char_at Plucks the character starting at the ith byte of a string.
core::str::StrSlice::char_at Plucks the character starting at the ith byte of a string.
collections::str::StrSlice::char_at_reverse Plucks the character ending at the ith byte of a string.
core::str::StrSlice::char_at_reverse Plucks the character ending at the ith byte of a string.

Perhaps libstd is a special case, and another approach would be to not document at all on http://doc.rust-lang.org/ crates that are entirely re-exported through libstd?

@SimonSapin SimonSapin changed the title rustdoc shouldn’t document reexports separately rustdoc: do something about exexported items Jul 17, 2014
@alexcrichton
Copy link
Member

I do indeed think this is a problem, but it's a problem that can be solved in the frontend without compromising documentation as a whole.

@tomjakubowski
Copy link
Contributor

The problem is with the redundant results in the search index. Maybe re-exported items in the search index could indicate the path of the original item, which would then (optionally?) be hidden from search results?

@SimonSapin SimonSapin changed the title rustdoc: do something about exexported items rustdoc: do something about reexported items Jul 29, 2014
@ben0x539
Copy link
Contributor

ben0x539 commented Sep 5, 2014

  • In addition, the documentation for B::C should list all the known name it is re-exported as (in this case A::C).

imo we really want something like this at least for cases where some item is defined in libname::some::hierarchy::of::internal::modules::foo and then re-exported as libname::foo. afaict, search only turns up the former while I'd assume that I'm really expected to use the latter.

@steveklabnik
Copy link
Member

Triage: no change, this is still an issue.

@steveklabnik
Copy link
Member

Triage: same as last year, no changes.

@steveklabnik steveklabnik added T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. and removed T-tools labels May 18, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 21, 2017
@steveklabnik
Copy link
Member

Triage: still no change. @rust-lang/rustdoc do we plan on doing anything here?

@SimonSapin
Copy link
Contributor Author

We now have #[doc(inline)] and #[doc(no_inline)] to control this, so I suppose this issue should be about reviewing how these attributes are used and should be used in the standard library.

@QuietMisdreavus
Copy link
Member

In addition, the documentation for B::C should list all the known name it is re-exported as (in this case A::C).

As you mentioned in the OP, this gets complicated across crates, but we do have precedent for adding things to a dependency's documentation: trait implementors. If two crates are documented into the same output directory, trait implementations between those two crates will fill a JavaScript file that is dynamically loaded by the parent trait to list implementations in "downstream" crates. This does only work for crates in the same "doc bundle" (my term for "crates documented at the same time into the same target directory), but for situations like the std facade (or other facade patterns if they don't defer documentation to docs.rs) it can work out.

There was another issue mentioned in the thread about the duplicate re-exports showing up in the search index. That is also a problem of the crates being documented into the same "doc bundle", since each will fill the search index independently. However, there is currently an open PR (#54706) that allows users to restrict their searches to a specific crate, which may help cut down somewhat. In addition, i believe that results from the same crate you're currently looking at are prioritized above other crates' results now, so patterns like the std facade will show the "proper" item first if you're starting from std. However, this doesn't prevent duplicates from the same crate showing up, which would still be a problem.

I'm open to allowing a way to tell rustdoc that a certain location is the "canonical" one, for the purposes of inlining, or for showing the path when an item is referenced, or the like. I'm not super sure how to deal with cross-crate re-exports in that case, but it will help the situation where an item is defined into a private module, then exported from two public ones (say, a prelude and the "real" location that it should be referenced from).

@ehuss ehuss removed the T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. label Jan 18, 2022
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 13, 2024
…r=<try>

rustdoc-search: single result for items with multiple paths

Part of rust-lang#15723

Preview: https://notriddle.com/rustdoc-html-demo-9/reexport-dup/std/index.html?search=hashmap

This change uses the same "exact" paths as trait implementors and type alias inlining to track items with multiple reachable paths. This way, if you search for `vec`, you get only the `std` exports of it, and not the one from `alloc`.

It still includes all the items in the search index so that you can search for them by all available paths. For example, try `core::option` and `std::option`, and notice that the results page doesn't show duplicates, but still shows all the items in their respective crates.
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 18, 2024
…r=GuillaumeGomez

rustdoc-search: single result for items with multiple paths

Part of rust-lang#15723

Preview: https://notriddle.com/rustdoc-html-demo-9/reexport-dup/std/index.html?search=hashmap

This change uses the same "exact" paths as trait implementors and type alias inlining to track items with multiple reachable paths. This way, if you search for `vec`, you get only the `std` exports of it, and not the one from `alloc`.

It still includes all the items in the search index so that you can search for them by all available paths. For example, try `core::option` and `std::option`, and notice that the results page doesn't show duplicates, but still shows all the items in their respective crates.
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 18, 2024
…r=GuillaumeGomez

rustdoc-search: single result for items with multiple paths

Part of rust-lang#15723

Preview: https://notriddle.com/rustdoc-html-demo-9/reexport-dup/std/index.html?search=hashmap

This change uses the same "exact" paths as trait implementors and type alias inlining to track items with multiple reachable paths. This way, if you search for `vec`, you get only the `std` exports of it, and not the one from `alloc`.

It still includes all the items in the search index so that you can search for them by all available paths. For example, try `core::option` and `std::option`, and notice that the results page doesn't show duplicates, but still shows all the items in their respective crates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. 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

8 participants