Skip to content

[rustdoc] Fix invalid jump to def link when #[rustc_allow_incoherent_impl] is involved - #163133

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
GuillaumeGomez:jump-to-def-incoherent
Sep 26, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
GuillaumeGomez:jump-to-def-incoherent

Conversation

@GuillaumeGomez

@GuillaumeGomez GuillaumeGomez commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

View all comments

Fixes #163112.

Problem here is that the method is not available in the crate where the type is defined. So def_path is actually problematic here as it resolves to the end item, which is not what we want. So instead, I made a simplified version of the rustc_middle::ty::print::pretty::try_print_visible_def_path_recur function.

It's also needed for #162808.

r? @Urgau

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Sep 21, 2026
@GuillaumeGomez GuillaumeGomez changed the title Fix invalid jump to def link when #[rustc_allow_incoherent_impl] is involved [rustdoc] Fix invalid jump to def link when #[rustc_allow_incoherent_impl] is involved Sep 21, 2026
Comment thread src/librustdoc/html/format.rs Outdated
Comment thread src/librustdoc/html/format.rs Outdated
// `#[rustc_allow_incoherent_impl]` and we need to keep the non-final item path.
// Sadly if we use `item_relative_path` which uses `def_path`, it renders the final
// item path and not the intermediate one.
&& let Some(fqp) = transitive_reexport_path(tcx, def_id)

@Urgau Urgau Sep 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just asking like this, but can't we always use transitive_reexport_path? maybe with a fallback to item_relative_path.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but it's likely much slower and also it would not link to the final item anymore if there are transitive crates.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also it would not link to the final item anymore if there are transitive crates.

Do we have a test case for this? If not we should add one.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the reexport ones I assume?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Applied suggestion.

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Applied it correctly this time. ^^'

@rust-bors

This comment has been minimized.

@rustbot

rustbot commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Fixed merge conflict.

@Urgau Urgau left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me with/without the question

View changes since this review

}

let visible_parent = visible_parent_map.get(&def_id).cloned()?;
if tcx.is_doc_hidden(visible_parent) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need/do we wantr to take into account --document-private-items here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too sure about that. I'll add a fixme comment so it's not forgotten and I'll try to find a case where it fails.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

@bors r=Urgau

@rust-bors

rust-bors Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 21c6277 has been approved by Urgau

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 25, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 25, 2026
…ent, r=Urgau

[rustdoc] Fix invalid jump to def link when `#[rustc_allow_incoherent_impl]` is involved

Fixes rust-lang#163112.

Problem here is that the method is not available in the crate where the type is defined. So `def_path` is actually problematic here as it resolves to the end item, which is not what we want. So instead, I made a simplified version of the `rustc_middle::ty::print::pretty::try_print_visible_def_path_recur` function.

It's also needed for rust-lang#162808.

r? @Urgau
rust-bors Bot pushed a commit that referenced this pull request Sep 25, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #162493 (Add support for -Zsanitizer-cfi-minimal-runtime)
 - #163133 ([rustdoc] Fix invalid jump to def link when `#[rustc_allow_incoherent_impl]` is involved)
 - #163215 (Fix suggestion for Option to bool with proper precedence handling)
 - #163266 (More deferred liveness cleanups)
 - #163274 (Support -Z merge-functions with gcc and add stack-protector asm tests)
 - #163312 (Add rustdoc regression test for glob import of a crate that re-exports)
 - #163332 (Add some docs to `Global`)
rust-bors Bot pushed a commit that referenced this pull request Sep 26, 2026
Rollup of 13 pull requests

Successful merges:

 - #160695 (Detect bad number of generics caused by bad derive)
 - #162883 (No longer auto-inline `f16` and `f128` on well-supported platforms)
 - #163133 ([rustdoc] Fix invalid jump to def link when `#[rustc_allow_incoherent_impl]` is involved)
 - #163215 (Fix suggestion for Option to bool with proper precedence handling)
 - #163266 (More deferred liveness cleanups)
 - #163274 (Support -Z merge-functions with gcc and add stack-protector asm tests)
 - #163290 (Merge `ForceWarning`/`Allow`/`Expect` into `Warning`)
 - #163298 (Don't emit sugg for pub-reexport extern std)
 - #163312 (Add rustdoc regression test for glob import of a crate that re-exports)
 - #163357 (Borrowck cleanups part trois)
 - #161710 (Stabilize `mem::conjure_zst`)
 - #163332 (Add some docs to `Global`)
 - #163362 (simplify ndk compiler test)
@rust-bors
rust-bors Bot merged commit 061c90a into rust-lang:main Sep 26, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 26, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 26, 2026
Rollup merge of #163133 - GuillaumeGomez:jump-to-def-incoherent, r=Urgau

[rustdoc] Fix invalid jump to def link when `#[rustc_allow_incoherent_impl]` is involved

Fixes #163112.

Problem here is that the method is not available in the crate where the type is defined. So `def_path` is actually problematic here as it resolves to the end item, which is not what we want. So instead, I made a simplified version of the `rustc_middle::ty::print::pretty::try_print_visible_def_path_recur` function.

It's also needed for #162808.

r? @Urgau
@GuillaumeGomez
GuillaumeGomez deleted the jump-to-def-incoherent branch September 26, 2026 16:13
pull Bot pushed a commit to LeeeeeeM/miri that referenced this pull request Sep 27, 2026
Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#160695 (Detect bad number of generics caused by bad derive)
 - rust-lang/rust#162883 (No longer auto-inline `f16` and `f128` on well-supported platforms)
 - rust-lang/rust#163133 ([rustdoc] Fix invalid jump to def link when `#[rustc_allow_incoherent_impl]` is involved)
 - rust-lang/rust#163215 (Fix suggestion for Option to bool with proper precedence handling)
 - rust-lang/rust#163266 (More deferred liveness cleanups)
 - rust-lang/rust#163274 (Support -Z merge-functions with gcc and add stack-protector asm tests)
 - rust-lang/rust#163290 (Merge `ForceWarning`/`Allow`/`Expect` into `Warning`)
 - rust-lang/rust#163298 (Don't emit sugg for pub-reexport extern std)
 - rust-lang/rust#163312 (Add rustdoc regression test for glob import of a crate that re-exports)
 - rust-lang/rust#163357 (Borrowck cleanups part trois)
 - rust-lang/rust#161710 (Stabilize `mem::conjure_zst`)
 - rust-lang/rust#163332 (Add some docs to `Global`)
 - rust-lang/rust#163362 (simplify ndk compiler test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[rustdoc] jump-to-def invalid link generated with #[rustc_allow_incoherent_impl]

4 participants