Skip to content

Conversation

@ncrothers
Copy link
Contributor

Fixes #8487, which points out a difference between how rustdoc and rust-analyzer rewrites intra-doc links in the markdown. rust-analyzer currently does not properly add the anchor to reference items associated with a type, such as struct fields or methods in an impl block.

This PR implements the fix to add the appropriate anchor for the associated item at the end of the URL, becoming aligned with how rustdoc handles it.

  • rewrite_intra_doc_link
    • If no anchor is provided for the link, falls back on the fragment from filename_and_frag_for_def
  • filename_and_frag_for_def
    • Modify Definition::Variant to follow the same procedure as Definition::Field, early returning with the fragment specified
  • doc_links::tests
    • Add a test to validate rewriting for all types of associated items (fields, methods, trait methods, associated constants, associated types)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 27, 2025
@ncrothers ncrothers force-pushed the add-anchor-for-associated-items branch from d069396 to 15207a0 Compare February 27, 2025 22:39
@Veykril Veykril added this pull request to the merge queue Feb 28, 2025
@Veykril
Copy link
Member

Veykril commented Feb 28, 2025

Thanks!

Merged via the queue into rust-lang:master with commit 2cc3682 Feb 28, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

intra-doc links: Link to method is not recognized

3 participants