close
Skip to content

Deprioritize doc(hidden) re-exports in diagnostic paths#153630

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
arferreira:fix-doc-hidden-reexport-diagnostic-path
Apr 12, 2026
Merged

Deprioritize doc(hidden) re-exports in diagnostic paths#153630
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
arferreira:fix-doc-hidden-reexport-diagnostic-path

Conversation

@arferreira
Copy link
Copy Markdown
Contributor

@arferreira arferreira commented Mar 9, 2026

Fixes #153477.

This is the other half of #99698, which fixed the case where the parent module is #[doc(hidden)] but left the case where the re-export itself is #[doc(hidden)] as a FIXME (with a tracking test in dont-suggest-doc-hidden-variant-for-enum/hidden-child.rs).

The problem: when a crate does #[doc(hidden)] pub use core::error::Error, diagnostics pick up the hidden re-export path instead of the canonical one. For example, snafu::Error instead of std::error::Error.

Two changes:

In visible_parent_map, the add_child closure now checks whether the re-export itself is #[doc(hidden)] via reexport_chain and sends it to fallback_map, same treatment as doc-hidden parents and underscore re-exports.

should_encode_attrs now returns true for DefKind::Use. Without this, #[doc(hidden)] on use items was never written to crate metadata, so is_doc_hidden always returned false cross-crate. This was the actual root cause, the check in visible_parent_map alone isn't enough if the attribute isn't in the metadata.

The existing FIXME test now serves as the regression test. The .stderr goes from suggesting hidden_child::__private::Some(1i32) to just Some(1i32).

cc @eggyal

@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 Mar 9, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 9, 2026

r? @jackh726

rustbot has assigned @jackh726.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

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

@jackh726
Copy link
Copy Markdown
Member

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 12, 2026

📌 Commit 4d3f0db has been approved by jackh726

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 Apr 12, 2026
rust-bors Bot pushed a commit that referenced this pull request Apr 12, 2026
Rollup of 4 pull requests

Successful merges:

 - #155171 (Patch musl's CVE-2026-6042 and CVE-2026-40200)
 - #153630 (Deprioritize doc(hidden) re-exports in diagnostic paths)
 - #152613 (unsafe keyword docs: bring back unsafe_op_in_unsafe_fn lint discussion)
 - #155142 (impl const Residual for ControlFlow)
@rust-bors rust-bors Bot merged commit 56ecb15 into rust-lang:main Apr 12, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 12, 2026
rust-timer added a commit that referenced this pull request Apr 12, 2026
Rollup merge of #153630 - arferreira:fix-doc-hidden-reexport-diagnostic-path, r=jackh726

Deprioritize doc(hidden) re-exports in diagnostic paths

Fixes #153477.

This is the other half of #99698, which fixed the case where the *parent module* is `#[doc(hidden)]` but left the case where the re-export itself is `#[doc(hidden)]` as a FIXME (with a tracking test in `dont-suggest-doc-hidden-variant-for-enum/hidden-child.rs`).

The problem: when a crate does `#[doc(hidden)] pub use core::error::Error`, diagnostics pick up the hidden re-export path instead of the canonical one. For example, `snafu::Error` instead of `std::error::Error`.

Two changes:

In `visible_parent_map`, the `add_child` closure now checks whether the re-export itself is `#[doc(hidden)]` via `reexport_chain` and sends it to `fallback_map`, same treatment as doc-hidden parents and underscore re-exports.

`should_encode_attrs` now returns `true` for `DefKind::Use`. Without this, `#[doc(hidden)]` on `use` items was never written to crate metadata, so `is_doc_hidden` always returned `false` cross-crate. This was the actual root cause, the check in `visible_parent_map` alone isn't enough if the attribute isn't in the metadata.

The existing FIXME test now serves as the regression test. The `.stderr` goes from suggesting `hidden_child::__private::Some(1i32)` to just `Some(1i32)`.

cc @eggyal
@panstromek
Copy link
Copy Markdown
Contributor

perf triage:

Looks like this has caused a perf regression in #155185. Was this expected or is it somehow justified? Can we reduce the impact?

The impact doesn't seem that big to me (regressions are small and mostly in tiny secondary benchmarks), so I don't think it's worth a revert, but we shuold at least pay some attention to it.

This is probably caused by encoding more metadata. Detailed results show regressions are in metadata related queries. Some of it is also more calls to is_doc_hidden query, so maybe there's a way to call it less often?

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-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.

Name resolution is confusing when crates re-exports std items

5 participants