Skip to content

Intra-doc links do not support disambiguating methods overloaded with generics #93398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
erickt opened this issue Jan 27, 2022 · 2 comments
Open
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@erickt
Copy link
Contributor

erickt commented Jan 27, 2022

Hello all! I couldn't find any tickets that discuss this problem, so hopefully this isn't a duplicate report.

I'm experimenting with the typestate pattern, where I'm using it in a builder to cascade a series of transformations. Here's a simple version:

pub trait State {}

pub struct Add;
impl State for Add {}

pub struct Mul;
impl State for Mul {}

pub struct Calculator<T: State = Add> { value: usize, _state: T }

impl Calculator {
    pub fn new() -> Calculator<Add> {
        Calculator { value: 0, _state: Add }
    }

    pub fn add_1(mut self) -> Self {
        self.value += 1;
        self
    }

    pub fn next(self) -> Calculator<Mul> {
        Calculator { value: self.value, _state: Mul }
    }

    /// See [Calculator<Mul>::done].
    pub fn done(self) -> usize {
        self.next().done()
    }
}

impl Calculator<Mul> {
    pub fn multiply_2(mut self) -> Self {
        self.value *= 2;
        self
    }

    /// I'm done.
    pub fn done(self) -> usize {
        self.value
    }
}

It seems though that rustdoc does not handle overloading the name particularly well. When running cargo doc, the documentation for the Calculator<Add>::done() just links to itself, rather than the doc on Calculator<Mul>::done(). I'm guessing it's just stripping out the type parameter and linking to the first entry.

I expected to see this happen:

I hoped that we could link to the doc comment on the overloaded method

Instead, this happened:

rustdoc linked to the first method's comment.

Meta

rustc --version --verbose:

rustc 1.58.0 (02072b482 2022-01-11)
binary: rustc
commit-hash: 02072b482a8b5357f7fb5e5637444ae30e423c40
commit-date: 2022-01-11
host: x86_64-apple-darwin
release: 1.58.0
LLVM version: 13.0.0
@erickt erickt added the C-bug Category: This is a bug. label Jan 27, 2022
@camelid camelid added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jan 28, 2022
@camelid
Copy link
Member

camelid commented Jan 28, 2022

Yep, rustdoc just ignores generics in intra-doc links currently. I don't think there's any way to disambiguate as of yet.

@camelid camelid added A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-enhancement Category: An issue proposing an enhancement or a PR with one. C-bug Category: This is a bug. and removed C-bug Category: This is a bug. labels Jan 28, 2022
@camelid camelid changed the title Rustdoc does not link to overloaded methods by name Intra-doc links do not support disambiguating methods overloaded with generics Jan 28, 2022
@fmease
Copy link
Member

fmease commented Mar 28, 2023

This has the same root cause as #85960. The type parameter defaults are not really relevant.

@fmease fmease removed the C-bug Category: This is a bug. label Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants