Skip to content

rustdoc: never link to unnamable items #143849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 1, 2025

Conversation

lolbinarycat
Copy link
Contributor

@lolbinarycat lolbinarycat commented Jul 12, 2025

fixes #143222

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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 Jul 12, 2025
@rust-log-analyzer

This comment has been minimized.

@lolbinarycat lolbinarycat force-pushed the rustdoc-priv-normalize-143222 branch from fb01811 to 950634d Compare July 12, 2025 20:05
@lolbinarycat lolbinarycat changed the title add regression test for RUST-143222 rustdoc: never link to unnamable items Jul 12, 2025
@lolbinarycat lolbinarycat marked this pull request as ready for review July 13, 2025 17:18
@rustbot
Copy link
Collaborator

rustbot commented Jul 13, 2025

r? @GuillaumeGomez

rustbot has assigned @GuillaumeGomez.
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

@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 Jul 13, 2025
type Ty = Bar;
}
pub struct Bar;
};
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to have this as a dependency for this test? Can't it be done within the current crate?

Copy link
Member

Choose a reason for hiding this comment

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

Also, what happens if the const is named X?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The bug only happens during cross-crate re-exports. Otherwise a separate failsafe kicks in.

I was under the impression that the _ was a delibraerately injected placeholder, but maybe it is just the constant name, if so we'll need a more principled approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, yeah, you're right, my assumptions were wrong. Just looking at the path isn't enough.

Copy link
Member

Choose a reason for hiding this comment

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

Need to check what kind of item (block more precisely) the parent is. If it's not a module, then it's likely wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

any idea what datastructure would retain that info in the cross-crate case? I'm somewhat struggling to understand how we even reconstruct path info and such from an rlib.

Copy link
Member

Choose a reason for hiding this comment

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

Path doesn't matter here, you need to check what is its parent.

@rust-log-analyzer

This comment has been minimized.

@lolbinarycat lolbinarycat force-pushed the rustdoc-priv-normalize-143222 branch from ef5c252 to 0952022 Compare July 15, 2025 21:14
/// Checks if the given defid refers to an item that is unnamable, such as one defined in a const block.
fn is_unnamable(tcx: TyCtxt<'_>, did: DefId) -> bool {
let mut cur_did = did;
while let Some(parent) = tcx.opt_parent(cur_did) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this code is wrong: we can link to an impl associated item even if the impl is in a const/function block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, i think impls should break with a return false and only modules should continue up...

well technically we can only link to an impl item if the thing being impl'd on is nameable, but i'm not sure if that's something observable.

Copy link
Member

Choose a reason for hiding this comment

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

Just discovered that we can have modules in any blocks. Dark magic. XD

Copy link
Member

@GuillaumeGomez GuillaumeGomez Jul 16, 2025

Choose a reason for hiding this comment

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

Also, if the item is not public, it'll be stripped so should be fine. (for impl block as parents)

@lolbinarycat lolbinarycat force-pushed the rustdoc-priv-normalize-143222 branch from 0952022 to aab9c69 Compare July 19, 2025 19:27
@lolbinarycat lolbinarycat force-pushed the rustdoc-priv-normalize-143222 branch from aab9c69 to 05a62c8 Compare July 22, 2025 22:11
@GuillaumeGomez
Copy link
Member

Thanks for the fix!

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jul 31, 2025

📌 Commit 05a62c8 has been approved by GuillaumeGomez

It is now in the queue for this repository.

@bors bors 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 Jul 31, 2025
bors added a commit that referenced this pull request Aug 1, 2025
Rollup of 7 pull requests

Successful merges:

 - #143849 (rustdoc: never link to unnamable items)
 - #144683 (Simplify library dependencies on `compiler-builtins`)
 - #144691 (Extend `is_case_difference` to handle digit-letter confusables)
 - #144700 (rustdoc-json: Move `#[macro_export]` from `Other` to it's own  variant)
 - #144751 (Add correct dynamic_lib_extension for aix)
 - #144757 (Ping Muscraft when emitter change)
 - #144759 (triagebot: Label `compiler-builtins` T-libs)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e6b80f3 into rust-lang:master Aug 1, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Aug 1, 2025
rust-timer added a commit that referenced this pull request Aug 1, 2025
Rollup merge of #143849 - lolbinarycat:rustdoc-priv-normalize-143222, r=GuillaumeGomez

rustdoc: never link to unnamable items

fixes #143222
@panstromek
Copy link
Contributor

Ping from triage:

Looks like this PR introduced a regression in #144768.

Based on detailed results, the regression is in the def_kind query which this PR uses. The number of invocations is increased by 10-20% on some benchmarks.

Is this regression expected or justified?

@GuillaumeGomez
Copy link
Member

I expected a regression, but not this big. I'll revert the PR for now and we can iterate over the performance improvement.

@panstromek
Copy link
Contributor

panstromek commented Aug 4, 2025

Ok. It doesn't seem that big to require a revert to me, so just to make sure I didn't add confusion here: 10%-20% change
is on the number of def_kind invocations, but the overall regression is around 0.5% on a few doc benchmarks.

Here's the perf run: https://perf.rust-lang.org/compare.html?start=6c02dd4eae83befde07dc4782395e2005055e9fa&end=e3ee7f7aea5b45af3b42b5e4713da43876a65ac9&stat=instructions:u

@GuillaumeGomez
Copy link
Member

Ah I see. Didn't check the report yet so spoke too quickly. Still, we will need to bring down the numbers. :)

@lolbinarycat
Copy link
Contributor Author

Obvious ideas optimizations:

  • only run this when -Znormalize-docs is enabled
  • only run this on types that have been normalized or are being normalized

the former is much easier to implement, but the perf improvement would go away if we ever make normalizing docs the default. the latter should actually be a substantial improvement, but is slightly trickier to implement. I'll see what i can do.

@GuillaumeGomez
Copy link
Member

That's a good start already. I also thought about caching this query with compiler queries.

@lolbinarycat
Copy link
Contributor Author

I suppose caching would improve things if an item is being linked to from multiple locations, but i do think it would be more ideal to try to simply disable normalization when it would cause a situation like this.

@GuillaumeGomez
Copy link
Member

I meant that in addition to your ideas. I'd like your suggestions to be implemented first, and then we'll see if we need to go further. I'll let you implement your ideas and then we can check perf results on them.

@lolbinarycat
Copy link
Contributor Author

Making it a query would also cache it across incremental builds, right? that might be worth it.

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.

Not Found error for the hyperlink from rustc_middle::ty::TypeFlags to InternalBitFlags
6 participants