Skip to content

Tracking issue for RFC 1946 - intra-rustdoc links #43466

Closed

Description

@nrc

RFC: https://github.com/rust-lang/rfcs/blob/master/text/1946-intra-rustdoc-links.md
RFC PR: rust-lang/rfcs#1946

Todo:

Other related issues:

Activity

  1. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.
    T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Jul 25, 2017
  2. QuietMisdreavus commented on Sep 19, 2017

    @QuietMisdreavus
    Contributor

    Preliminary implementation notes:

    Getting just the links from the markdown is relatively straightforward. You'll need to do this twice, to capture the behavior in both the Hoedown and Pulldown markdown renderers. Thankfully, each has a way of capturing links as they are parsed from the document. (While capturing the link you can also look for the "struct/enum/mod/macro/static/etc" marker to aid in resolution down the line.)

    In Hoedown, the render function in src/librustdoc/html/markdown.rs captures all the events as they are captured. Hoedown uses a system of registering callbacks on the renderer configuration to capture each event separately. The link event and its related linkfn function pointer signature are already present in the file, so you would need to create and use that callback to capture and modify links as they appear.

    For Pulldown, the parser is surfaced as an Iterator of events. There are already a handful of iterator wrappers present in html/markdown.rs, so adding another one (and using it in the impl fmt::Display for Markdown farther down) shouldn't be a big deal. I'm... honestly not that familiar with how Pulldown represents link definitions in its Event/Tag enums, so more research would be needed to effectively get link text for that.

    Now, with the links in hand, you need to do two things, neither of which i know offhand since they involve interfacing with the compiler:

    • Attempt to parse the link as a path (if it's not a valid Rust path, just emit the URL as-is and skip the rest of this)
    • Resolve the path in the "current" module (emit a warning if resolution fails)

    Presumably there's a way to make the resolution come up with a DefId? Even after cleaning the AST, rustdoc still deals in those, so if that's the case there are ways to map that to the proper relative link.

  3. Manishearth commented on Dec 28, 2017

    @Manishearth
    Member

    I've got a WIP going on in https://github.com/manishearth/rust/tree/correct-resolver-fail , which works off of Misdreavus' WIP (they did most of the work).

  4. QuietMisdreavus commented on Dec 28, 2017

    @QuietMisdreavus
    Contributor

    Note that that branch is now live as #47046, which i'm polishing and finishing up.

  5. QuietMisdreavus commented on Jan 8, 2018

    @QuietMisdreavus
    Contributor

    Note for people watching this thread but not #47046: We're trying to wind that PR down to get a minimal version landed, so an initial implementation is fairly close.

  6. added 3 commits that reference this issue on Jan 22, 2018
  7. sgrif commented on Jan 23, 2018

    @sgrif
    Contributor

    One thing that appears to not work in #47046 (and I don't think is ever explicitly addressed in the RFC) is how to link to primitives like u32 or bool.

  8. Manishearth commented on Jan 24, 2018

    @Manishearth
    Member

    Yeah I have to investigate that

  9. Manishearth commented on Jan 24, 2018

    @Manishearth
    Member

    @killercup @QuietMisdreavus should we turn the error into a warning ? I don't like the idea of crate docs breaking because someone introduced a name into a glob import

  10. killercup commented on Jan 24, 2018

    @killercup
    Contributor

    @Manishearth does rustdoc have some idea of "lint levels"? What are the current deprecation warnings? Just println!s?

  11. 155 remaining items

  12. Manishearth commented on Jul 9, 2020

    @Manishearth
    Member

    @ollie27 We have had a functional implementation for three years now. It has been used in the stdlib docs for ages, and is used across the ecosystem. The ability for reexports to work correctly was a blocker to stabilization, but it is not a huge feature that will be used a lot. The reason stabilization was blocked on reexports was that we determined that the bug fix could be complicated and might require rearchitecting the feature, which made us reluctant to stabilize earlier.

  13. Manishearth commented on Jul 9, 2020

    @Manishearth
    Member

    seeing if it can fix the issues it was designed for (#32129, #32130)

    I hadn't seen these issues earlier, and we should absolutely fix them using intra doc links, but I don't want to block stabilization on that. We've had this feature mostly working for ages.

  14. Manishearth commented on Jul 15, 2020

    @Manishearth
    Member

    Alright, so the current status of this is that we have a stack of PRs blocking all remaining major issues (#65983, #73363): #74347 -> #73566 -> #73101 -> #73365

    Between @GuillaumeGomez, @jyn514, and myself, we hope to stabilize this shortly thereafter. @GuillaumeGomez will be filing an FCP but as we're currently mostly waiting for the final chips to fall in place, I wanted to front-load some of the discussions that may happen during that FCP. Hopefully when we make that FCP it is simply some rubber-stamping if we have these discussions earlier.

    @rust-lang/rustdoc What are your thoughts on stabilizing this shortly after the last few patches land? I recall @ollie27 having some concerns. I don't recall if @kinnison has said anything on this point.

    My position on this (I think this is shared by Guillaume and Joshua) is that this feature has been cooking on nightly for three years now. The cross-crate import issue was a blocker not because it was a major piece of functionality, but rather because there was a chance we wouldn't be able to implement it in a neat manner and would paint ourselves into a corner by committing to it. It's clear that that's not the case. If we're worried about the code for cross-crate imports itself being broken, that's what the release train schedule is for -- we can undo these patches and stabilization for twelve weeks if this happens.

  15. kinnison commented on Jul 16, 2020

    @kinnison
    Contributor

    I think that once the remaining stack lands, we're in good shape to stabilise. There're bound to be corner cases we've not found etc. and documentation which could be improved, but getting this out and usable by the general developer community will be immensely useful.

  16. Manishearth commented on Jul 17, 2020

    @Manishearth
    Member

    #65983 has landed, so now we're ready for stabilization. #73363 should land soon

  17. Manishearth commented on Jul 17, 2020

    @Manishearth
    Member

    Stabilization PR is ready #74430

  18. jyn514 commented on Aug 19, 2020

    @jyn514
    Member

    It should be noted that in the RFC discussion it was determined that exact knowledge of the item type should not be necessary; only knowing the namespace should suffice. It is acceptable that the tool resolving the links allows (and successfully resolves) a link with the wrong prefix that is in the same namespace. E.g., given an struct Foo, it may be possible to link to it using [enum Foo], or, given a mod bar, it may be possible to link to that using [struct bar].

    After #75079 this is no longer the case. Should the RFC be updated?

  19. Manishearth commented on Aug 20, 2020

    @Manishearth
    Member

    @jyn514 go for it

  20. runiq commented on Sep 4, 2020

    @runiq

    Triage: #74489 has been merged, so its mark can be checked, I believe?

  21. added a commit that references this issue on Sep 24, 2020
  22. added a commit that references this issue on Sep 24, 2020
  23. added a commit that references this issue on Mar 18, 2021
  24. swfsql commented on Oct 18, 2021

    @swfsql

    Hi, does someone knows how to write intra-rustdoc links to trait implementation on structs? I'm not sure if this is not implemented or if I'm writing incorrectly.

    Have tried those, but they are not working:

    [`<Struct as Trait>::f()`]
    [`<Struct as Trait>::f`]
    (link)[<Struct as Trait>::f]
    (link)[<Struct as Trait>::f()]
    
  25. jyn514 commented on Oct 18, 2021

    @jyn514
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by nameB-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions