Skip to content

rustdoc: Inline code in links in first paragraph of doc of trait implementation not clickable #140857

Closed
@SpecificProtagonist

Description

@SpecificProtagonist

Any inline code in a link in the first paragraph of the documentation of an implementation of a trait with at least one item isn't clickable.

MRE:

struct Type;

trait Trait {
    const ITEM: () = ();
}

/// [`i32`]
///
/// [`i32`]
impl Trait for Type {}

I expected to see this happen:

In the documentation generated by cargo doc, both links should be clickable.

Instead, this happened:

Unless JS is disabled, clicking on the top link does nothing.

Meta

rustc --version:

rustc 1.88.0-nightly (d5b4c2e4f 2025-04-02)

The cause seems to be this event listener, which is added to the impl's summary and doesn't account for the fact that inline code is allowed inside Markdown links:

onEachLazy(document.querySelectorAll(".toggle > summary:not(.hideme)"), el => {
    // @ts-expect-error
    el.addEventListener("click", e => {
        if (e.target.tagName !== "SUMMARY" && e.target.tagName !== "A") {
            e.preventDefault();
        }
    });
});

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