Skip to content

rustdoc creates incorrect link in repeated macro invocation containing an inlined re-export with docstring #144965

@mgeier

Description

@mgeier

I know this is a niche situation, but encountered this in some macro-heavy code I actually would like to write.

Code

#[doc(hidden)]
pub struct MyStruct;

macro_rules! my_macro {
    () => {
        pub fn my_function() {}

        /// Incorrect: [`my_function()`].
        #[doc(inline)]
        pub use $crate::MyStruct;

        /// Correct: [`my_function()`].
        pub struct AnotherStruct;
    };
}

pub mod one {
    my_macro!();
}

pub mod two {
    my_macro!();
}

Reproduction Steps

Run rustdoc, look at the documentation of module two.

Expected Outcome

Both links in module two should link to two::my_function.

Actual Output

The docstring of the re-exported struct in module two links to one::my_function.

Version

rustdoc 1.88.0 (6b00bc388 2025-06-23)

Metadata

Metadata

Assignees

Labels

A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by nameA-local-reexportsArea: Documentation that has been locally re-exported (i.e., non-cross-crate)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-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