Skip to content

Stabilization of the documentation scope in rustc #163896

Open

Description

@Urgau

Stabilization of the documentation scope in rustc

rustdoc is in the process of stabilizing --remap-path-scope in rustdoc in #163895. (We stabilized --remap-path-scope in rustc earlier this year in #147611).

Summary

In addition to the other stable scopes (diagnostics, debuginfo, object, ...), rustdoc has an additional scope: documentation, it's used to define if paths should be remapped in the documentation.

In order to simplify interoperability between rustc and rustdoc, the scope is being proposed to be accepted by rustc.

The scope is never checked to be active by rustc, but it still encoded in rmeta. This is so rustdoc can check if the documentation scope is active for a RealFilename when getting the filepath of a RealFilename coming from a dependency.

Implementation

Major parts

Coverage in rustc

Activity

  1. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 6, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 6, 2026
  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 6, 2026
  4. Urgau commented on Oct 6, 2026

    @Urgau
    MemberAuthor

    @rfcbot merge compiler

  5. rust-rfcbot commented on Oct 6, 2026

    @rust-rfcbot
    Collaborator

    @Urgau has proposed to merge this. The next step is review by the rest of the tagged team members:

    No concerns currently listed.

    Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

    See this document for info about what commands tagged team members can give me.

  6. added
    proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
    disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.
    on Oct 6, 2026
  7. oli-obk commented on Oct 7, 2026

    @oli-obk
    Contributor

    In order to simplify interoperability between rustc and rustdoc, the scope is being proposed to be accepted by rustc.

    why is it necessary for rustc to accept this flag? simply forwarding all rustdoc flags to rustc without filtering?

  8. Urgau commented on Oct 7, 2026

    @Urgau
    MemberAuthor

    The flag (--remap-path-scope) is stable in rustc, that's not something new or something that's changing.

    The flag has multiple options that can be passed to it, we called them scopes. All the scopes currently stable do something in rustc.

    What's changing is it rustdoc is stabilizing the flag on their side, but to avoid using a misleading scope, like diagnostics for the generated documentation html files by rustdoc, we created a new scope in rustc/rustdoc: documentation.

    It's this new scope, and only this new scope, that will do nothing in rustc it-self.

    As for why rustc should accept it, it's both to simply interoperability, it's easier for users if rustc and rustdoc accept the same options.

    But there also is a more practical use, rustdoc uses the same rmeta from the dependencies and those may contain paths that rustdoc may want to print the remapped path (not sure if we have a stable case in rustdoc for that though).

  9. oli-obk commented on Oct 7, 2026

    @oli-obk
    Contributor

    As for why rustc should accept it, it's both to simply interoperability, it's easier for users if rustc and rustdoc accept the same options.

    I thought rustdoc already had options that rustc doesn't accept. But even if not, where is such "interop" (do you mean drop-in replacement?) useful or already in use?

    But there also is a more practical use, rustdoc uses the same rmeta from the dependencies and those may contain paths that rustdoc may want to print the remapped path (not sure if we have a stable case in rustdoc for that though).

    How does that relate to the flags? If rustc built the rmeta, it didn't get remapped, so rustdoc needs to do sth here anyway

  10. Urgau commented on Oct 7, 2026

    @Urgau
    MemberAuthor

    As for why rustc should accept it, it's both to simply interoperability, it's easier for users if rustc and rustdoc accept the same options.

    I thought rustdoc already had options that rustc doesn't accept. But even if not, where is such "interop" (do you mean drop-in replacement?) useful or already in use?

    rustdoc has flags that rustc doesn't have, but I don't think rustdoc has any rustdoc specific options in a shared flag.

    Rust-for-linux is not currently using --remap-path-scope in rustdoc but they do consider the flag to be "common". Just like --remap-path-prefix is.

    https://github.com/torvalds/linux/blob/602042bf29f6efde39cfb5fdd9289bf4854bc0c5/rust/Makefile#L176

    But there also is a more practical use, rustdoc uses the same rmeta from the dependencies and those may contain paths that rustdoc may want to print the remapped path (not sure if we have a stable case in rustdoc for that though).

    How does that relate to the flags? If rustc built the rmeta, it didn't get remapped, so rustdoc needs to do sth here anyway

    The scopes are attached to each individual RealFilename in the rmeta at https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.RealFileName.html. It's done this way so that the current scopes do not affect those from the dependencies. We had an unsoundness when we used the scopes from the current session.

  11. oli-obk commented on Oct 7, 2026

    @oli-obk
    Contributor

    The scopes are attached to each individual RealFilename in the rmeta at https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.RealFileName.html. It's done this way so that the current scopes do not affect those from the dependencies. We had an unsoundness when we used the scopes from the current session.

    Right, but are the rmeta created by rustdoc or by rustc? Because if thr latter, and a no-op there, then why would rustdoc benefit from it being specified as documentation vs not being specified at all?

  12. Urgau commented on Oct 7, 2026

    @Urgau
    MemberAuthor

    The later, rustc is the one creating the rmeta.

    and a no-op there

    When it said that is does nothing I meant that rustc doesn't condition on it (ie. rustc never checks if the documentation scope is active for a RealFilename, only rustdoc does that), but rustc still encodes it in rmeta, otherwise rustdoc couldn't exploit it.

    Sorry for the confusion. Improved the wording in the top comment.

  13. Urgau commented on Oct 14, 2026

    @Urgau
    MemberAuthor

    For information, #164279 moves the documentation scope under the object alias scope. It currently covers the macro, debuginfo and coverage scopes, and would include the documentation scope as well.

    Rational in #164279 (comment), but tl;dr is that it better reflects how the scope is actually used (for things that end up written to disk, which the object scope is meant to represent) and simplify things for Cargo.

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

    F-trim-pathsFeature: trim-pathsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions