Skip to content

rustdoc: Can't use anchors in links to primitive types #83083

Closed
@taylordotfish

Description

@taylordotfish

rustdoc doesn't allow anchors in links to primitive types. For example, given this code:

//! [test](str#examples)

cargo doc produces this warning:

warning: `str#examples` contains an anchor, but links to builtin types are already anchored
 --> src/lib.rs:1:12
  |
1 | //! [test](str#examples)
  |            ^^^^^^^^^^^^ contains invalid anchor
  |
  = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default

and the resulting link doesn't point to any part of str's documentation, but is rather treated as a normal URL relative to the current page.

The warning claims that “links to builtin types are already anchored”, but this does not appear to be correct. For example, this code:

//! [test](str)

produces a link to https://doc.rust-lang.org/nightly/std/primitive.str.html, which does not contain an anchor.

Meta

rustc 1.52.0-nightly (b3e19a221 2021-03-12)
binary: rustc
commit-hash: b3e19a221e63dcffdef87e12eadf1f36a8b90295
commit-date: 2021-03-12
host: powerpc64le-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 12.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by nameC-bugCategory: This is a bug.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.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