Skip to content

Intra-doc links cannot link to associated methods on type aliases. #86120

Closed
@jonhoo

Description

@jonhoo

I tried this code:

#[warn(rustdoc::all)]

pub struct Foo<C>(C);

impl<C> Foo<C> {
    pub fn new() -> Self {
        todo!()
    }
}

/// [`Bar::new`]
pub type Bar<C> = Foo<C>;

I expected to see this happen: Bar::new should be a link to Foo::new.

Instead, this happened: Bar::new was not turned into a link, and the compiler gave this warning:

warning: unresolved link to `Bar::new`
  --> src/lib.rs:11:6
   |
11 | /// [`Bar::new`]
   |      ^^^^^^^^^^ the type alias `Bar` has no associated item named `new`
   |
   = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default

warning: 1 warning emitted

I'm guessing that this isn't implemented because the forwarding may not always be obvious such as if there are multiple fn new for Foo for different values of C. But it'd be nice if it did work when there aren't and the choice is "clear".

EDIT: Though on second thought, that should also be an issue for

/// [`Foo::new`]

on Foo, so I feel like if that works this should also work.

Meta

rustc --version --verbose:

rustc 1.52.1 (9bc8c42bb 2021-05-09)
binary: rustc
commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
commit-date: 2021-05-09
host: x86_64-apple-darwin
release: 1.52.1
LLVM version: 12.0.0

The same issue is present on nightly.

Metadata

Metadata

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