Skip to content

Rustdoc doesn't warn if links to associated items are ambiguous if primitives are involved #83862

Closed

Description

@jyn514

Rustdoc should give an error if the base res is ambiguous, but it doesn't:

$ cat primitive-ambiguous.rs 
//! [usize::MAX]

mod usize {
  const MAX: usize = 1;
}
$ rustdoc primitive-ambiguous.rs
$

This was originally discovered through the special case

//! [usize::MAX]

#[doc(primitive = "usize")]
mod usize {}

which I think should continue working, rustdoc shouldn't give an ambiguity error if the module has doc(primitive) on it.

Originally posted by @jyn514 in #83849 (comment)

Meta

HEAD is 2616ab1

Activity

  1. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    A-associated-itemsArea: Associated items (types, constants & functions)
    A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by name
    C-bugCategory: This is a bug.
    on Apr 4, 2021
  2. jyn514 commented on Apr 8, 2021

    @jyn514
    MemberAuthor

    Oof I just realized this is a lot harder than I expected. For the case where usize is a module, usize::MAX resolves normally with resolve_path, before the hacky string splitting for resolve_associated_item. So to support prim@usize::MAX I need to do the string splitting before resolve_path ever runs, and call resolve_primitive_associated_item instead.

    @Manishearth btw do you want that prim@usize::MAX syntax to work? Or should it just not be possible to disambiguate the two? It does seem weird for the disambiguator to refer to the root res usize instead of MAX, that's inconsistent with how it works eveywhere else.

  3. Manishearth commented on Apr 8, 2021

    @Manishearth
    Member

    @Manishearth btw do you want that prim@usize::MAX syntax to work? Or should it just not be possible to disambiguate the two? It does seem weird for the disambiguator to refer to the root res usize instead of MAX, that's inconsistent with how it works eveywhere else.

    Hmm, this sounds like a pretty big complication; unsure if we should.

    We can just special case the primitives and do both lookups.

  4. jyn514 commented on Apr 8, 2021

    @jyn514
    MemberAuthor

    We can just special case the primitives and do both lookups.

    Sorry, I don't follow - what should happen if it's ambiguous (both resolve)?

  5. changed the title [-]Rustdoc doesn't warn if links to associated items are ambiguous[/-] [+]Rustdoc doesn't warn if links to associated items are ambiguous if primitives are involved[/+] on Apr 8, 2021
  6. jyn514 commented on Apr 8, 2021

    @jyn514
    MemberAuthor

    I would also be ok with saying "don't name modules after primitives" and closing this as WONTFIX, that seems confusing anyway.

  7. Manishearth commented on Apr 8, 2021

    @Manishearth
    Member

    I mean, don't name modules after primitives such that the names clash. Fine with wontfixing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)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