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 "Aliased Type" view is wrong #120404

Open
SludgePhD opened this issue Jan 27, 2024 · 7 comments
Open

rustdoc "Aliased Type" view is wrong #120404

SludgePhD opened this issue Jan 27, 2024 · 7 comments
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-discussion Category: Discussion or questions that doesn't represent real issues. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@SludgePhD
Copy link

screenshot_2024-01-27_01:56:48

In this rustdoc output, rustdoc seems to claim that MatrixView aliases a struct MatrixView.

This is wrong, since no such struct exists. It seems like there was some sort of mistake when implementing this feature that ended up using the wrong name there? It should say Matrix instead.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 27, 2024
@aDotInTheVoid aDotInTheVoid added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 27, 2024
@aDotInTheVoid
Copy link
Member

What crate is this for? Can you give a minimal example that reproduces this behavior?

@SludgePhD
Copy link
Author

Any type alias of a struct will reproduce it.

pub type Alias<T> = Vec<T>;

Result:

screenshot_2024-01-27_02:54:58

@fmease
Copy link
Member

fmease commented Jan 27, 2024

This works exactly as intended: The “aliased type” shown isn't a real user-written type but a synthetic one.

@fmease
Copy link
Member

fmease commented Jan 27, 2024

Of course, we should probably employ some more heuristics and e.g., not show aliased structs whose fields are all private.

@fmease
Copy link
Member

fmease commented Jan 27, 2024

I can understand that that feature might be a bit unintuitive at first. If you have suggestions for making it clearer to the reader that this aliased type isn't grounded in source code, please don't hesitate to share them :)

@SludgePhD
Copy link
Author

To me, "aliased type" strictly refers to the right-hand side of the type A = B syntax, so I would find this feature much less confusing if it simply used the name of the right-hand type instead.

@fmease fmease added C-discussion Category: Discussion or questions that doesn't represent real issues. A-rustdoc-ui Area: Rustdoc UI (generated HTML) and removed S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. labels Jan 27, 2024
@Urgau
Copy link
Member

Urgau commented Feb 2, 2024

To me, "aliased type" strictly refers to the right-hand side of the type A = B syntax, so I would find this feature much less confusing if it simply used the name of the right-hand type instead.

@SludgePhD Except that this wouldn't work in "generic context", take for exemple this type alias:

type NonZeroU128 = NonZero<u128>;

writting it with the "right hand side" would mean:

struct NonZero<u128>(/* ... */);

which is not a valid syntax and is not that what anyone that would use NonZeroU128 would need to know.

Taking a more expressive example:

struct Container<A: Trait>(pub A, pub A);
type MyContainer = Container<MyStruct, MyStruct>;

Here, the aliased type (as seen by the compiler) is:

struct MyContainer(pub MyStruct, pub MyStruct);

and it makes much more sense to write it like this. That way users don't have the irrelevant Trait bound or even the generic in the way.


You can look at the description of #114855 for a more detailed explanation and motivation for the "aliased type" feature.


As for how we can improve the reading of this section, what about a tooltip (or small label) with something like this:

This section shows the concrete type (i.e. removing any generics/bounds not present the aliased type) has would been seen by anyone using the aliased type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-discussion Category: Discussion or questions that doesn't represent real issues. 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