Skip to content

rustdoc: Prefixing parent modules to distinguish between items in cases where item names would otherwise be ambiguous #65330

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

Closed
mitchmindtree opened this issue Oct 12, 2019 · 1 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.

Comments

@mitchmindtree
Copy link
Contributor

Motivation

I often run into an issue when reading through rendered documentation where many types exist with the same name and it is unclear which type is being referred to in a function signature or type declaration.

Two simple, common examples of this are the Result and Error types. When displayed within a type declaration or function signature, the reader is unable to tell at a glance what Result or Error type is being referred to, and is forced to either click to the type or hover over the type and examine the link, both of which can be a significant hindrance when reading through large amounts of documentation. Here's an example of an ambiguous error type within a type declaration:

Screenshot from 2019-10-12 12-10-28

Here, unless you are already familiar with the crate, it is difficult to know exactly what Error type the type declaration refers to, as it is convention for crates (and often sub-modules) to define unique Error types. We can't know for sure without clicking on the Error type and checking exactly which one is being referred to. The same issue applies to ambiguous item names that appear in function signatures and struct fields.

Result and Error are just two examples of many. For example, in math and gaming libraries, the same issues apply to types like Point, Vector and Matrix, and are especially confusing when using e.g. one physics library with one graphics library, or a tessellation library alongside another math library - it is impossible to know for sure exactly what type the documentation refers to without clicking through and interrupting the flow of doc perusal.

Potential Solution

One potential solution that comes to mind might be to prefix these potentially ambiugous types with their parent module in the rendered docs. E.g. in the error case above, the rendered doc might look more like this:

type Fallible<T> = Result<T, failure::Error>;

In this case, we know that there is at least one other type within this crate or its dependencies with the same name (std::io::Error) - in order to remove ambiguity, the Error type is prefixed with its parent module failure, so that it is clear which is being referred to.

Keeping in mind I am unfamiliar with rustdoc internals, I wonder if this can be achieved by keeping a map from item names to whether or not they occur more than once during the documentation process. For all items that occur more than once in the crate or its dependency graph, their parent modules are prefixed to the item name until the ambiguity is resolved?


Just thought I'd share this while it's on my mind in case anyone else has come across a similar desire! I searched past issues briefly but was unable to find this raised elsewhere - feel free to close this in favour of an existing issue if one already exists!

@jonas-schievink jonas-schievink added 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. labels Oct 12, 2019
@jyn514
Copy link
Member

jyn514 commented Aug 27, 2020

Duplicate of #74924, but this is a really good write-up! Feel free to post it as a comment on that issue :)

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

3 participants