How can we get previous rust compiler API docs locally?

There is an officially hosted website for latest rustc internal APIs:

But I can't find the same docs on local path where std doc locates. Like in the folder ~/.rustup/toolchains/nightly-2024-10-12-x86_64-unknown-linux-gnu/share/doc/rust/html/.

The internal API docs are specific to local toolchain. How can we get them?

I find the command rustup doc is helpful to open the content in that folder, but there isn't an argument for rustc API docs.

$ rustup doc --help
Open the documentation for the current toolchain

Usage: rustup doc [OPTIONS] [topic]

Arguments:
  [topic]  Topic such as 'core', 'fn', 'usize', 'eprintln!', 'core::arch', 'alloc::format!', 'std::fs', 'std::fs::read_dir', 'std::io::Bytes', 'std::iter::Sum',
           'std::io::error::Result' etc...

Options:
      --path                   Only print the path to the documentation
      --toolchain <toolchain>  Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see `rustup help toolchain`
      --alloc                  The Rust core allocation and collections library
      --book                   The Rust Programming Language book
      --cargo                  The Cargo Book
      --core                   The Rust Core Library
      --edition-guide          The Rust Edition Guide
      --nomicon                The Dark Arts of Advanced and Unsafe Rust Programming
      --proc_macro             A support library for macro authors when defining new macros
      --reference              The Rust Reference
      --rust-by-example        A collection of runnable examples that illustrate various Rust concepts and standard libraries
      --rustc                  The compiler for the Rust programming language
      --rustdoc                Documentation generator for Rust projects
      --std                    Standard library API documentation
      --test                   Support code for rustc's built in unit-test and micro-benchmarking framework
      --unstable-book          The Unstable Book
      --embedded-book          The Embedded Rust Book
  -h, --help                   Print help

Discussion:
    Opens the documentation for the currently active toolchain with
    the default browser.

    By default, it opens the documentation index. Use the various
    flags to open specific pieces of documentation.

I thought rustc-dev component would include the API docs, which rustup book says:

  • rustc-dev — This component contains the compiler as a library. Most users will not need this; it is only needed for development of tools that link to the compiler, such as making modifications to Clippy.

src: Components - The rustup book

there's a rustc-doc-TRIPLET in the output of rustup component list, but it's not listed in the rustup book, I'm guessing that might contain the internal documentation, but I didn't install it because it conflicts with rust-docs. you can check it out yourself.

1 Like

Thank you for reminding me of rustup component list!

I managed to get rustc-docs by running rustup component add rustc-docs-x86_64-unknown-linux-gnu.

As a reminder, I came arocss the error: failed to install component: 'rustc-docs-x86_64-unknown-linux-gnu', detected conflict: 'share/doc/rust/html/rustc', because the folder has already contained a rustc subdirectory for rustc book. I removed the rustc subdirectory manually since I don't need it. Then I ran the above command, and successfully got rustc internal docs.

The conflict is a known bug for years: