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

Add cargo fix support for switching to intra-doc links #75805

Open
jyn514 opened this issue Aug 22, 2020 · 4 comments
Open

Add cargo fix support for switching to intra-doc links #75805

jyn514 opened this issue Aug 22, 2020 · 4 comments
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-resolve Area: Name resolution A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-feature-request Category: A feature request, i.e: not implemented / a PR. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Aug 22, 2020

This will be tricky for several reasons.

  • It needs pulldown support to look at the links even if they're not broken. Event and Tag seem like they should work.
  • Rustdoc needs to know what the link is meant to resolve to. This can be tricky if the item is re-exported in multiple places (see e.g. Broken links in String documentation from Deref impl #32129). Rustdoc should report all possible items you meant if there's ambiguity (and downgrade the applicability).
  • Rustdoc needs to know what name in scope matches with the item you're linking too. This seems like it shouldn't be too hard, but I don't see a way to go from DefId -> Path on Resolver, only the reverse. cc @Manishearth, do you have ideas?

This can be implemented as an allowed-by-default lint with Applicability::MachineApplicable; then cargo fix will pick it up automatically.

@jyn514 jyn514 added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Aug 22, 2020
@jyn514
Copy link
Member Author

jyn514 commented Aug 22, 2020

I don't see a way to go from DefId -> Path on Resolver

Maybe def_path_str would work for this. I'm worried that will only give the absolute path, not the relative path, though (see also #50310).

@Manishearth
Copy link
Member

It's been a long standing bug that diagnostics should print out a local path, so, I don't think it's easy to do yet. The information exists, just not the code for it

@jyn514
Copy link
Member Author

jyn514 commented Aug 22, 2020

I mean, I don't mind trying to fix #50310 at the same time. Where's the information stored?

ScopeTree seems vaguely related.

@Manishearth
Copy link
Member

Unsure, @eddyb may know

@jyn514 jyn514 added E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. A-resolve Area: Name resolution labels Aug 22, 2020
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 A-resolve Area: Name resolution A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-feature-request Category: A feature request, i.e: not implemented / a PR. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. 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

2 participants