rust-lang/rust · error

no traits in scope for a doc link

Error message

no traits in scope for a doc link

What it means

Fires in `get_doc_link_traits_in_scope` (decoder.rs:1937), the companion to 288. Rustdoc encodes the list of traits in scope (for method-resolution in intra-doc links) per definition; the decoder `.expect()`s an entry in `doc_link_traits_in_scope`. A missing entry indicates doc metadata was not encoded for that definition or was encoded by an incompatible version.

Source

Thrown at compiler/rustc_metadata/src/rmeta/decoder.rs:1937

    fn get_doc_link_resolutions(&self, tcx: TyCtxt<'_>, index: DefIndex) -> DocLinkResMap {
        self.root
            .tables
            .doc_link_resolutions
            .get(self, index)
            .expect("no resolutions for a doc link")
            .decode((self, tcx))
    }

    fn get_doc_link_traits_in_scope(
        &self,
        tcx: TyCtxt<'_>,
        index: DefIndex,
    ) -> impl Iterator<Item = DefId> {
        self.root
            .tables
            .doc_link_traits_in_scope
            .get(self, index)
            .expect("no traits in scope for a doc link")
            .decode((self, tcx))
    }
}

impl CrateMetadata {
    pub(crate) fn new(
        tcx: TyCtxt<'_>,
        blob: MetadataBlob,
        root: CrateRoot,
        raw_proc_macros: Option<&'static [ProcMacroClient]>,
        cnum: CrateNum,
        cnum_map: CrateNumMap,
        dep_kind: CrateDepKind,
        source: CrateSource,
        private_dep: bool,
        host_hash: Option<Svh>,
    ) -> CrateMetadata {
        let trait_impls = root

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. `cargo clean` then `cargo doc` so traits-in-scope are encoded for the current graph.
  2. Ensure all documented dependencies carry doc metadata (remove `--no-deps`, set `RUSTDOCFLAGS=-D rustdoc::broken_intra_doc_links` consistently).
  3. Pin one toolchain for the whole doc build.
  4. Clean-build ICE -> file against rustdoc.
Defensive patterns

Strategy: validation

Validate before calling

cargo clean && cargo doc   # re-encode traits-in-scope for the current graph

Try / catch

cargo doc || { cargo clean && cargo doc; }

Prevention

When it happens

Trigger: Documenting a definition whose traits-in-scope were never serialized (dependency built without doc metadata); schema change in the doc-link tables; reusing artifacts across rustdoc versions.

Common situations: Shared `target/` between `cargo build` and `cargo doc`; dependency recompiled without doc flags; nightly rustdoc changes to the doc-link encoding.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/bb0d874f3ba73f86. Report an issue: GitHub.