Skip to content

rustdoc intra-doc link: cannot disambiguate between primitive and type alias #146855

@k2d222

Description

@k2d222

Related #135897

After shadowing a primitive with a type-alias, it seems impossible to disambiguate a rustdoc link to the type-alias. Using the type@ disambiguator does not help.

struct Foo;
type f32 = Foo;

#[doc = "this function returns [`type@f32`]"]
fn my_fn() -> f32;

I ran

$> cargo doc

warning: `f32` is both a type alias and a primitive type
  ...
  = note: ambiguous link
  = help: to link to the type alias, prefix with `type@`: type@f32
  = help: to link to the primitive type, prefix with `prim@`: prim@f32

Meta

rustc --version --verbose:

rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-unknown-linux-gnu
release: 1.88.0
LLVM version: 20.1.5

Present in nightly too. cargo 1.90.0-nightly (409fed7dc 2025-06-23). But the diagnostic is slightly different:

warning: `f32` is both a type alias and a primitive type
3 | #[doc = "this function returns [`type@f32`]"]                                                                                                                   
  |                                  ^^^^^^^^ ambiguous link
  |
  = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
help: to link to the primitive type, prefix with `prim@`

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.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