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 = rootView on GitHub (pinned to 7088e4b63a)
Solutions
- `cargo clean` then `cargo doc` so traits-in-scope are encoded for the current graph.
- Ensure all documented dependencies carry doc metadata (remove `--no-deps`, set `RUSTDOCFLAGS=-D rustdoc::broken_intra_doc_links` consistently).
- Pin one toolchain for the whole doc build.
- 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
- Build the documentation graph with one toolchain and consistent `RUSTDOCFLAGS`.
- `cargo clean` before doc builds that follow a toolchain change.
- Ensure documented dependencies are compiled with doc metadata.
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
- no resolutions for a doc link
- no encoded ident for item
- variants are not encoded for an enum
- provided `DefIndex` must refer to a module-like item
- argument names not encoded for a function
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/bb0d874f3ba73f86.
Report an issue: GitHub.