-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
rustdoc: Cleanup CacheBuilder
code for building search index
#128578
Conversation
Many of the code paths it handled were actually impossible. In other cases, the various checks and transformations were spread around in such a way that it was hard to tell what was going on.
0f96d56
to
220c2d8
Compare
I realized that these changes are actually completely independent, so this is no longer based on the |
This comment has been minimized.
This comment has been minimized.
Well that's weird... those tests passed locally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a suggested fix, along with a much longer comment for a remaining, ugly fact of the search engine builder:
diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs
index d2d0f5a4380..6454bc58cd6 100644
--- a/src/librustdoc/formats/cache.rs
+++ b/src/librustdoc/formats/cache.rs
@@ -486,10 +486,26 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
ParentStackItem::Type(item_id) => item_id.as_def_id(),
};
let Some(parent_did) = parent_did else { return };
- // The current stack not necessarily has correlation
- // for where the type was defined. On the other
- // hand, `paths` always has the right
- // information if present.
+ // The current stack reflects the CacheBuilder's recursive
+ // walk over HIR. For associated items, this is the module
+ // where the `impl` block is defined. That's an implementation
+ // detail that we don't want to affect the search engine.
+ //
+ // In particular, you can arrange things like this:
+ //
+ // #![crate_name="me"]
+ // mod private_mod {
+ // impl Clone for MyThing { fn clone(&self) -> MyThing { MyThing } }
+ // }
+ // pub struct MyThing;
+ //
+ // When that happens, we need to:
+ // - ignore the `cache.stripped_mod` flag, since the Clone impl is actually
+ // part of the public API even though it's defined in a private module
+ // - present the method as `me::MyThing::clone`, its publicly-visible path
+ // - deal with the fact that the recursive walk hasn't actually reached `MyThing`
+ // until it's already past `private_mod`, since that's first, and doesn't know
+ // yet if `MyThing` will actually be public or not (it could be re-exported)
match cache.paths.get(&parent_did) {
Some((fqp, _)) => (Some(parent_did), &fqp[..fqp.len() - 1]),
None => {
@@ -500,7 +516,8 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
}
_ => {
// Don't index if item is crate root, which is inserted later on when serializing the index.
- if item_def_id.is_crate_root() {
+ // Don't index if containing module is stripped (i.e., private),
+ if item_def_id.is_crate_root() || cache.stripped_mod {
return;
}
(None, &*cache.stack)
Co-authored-by: Michael Howell <[email protected]>
@bors r+ |
…riddle rustdoc: Cleanup `CacheBuilder` code for building search index This code was very convoluted and hard to reason about. It is now (I hope) much clearer and more suitable for both future enhancements and future cleanups. I'm doing this as a precursor, with no UI changes, to changing rustdoc to [ignore blanket impls][1] in type-based search. [1]: rust-lang#128471 (comment) r? `@notriddle`
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#128362 (add test for symbol visibility of `#[naked]` functions) - rust-lang#128526 (time.rs: remove "Basic usage text") - rust-lang#128531 (Miri: add a flag to do recursive validity checking) - rust-lang#128578 (rustdoc: Cleanup `CacheBuilder` code for building search index) - rust-lang#128589 (allow setting `link-shared` and `static-libstdcpp` with CI LLVM) - rust-lang#128615 (rustdoc: make the hover trail for doc anchors a bit bigger) - rust-lang#128620 (Update rinja version to 0.3.0) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#128305 (improve error message when `global_asm!` uses `asm!` operands) - rust-lang#128526 (time.rs: remove "Basic usage text") - rust-lang#128531 (Miri: add a flag to do recursive validity checking) - rust-lang#128578 (rustdoc: Cleanup `CacheBuilder` code for building search index) - rust-lang#128589 (allow setting `link-shared` and `static-libstdcpp` with CI LLVM) - rust-lang#128615 (rustdoc: make the hover trail for doc anchors a bit bigger) - rust-lang#128620 (Update rinja version to 0.3.0) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#128578 - camelid:cache-index-cleanup, r=notriddle rustdoc: Cleanup `CacheBuilder` code for building search index This code was very convoluted and hard to reason about. It is now (I hope) much clearer and more suitable for both future enhancements and future cleanups. I'm doing this as a precursor, with no UI changes, to changing rustdoc to [ignore blanket impls][1] in type-based search. [1]: rust-lang#128471 (comment) r? ``@notriddle``
This code was very convoluted and hard to reason about. It is now (I hope) much
clearer and more suitable for both future enhancements and future cleanups.
I'm doing this as a precursor, with no UI changes, to changing rustdoc to
ignore blanket impls in type-based search.
r? @notriddle