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

Allow generic parameters in intra doc link #62834

Closed
dtolnay opened this issue Jul 20, 2019 · 10 comments · Fixed by #76934
Closed

Allow generic parameters in intra doc link #62834

dtolnay opened this issue Jul 20, 2019 · 10 comments · Fixed by #76934
Assignees
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-enhancement Category: An issue proposing an enhancement or a PR with one. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@dtolnay
Copy link
Member

dtolnay commented Jul 20, 2019

pub struct Collection<T> { __: T }

/// [`Collection`], [`Collection<T>`]
pub struct S;

Currently this renders as ` Collection, [Collection<T>] `, where the first link is ok but the second link is not rendered. I think these should both point to struct.Collection.html. For some types it can be clearer to include the type parameters when discussing them.

Mentioning the tracking issue: #43466

@dtolnay dtolnay added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name labels Jul 20, 2019
@jonas-schievink jonas-schievink added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 20, 2019
@Nemo157
Copy link
Member

Nemo157 commented Jul 22, 2019

In relation to the objection @GuillaumeGomez had on the tracking thread, I have a usecase where I want to link to the different parts of a fully applied (nested) generic type.

Extending the example slightly, should the following also work:

pub struct Collection<T> { __: T }

pub struct U;

/// [`Collection`], [`Collection<T>`], [`Collection<U>`]
pub struct S;

and should that result in something like:

Collection, Collection<T>, Collection<U>

?

@nixpulvis
Copy link

nixpulvis commented Aug 6, 2019

Would it make sense to support entire specialized doc pages like ".../target/doc/general/struct.General<i32>.html" (exact URL can't look like this I believe) so a link to a specific type of a polymorphic type can filter out all other impls from the docs?

This might be nice in some specific use cases that make heavy use of specialized implementations.

@jyn514
Copy link
Member

jyn514 commented Jun 26, 2020

support entire specialized doc pages

That seems a much bigger change than the one originally suggested. For one thing we'd have to design what the page should look like.

I wonder if we could hack this by deleting all text between < and > in intra-doc links? AFAIK the only time those are valid is for generics, and an unclosed delimiter would be a syntax error in a type.

@jyn514
Copy link
Member

jyn514 commented Jul 17, 2020

I've also seen people trying to use Some(T) which would be nice to support. This one is tricky because Some() is parsed as a function disambiguator. But maybe since we currently don't distinguish between functions and other types just stripping the T would work?

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented Jul 17, 2020

I'm still strongly against it. However, I don't remember if we can mix type and anchor? Like: [Collection#some-impl]. In this case, it'd fix all issues I assume and is far more simple to implement (if not already done).

EDIT: It's already supported. I'll add it to the documentation of intra-doc links.

@jyn514
Copy link
Member

jyn514 commented Jul 17, 2020

Direct link so all the discussion is in one place: #43466 (comment)

@jyn514
Copy link
Member

jyn514 commented Jul 17, 2020

In this case, it'd fix all issues I assume and is far more simple to implement (if not already done).

Well, it's still possible to link to Some directly. But it makes you use [Some(T)](Some) instead of the direct [Some(T)]. So I think we should consider making it easier for the same reason as Option<T>. See #74300 (comment) for an example.

@camelid
Copy link
Member

camelid commented Sep 18, 2020

Is a simple version of this planned to be implemented? A nice start would be something where Vec<T> just links to Vec. Then a lot of duplication like this could be avoided:

Here's a link to [`Vec<T>`].

[`Vec<T>`]: Vec

@jyn514
Copy link
Member

jyn514 commented Sep 18, 2020

Mentoring instructions:

Just before calling resolve_with_disambiguator, replace path_str with a version that has everything in <> stripped. Note that this should match the brackets: Vec<Option<T>> should turn into Vec, not Vec>.

@jyn514 jyn514 added E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Sep 18, 2020
@camelid
Copy link
Member

camelid commented Sep 18, 2020

I would be interested in implementing this.

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-enhancement Category: An issue proposing an enhancement or a PR with one. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants