Skip to content

fix: Do not stop visible_parent_map breadth-first search reaching children of #[doc(hidden)] modules - #159881

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
zalanlevai:fix-incomplete-visible-parent-map
Aug 2, 2026
Merged

fix: Do not stop visible_parent_map breadth-first search reaching children of #[doc(hidden)] modules#159881
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
zalanlevai:fix-incomplete-visible-parent-map

Conversation

@zalanlevai

@zalanlevai zalanlevai commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

The visible_parent_map query misses putting the child items of #[doc(hidden)] modules into the queue, resulting in the breadth-first search missing them entirely. This results in inconsistent path printing behavior affecting diagnostics: namely that re-exports nested deeply within #[doc(hidden)] modules are not considered as a possible fallback path. See the linked issue (#159880) for more details and an example of how this manifests in diagnostics.

This PR makes sure that #[doc(hidden)] parents in the fallback map are still searched as part of the breadth-first search.

Fixes #159880.

The two tests for this change are based on the inconsistent diagnostics shown in the issue:

  • tests/ui/suggestions/suggest-path-through-direct-dep-crate/hidden-reexport-of-transitive-dep-item.rs captures the current, expected behavior in the already working base case where the hidden module is still recorded in the fallback map;
  • tests/ui/suggestions/suggest-path-through-direct-dep-crate/hidden-reexport-of-nested-transitive-dep-item.rs is a regression test for the breadth-first search covering nested children of #[doc(hidden)] modules to populate the fallback map by testing whether the diagnostic prefers the hidden but accessible path through the direct dependency crate.

Related PRs/issues:

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 25, 2026
@rustbot

rustbot commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @fee1-dead (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 74 candidates
  • Random selection from 16 candidates

@zalanlevai

Copy link
Copy Markdown
Contributor Author

@rustbot label +A-diagnostics +A-visibility

fn main() {
let _: direct_dep::__private::inner::Struct = Struct;
//~^ ERROR mismatched types
//~| NOTE expected `direct_dep::__private::inner::Struct`, found `Struct`

@fee1-dead fee1-dead Aug 1, 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.

I think what you want here is //~| LABEL. Also it might just be okay adding the rest of the //~| NOTE too.

View changes since the review

@zalanlevai zalanlevai Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is //~| LABEL a valid diagnostic kind (more accurately LABEL itself)? When I tried making the following change:

diff --git a/tests/ui/suggestions/suggest-path-through-direct-dep-crate/hidden-reexport-of-nested-transitive-dep-item.rs b/tests/ui/suggestions/suggest-path-through-direct-dep-crate/hidden-reexport-of-nested-transitive-dep-item.rs
index f8d2f36dc39..305a340cbaf 100644
--- a/tests/ui/suggestions/suggest-path-through-direct-dep-crate/hidden-reexport-of-nested-transitive-dep-item.rs
+++ b/tests/ui/suggestions/suggest-path-through-direct-dep-crate/hidden-reexport-of-nested-transitive-dep-item.rs
@@ -9,5 +9,5 @@
 fn main() {
     let _: direct_dep::__private::inner::Struct = Struct;
     //~^ ERROR mismatched types
-    //~| NOTE expected `direct_dep::__private::inner::Struct`, found `Struct`
+    //~| LABEL expected `direct_dep::__private::inner::Struct`, found `Struct`
 }

I get the following error from compiletest:

error: 1 diagnostics expected in test file but not reported in JSON output
<...>: UNKNOWN: LABEL expected `direct_dep::__private::inner::Struct`, found `Struct`
  reported with different kind: NOTE with different message: expected `direct_dep::__private::inner::Struct`, found `Struct`

Which reads to me like compiletest recognises that diagnostic as a NOTE.

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.

Oh, I must have misremembered. Yes, just using NOTE for all of these should be fine.

Entry::Vacant(entry) => {
entry.insert(parent);
if fallback {
fallback_map.push((def_id, parent));

@fee1-dead fee1-dead Aug 1, 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.

add a note here that we aren't returning early because we still want to do more BFS of its children.

View changes since the review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 1, 2026
@rustbot

rustbot commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@fee1-dead

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 1, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 1, 2026
… r=<try>

fix: Do not stop `visible_parent_map` breadth-first search reaching children of `#[doc(hidden)]` modules
@zalanlevai
zalanlevai force-pushed the fix-incomplete-visible-parent-map branch from bc5b71e to e5b6364 Compare August 1, 2026 18:57
@zalanlevai

Copy link
Copy Markdown
Contributor Author

I added the requested comment on not returning early and the rest of the diagnostic parts I omitted from the UI tests (I did it for both files, as it was the same kind of change). The only request I could not apply was changing NOTE to LABEL for the expected $PATH, found Struct diagnostics. See #159881 (comment).

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 1, 2026
@rust-bors

rust-bors Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 2e60bec (2e60bec4054dc1ceccef03706c2767908415860a)
Base parent: b430378 (b430378746a835fd5240e2c7169795d7de0547e8)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (2e60bec): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

Results (primary 0.7%, secondary 0.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.1% [0.4%, 2.3%] 3
Regressions ❌
(secondary)
0.5% [0.4%, 1.2%] 10
Improvements ✅
(primary)
-0.6% [-0.6%, -0.6%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.7% [-0.6%, 2.3%] 4

Cycles

Results (primary 0.2%, secondary 0.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.0% [0.4%, 2.5%] 6
Regressions ❌
(secondary)
2.7% [0.6%, 8.6%] 6
Improvements ✅
(primary)
-0.8% [-1.3%, -0.4%] 5
Improvements ✅
(secondary)
-1.0% [-2.3%, -0.4%] 10
All ❌✅ (primary) 0.2% [-1.3%, 2.5%] 11

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 489.711s -> 489.974s (0.05%)
Artifact size: 390.35 MiB -> 390.39 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 1, 2026
@fee1-dead

Copy link
Copy Markdown
Member

Thank you so much! Looks good to me.

@bors r+ rollup

@rust-bors

rust-bors Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

📌 Commit e5b6364 has been approved by fee1-dead

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 Aug 2, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 2, 2026
…parent-map, r=fee1-dead

fix: Do not stop `visible_parent_map` breadth-first search reaching children of `#[doc(hidden)]` modules

The `visible_parent_map` query misses putting the child items of `#[doc(hidden)]` modules into the queue, resulting in the breadth-first search missing them entirely. This results in inconsistent path printing behavior affecting diagnostics: namely that re-exports nested deeply within `#[doc(hidden)]` modules are not considered as a possible fallback path. See the linked issue (rust-lang#159880) for more details and an example of how this manifests in diagnostics.

This PR makes sure that `#[doc(hidden)]` parents in the fallback map are still searched as part of the breadth-first search.

Fixes rust-lang#159880.

The two tests for this change are based on the inconsistent diagnostics shown in the issue:
* `tests/ui/suggestions/suggest-path-through-direct-dep-crate/hidden-reexport-of-transitive-dep-item.rs` captures the current, expected behavior in the already working base case where the hidden module is still recorded in the fallback map;
* `tests/ui/suggestions/suggest-path-through-direct-dep-crate/hidden-reexport-of-nested-transitive-dep-item.rs` is a regression test for the breadth-first search covering nested children of `#[doc(hidden)]` modules to populate the fallback map by testing whether the diagnostic prefers the hidden but accessible path through the direct dependency crate.

Related PRs/issues:
* rust-lang#87349
* rust-lang#153477
rust-bors Bot pushed a commit that referenced this pull request Aug 2, 2026
Rollup of 6 pull requests

Successful merges:

 - #156527 (Move `std::io` tests to `alloctests` & add prelude)
 - #159525 (Stabilize passing 128-bit integers via vector registers with `asm!` on x86)
 - #160342 (Specialize `advance_by` method of `Fuse`)
 - #106643 (Allow only implementing `Read::read_buf`)
 - #159729 (allocations are allowed to grow (but not shrink))
 - #159881 (fix: Do not stop `visible_parent_map` breadth-first search reaching children of `#[doc(hidden)]` modules)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 2, 2026
…parent-map, r=fee1-dead

fix: Do not stop `visible_parent_map` breadth-first search reaching children of `#[doc(hidden)]` modules

The `visible_parent_map` query misses putting the child items of `#[doc(hidden)]` modules into the queue, resulting in the breadth-first search missing them entirely. This results in inconsistent path printing behavior affecting diagnostics: namely that re-exports nested deeply within `#[doc(hidden)]` modules are not considered as a possible fallback path. See the linked issue (rust-lang#159880) for more details and an example of how this manifests in diagnostics.

This PR makes sure that `#[doc(hidden)]` parents in the fallback map are still searched as part of the breadth-first search.

Fixes rust-lang#159880.

The two tests for this change are based on the inconsistent diagnostics shown in the issue:
* `tests/ui/suggestions/suggest-path-through-direct-dep-crate/hidden-reexport-of-transitive-dep-item.rs` captures the current, expected behavior in the already working base case where the hidden module is still recorded in the fallback map;
* `tests/ui/suggestions/suggest-path-through-direct-dep-crate/hidden-reexport-of-nested-transitive-dep-item.rs` is a regression test for the breadth-first search covering nested children of `#[doc(hidden)]` modules to populate the fallback map by testing whether the diagnostic prefers the hidden but accessible path through the direct dependency crate.

Related PRs/issues:
* rust-lang#87349
* rust-lang#153477
rust-bors Bot pushed a commit that referenced this pull request Aug 2, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #159906 (Semantic check of `mut` restrictions)
 - #156527 (Move `std::io` tests to `alloctests` & add prelude)
 - #159525 (Stabilize passing 128-bit integers via vector registers with `asm!` on x86)
 - #160342 (Specialize `advance_by` method of `Fuse`)
 - #160358 (borrowck: Simplify deps to build compiler 30s faster)
 - #160375 (miri subtree update)
 - #106643 (Allow only implementing `Read::read_buf`)
 - #159499 (tests: prefer max-llvm-major-version over open LLVM ranges)
 - #159729 (allocations are allowed to grow (but not shrink))
 - #159881 (fix: Do not stop `visible_parent_map` breadth-first search reaching children of `#[doc(hidden)]` modules)
 - #160189 (Move codegen_stmt_debuginfo to debuginfo.rs)
 - #160356 (Add more tests for `must_implement_one_of`)
@rust-bors
rust-bors Bot merged commit d982e2e into rust-lang:main Aug 2, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Aug 2, 2026
rust-timer added a commit that referenced this pull request Aug 2, 2026
Rollup merge of #159881 - zalanlevai:fix-incomplete-visible-parent-map, r=fee1-dead

fix: Do not stop `visible_parent_map` breadth-first search reaching children of `#[doc(hidden)]` modules

The `visible_parent_map` query misses putting the child items of `#[doc(hidden)]` modules into the queue, resulting in the breadth-first search missing them entirely. This results in inconsistent path printing behavior affecting diagnostics: namely that re-exports nested deeply within `#[doc(hidden)]` modules are not considered as a possible fallback path. See the linked issue (#159880) for more details and an example of how this manifests in diagnostics.

This PR makes sure that `#[doc(hidden)]` parents in the fallback map are still searched as part of the breadth-first search.

Fixes #159880.

The two tests for this change are based on the inconsistent diagnostics shown in the issue:
* `tests/ui/suggestions/suggest-path-through-direct-dep-crate/hidden-reexport-of-transitive-dep-item.rs` captures the current, expected behavior in the already working base case where the hidden module is still recorded in the fallback map;
* `tests/ui/suggestions/suggest-path-through-direct-dep-crate/hidden-reexport-of-nested-transitive-dep-item.rs` is a regression test for the breadth-first search covering nested children of `#[doc(hidden)]` modules to populate the fallback map by testing whether the diagnostic prefers the hidden but accessible path through the direct dependency crate.

Related PRs/issues:
* #87349
* #153477
This was referenced Aug 4, 2026
WhySoBad pushed a commit to WhySoBad/miri that referenced this pull request Aug 5, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#159906 (Semantic check of `mut` restrictions)
 - rust-lang/rust#156527 (Move `std::io` tests to `alloctests` & add prelude)
 - rust-lang/rust#159525 (Stabilize passing 128-bit integers via vector registers with `asm!` on x86)
 - rust-lang/rust#160342 (Specialize `advance_by` method of `Fuse`)
 - rust-lang/rust#160358 (borrowck: Simplify deps to build compiler 30s faster)
 - rust-lang/rust#160375 (miri subtree update)
 - rust-lang/rust#106643 (Allow only implementing `Read::read_buf`)
 - rust-lang/rust#159499 (tests: prefer max-llvm-major-version over open LLVM ranges)
 - rust-lang/rust#159729 (allocations are allowed to grow (but not shrink))
 - rust-lang/rust#159881 (fix: Do not stop `visible_parent_map` breadth-first search reaching children of `#[doc(hidden)]` modules)
 - rust-lang/rust#160189 (Move codegen_stmt_debuginfo to debuginfo.rs)
 - rust-lang/rust#160356 (Add more tests for `must_implement_one_of`)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 6, 2026
…fallback-entry-check, r=oli-obk

fix: Check the fallback map before queueing child in `visible_parent_map` breadth-first search

The fix in rust-lang#159881 extended the `visible_parent_map` breadth-first search (BFS) to include items nested within "fallback" items, such as `#[doc(hidden)]` modules and re-exports. However, the fix resulted in fallback entries not being checked before enqueueing new items into the BFS, resulting in fallback items being explored in the BFS multiple times, once for each fallback parent, up until a non-fallback visible parent is found instead, if any.

This PR adds a check before new fallback items are recorded and the BFS queue is extended that ensures that the item has not already been searched through a fallback parent item.

Fixes the `libc` performance regression described in rust-lang#160439. (Fixes rust-lang#160439.)

Unfortunately, I could not think of a way to write a test case that covers the regression that this PR fixes, as it would require a massive crate with a very large number of "fallback" parents, and the test would be performance-based.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 6, 2026
…fallback-entry-check, r=oli-obk

fix: Check the fallback map before queueing child in `visible_parent_map` breadth-first search

The fix in rust-lang#159881 extended the `visible_parent_map` breadth-first search (BFS) to include items nested within "fallback" items, such as `#[doc(hidden)]` modules and re-exports. However, the fix resulted in fallback entries not being checked before enqueueing new items into the BFS, resulting in fallback items being explored in the BFS multiple times, once for each fallback parent, up until a non-fallback visible parent is found instead, if any.

This PR adds a check before new fallback items are recorded and the BFS queue is extended that ensures that the item has not already been searched through a fallback parent item.

Fixes the `libc` performance regression described in rust-lang#160439. (Fixes rust-lang#160439.)

Unfortunately, I could not think of a way to write a test case that covers the regression that this PR fixes, as it would require a massive crate with a very large number of "fallback" parents, and the test would be performance-based.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 6, 2026
…fallback-entry-check, r=oli-obk

fix: Check the fallback map before queueing child in `visible_parent_map` breadth-first search

The fix in rust-lang#159881 extended the `visible_parent_map` breadth-first search (BFS) to include items nested within "fallback" items, such as `#[doc(hidden)]` modules and re-exports. However, the fix resulted in fallback entries not being checked before enqueueing new items into the BFS, resulting in fallback items being explored in the BFS multiple times, once for each fallback parent, up until a non-fallback visible parent is found instead, if any.

This PR adds a check before new fallback items are recorded and the BFS queue is extended that ensures that the item has not already been searched through a fallback parent item.

Fixes the `libc` performance regression described in rust-lang#160439. (Fixes rust-lang#160439.)

Unfortunately, I could not think of a way to write a test case that covers the regression that this PR fixes, as it would require a massive crate with a very large number of "fallback" parents, and the test would be performance-based.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 6, 2026
…fallback-entry-check, r=oli-obk

fix: Check the fallback map before queueing child in `visible_parent_map` breadth-first search

The fix in rust-lang#159881 extended the `visible_parent_map` breadth-first search (BFS) to include items nested within "fallback" items, such as `#[doc(hidden)]` modules and re-exports. However, the fix resulted in fallback entries not being checked before enqueueing new items into the BFS, resulting in fallback items being explored in the BFS multiple times, once for each fallback parent, up until a non-fallback visible parent is found instead, if any.

This PR adds a check before new fallback items are recorded and the BFS queue is extended that ensures that the item has not already been searched through a fallback parent item.

Fixes the `libc` performance regression described in rust-lang#160439. (Fixes rust-lang#160439.)

Unfortunately, I could not think of a way to write a test case that covers the regression that this PR fixes, as it would require a massive crate with a very large number of "fallback" parents, and the test would be performance-based.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 6, 2026
…fallback-entry-check, r=oli-obk

fix: Check the fallback map before queueing child in `visible_parent_map` breadth-first search

The fix in rust-lang#159881 extended the `visible_parent_map` breadth-first search (BFS) to include items nested within "fallback" items, such as `#[doc(hidden)]` modules and re-exports. However, the fix resulted in fallback entries not being checked before enqueueing new items into the BFS, resulting in fallback items being explored in the BFS multiple times, once for each fallback parent, up until a non-fallback visible parent is found instead, if any.

This PR adds a check before new fallback items are recorded and the BFS queue is extended that ensures that the item has not already been searched through a fallback parent item.

Fixes the `libc` performance regression described in rust-lang#160439. (Fixes rust-lang#160439.)

Unfortunately, I could not think of a way to write a test case that covers the regression that this PR fixes, as it would require a massive crate with a very large number of "fallback" parents, and the test would be performance-based.
rust-timer added a commit that referenced this pull request Aug 6, 2026
Rollup merge of #160464 - zalanlevai:fix-visible-parent-map-fallback-entry-check, r=oli-obk

fix: Check the fallback map before queueing child in `visible_parent_map` breadth-first search

The fix in #159881 extended the `visible_parent_map` breadth-first search (BFS) to include items nested within "fallback" items, such as `#[doc(hidden)]` modules and re-exports. However, the fix resulted in fallback entries not being checked before enqueueing new items into the BFS, resulting in fallback items being explored in the BFS multiple times, once for each fallback parent, up until a non-fallback visible parent is found instead, if any.

This PR adds a check before new fallback items are recorded and the BFS queue is extended that ensures that the item has not already been searched through a fallback parent item.

Fixes the `libc` performance regression described in #160439. (Fixes #160439.)

Unfortunately, I could not think of a way to write a test case that covers the regression that this PR fixes, as it would require a massive crate with a very large number of "fallback" parents, and the test would be performance-based.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-diagnostics Area: Messages for errors, warnings, and lints A-visibility Area: Visibility / privacy S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent path to item in transitive dependency crate in diagnostic when the re-export is #[doc(hidden)]

4 participants