about summary refs log tree commit diff
path: root/src/librustdoc/formats/cache.rs
AgeCommit message (Collapse)AuthorLines
2023-11-25is_{some,ok}_and for rustdocMichael Goulet-4/+4
2023-11-19rustdoc-search: add support for associated typesMichael Howell-0/+1
2023-11-15Re-format code with new rustfmtMark Rousskov-11/+16
2023-10-22rustdoc: use JS to inline target type impl docs into aliasMichael Howell-2/+2
This is an attempt to balance three problems, each of which would be violated by a simpler implementation: - A type alias should show all the `impl` blocks for the target type, and vice versa, if they're applicable. If nothing was done, and rustdoc continues to match them up in HIR, this would not work. - Copying the target type's docs into its aliases' HTML pages directly causes far too much redundant HTML text to be generated when a crate has large numbers of methods and large numbers of type aliases. - Using JavaScript exclusively for type alias impl docs would be a functional regression, and could make some docs very hard to find for non-JS readers. - Making sure that only applicable docs are show in the resulting page requires a type checkers. Do not reimplement the type checker in JavaScript. So, to make it work, rustdoc stashes these type-alias-inlined docs in a JSONP "database-lite". The file is generated in `write_shared.rs`, included in a `<script>` tag added in `print_item.rs`, and `main.js` takes care of patching the additional docs into the DOM. The format of `trait.impl` and `type.impl` JS files are superficially similar. Each line, except the JSONP wrapper itself, belongs to a crate, and they are otherwise separate (rustdoc should be idempotent). The "meat" of the file is HTML strings, so the frontend code is very simple. Links are relative to the doc root, though, so the frontend needs to fix that up, and inlined docs can reuse these files. However, there are a few differences, caused by the sophisticated features that type aliases have. Consider this crate graph: ```text --------------------------------- | crate A: struct Foo<T> | | type Bar = Foo<i32> | | impl X for Foo<i8> | | impl Y for Foo<i32> | --------------------------------- | ---------------------------------- | crate B: type Baz = A::Foo<i8> | | type Xyy = A::Foo<i8> | | impl Z for Xyy | ---------------------------------- ``` The type.impl/A/struct.Foo.js JS file has a structure kinda like this: ```js JSONP({ "A": [["impl Y for Foo<i32>", "Y", "A::Bar"]], "B": [["impl X for Foo<i8>", "X", "B::Baz", "B::Xyy"], ["impl Z for Xyy", "Z", "B::Baz"]], }); ``` When the type.impl file is loaded, only the current crate's docs are actually used. The main reason to bundle them together is that there's enough duplication in them for DEFLATE to remove the redundancy. The contents of a crate are a list of impl blocks, themselves represented as lists. The first item in the sublist is the HTML block, the second item is the name of the trait (which goes in the sidebar), and all others are the names of type aliases that successfully match. This way: - There's no need to generate these files for types that have no aliases in the current crate. If a dependent crate makes a type alias, it'll take care of generating its own docs. - There's no need to reimplement parts of the type checker in JavaScript. The Rust backend does the checking, and includes its results in the file. - Docs defined directly on the type alias are dropped directly in the HTML by `render_assoc_items`, and are accessible without JavaScript. The JSONP file will not list impl items that are known to be part of the main HTML file already. [JSONP]: https://en.wikipedia.org/wiki/JSONP
2023-10-11Handle private dep at the same level as masked cratesGuillaume Gomez-15/+10
2023-10-11Prevent showing methods from blanket impls of not available foreign traits ↵Guillaume Gomez-1/+13
to show up in the search results
2023-09-21rustdoc-search: add impl disambiguator to duplicate assoc itemsMichael Howell-0/+13
Helps with #90929 This changes the search results, specifically, when there's more than one impl with an associated item with the same name. For example, the search queries `simd<i8> -> simd<i8>` and `simd<i64> -> simd<i64>` don't link to the same function, but most of the functions have the same names. This change should probably be FCP-ed, especially since it adds a new anchor link format for `main.js` to handle, so that URLs like `struct.Vec.html#impl-AsMut<[T]>-for-Vec<T,+A>/method.as_mut` redirect to `struct.Vec.html#method.as_mut-2`. It's a strange design, but there are a few reasons for it: * I'd like to avoid making the HTML bigger. Obviously, fixing this bug is going to add at least a little more data to the search index, but adding more HTML penalises viewers for the benefit of searchers. * Breaking `struct.Vec.html#method.len` would also be a disappointment. On the other hand: * The path-style anchors might be less prone to link rot than the numbered anchors. It's definitely less likely to have URLs that appear to "work", but silently point at the wrong thing. * This commit arranges the path-style anchor to redirect to the numbered anchor. Nothing stops rustdoc from doing the opposite, making path-style anchors the default and redirecting the "legacy" numbered ones.
2023-09-21rustdoc: use let chain in `CacheBuilder::fold_item`Michael Howell-31/+29
2023-08-26rustdoc: bind typedef inner type items to the folding systemUrgau-0/+1
This let's us handle a multitude of things for free: - #[doc(hidden)] - private fields/variants - --document-private-items - --document-hidden-items And correct in the process the determination of "has stripped items" by doing the same logic done by other ones.
2023-08-21rustdoc: Rename `clean` items from typedef to type aliasNoah Lev-1/+1
2023-07-18Auto merge of #113574 - GuillaumeGomez:rustdoc-json-strip-hidden-impl, ↵bors-2/+5
r=aDotInTheVoid,notriddle Strip impl if not re-exported and is doc(hidden) Part of #112852. r? `@aDotInTheVoid`
2023-07-14Correctly handle `--document-hidden-items`Guillaume Gomez-2/+5
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-1/+1
2023-06-20Fix invalid creation of files in rustdocGuillaume Gomez-0/+5
2023-05-27Rollup merge of #112018 - GuillaumeGomez:cleanup-tcx, r=notriddleMatthias Krüger-1/+1
Clean up usage of `cx.tcx` when `tcx` is already set into a variable I discovered a few cases where `cx.tcx` (and equivalents) was used whereas `tcx` was already stored into a variable. In those cases, better to just use `tcx` directly. r? `@notriddle`
2023-05-27Clean up usage of `cx.tcx` when `tcx` is already set into a variableGuillaume Gomez-1/+1
2023-05-22rustdoc: Cleanup doc string collapsingVadim Petrochenkov-3/+2
2023-05-05Correctly handle associated items of a trait inside a `#[doc(hidden)]` itemGuillaume Gomez-1/+7
2023-04-16fix clippy::toplevel_ref_arg and ::manual_mapMatthias Krüger-4/+3
2023-04-02rustdoc: fix quadratic time in intra-doc link passJacob Hoffman-Andrews-2/+2
In the collect_intra_doc_links pass, links to a given item that occurred repeatedly were getting inserted into a Vec<clean::ItemLink> repeatedly. This led to n^2 behavior (where n = the number of pages generated), particularly for the intra-doc link on the `Into<U> for T where U: From<T>` blanket implementation, since that link appears on every single struct page.
2023-03-11Rollup merge of #107629 - pitaj:rustdoc-search-deprecated, r=jshaMatthias Krüger-0/+1
rustdoc: sort deprecated items lower in search closes #98759 ### Screenshots `i32::MAX` show sup above `std::i32::MAX` and `core::i32::MAX` ![image](https://user-images.githubusercontent.com/803701/216725619-40afb7b0-e984-4a2e-ab5b-a95b24736b0e.png) If just searching for `min`, the deprecated results show up far below other things: ![image](https://user-images.githubusercontent.com/803701/216725672-e4325d37-9bfe-47eb-a1fe-0e57092aa811.png) one page later ![image](https://user-images.githubusercontent.com/803701/216725932-cd1c4a42-d527-44fb-a4ab-5a6d243659cc.png) ~~And, as you can see, the "Deprecation planned" message shows up in the search results. The same is true for fully-deprecated items like `mem::uninitialized`: ![image](https://user-images.githubusercontent.com/803701/216726268-1657e77a-563f-45a0-85a7-3a0cf4d66d6f.png)~~ Edit: the deprecation message change was removed from this PR. Only the sorting is changed.
2023-03-10rustdoc: sort deprecated items lower in searchPeter Jaszkowiak-0/+1
serialize `q` (`itemPaths`) sparsely overall 4% reduction in search index size
2023-02-19Rollup merge of #108146 - notriddle:notriddle/rustdoc-search-reference, ↵Dylan DPC-0/+10
r=GuillaumeGomez rustdoc: hide `reference` methods in search index They're hidden in the HTML, so it makes no sense in the search engine for `reference::next` or `reference::shrink` to be shown. https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/What.20is.20.60reference.3A.3Ashrink.60.3F
2023-02-17Add comment explaining the search index tweakMichael Howell-0/+6
2023-02-16rustdoc: hide `reference` methods in search indexMichael Howell-0/+4
2023-02-16remove bound_type_of query; make type_of return EarlyBinder; change type_of ↵Kyle Matsuda-1/+1
in metadata
2023-02-16change usages of type_of to bound_type_ofKyle Matsuda-1/+1
2023-02-15Use more let chainGuillaume Gomez-10/+9
2023-01-22rustdoc: Use `DefId(Map,Set)` instead of `FxHash(Map,Set)`Vadim Petrochenkov-5/+5
Not all uses are converted, a few cases iterating through maps/sets and requiring nontrivial changes are kept.
2023-01-15rustdoc: simplify some & ref erencesMatthias Krüger-1/+1
2023-01-13IndexItem.name String -> Symbolklensy-4/+5
2022-10-31Don't generate tuple struct fields into the search indexGuillaume Gomez-15/+22
2022-10-29rustdoc: Split effective visibilities from rustc from similar data built by ↵Vadim Petrochenkov-8/+5
rustdoc for external def-ids
2022-10-26privacy: Rename "accessibility levels" to "effective visibilities"Vadim Petrochenkov-6/+12
And a couple of other naming tweaks Related to https://github.com/rust-lang/rust/issues/48054
2022-09-27rustdoc: remove `clean::TraitWithExtraInfo`Michael Howell-8/+3
Instead, it gathers the extra info later, when it's actually requested.
2022-08-16rustdoc: box ItemKind::TraitMichael Howell-1/+1
This reduces the memory consumption of ItemKind.
2022-07-29Box TypedefItem, ImplItem, AssocTypeItem variants of ItemKindest31-1/+1
This reduces ItemKind size from 224 bytes to 160 bytes.
2022-07-21Remove unused field in ItemKind::KeywordItemGuillaume Gomez-1/+1
2022-05-27cleanup librustdoc by making parent stack store itemsMichael Howell-75/+82
2022-05-26rustdoc: factor orphan impl items into an actual structMichael Howell-7/+13
2022-05-25rustdoc: include impl generics / self in search indexMichael Howell-4/+43
2022-05-24fix simple clippy lintsklensy-1/+1
2022-05-21Remove `crate` visibility modifier in libs, testsJacob Pratt-19/+19
2022-05-20Rollup merge of #96565 - notriddle:notriddle/impl-box, r=camelidGuillaume Gomez-1/+10
rustdoc: show implementations on `#[fundamental]` wrappers Fixes #92940
2022-05-10rustdoc: clean up method path indexMichael Howell-9/+1
This removes a special case that doesn't seem to do anything any more.
2022-05-09rustdoc: correct path to type alias methodsMichael Howell-1/+2
2022-05-06Fix reexports missing from the search indexGuillaume Gomez-1/+10
2022-04-29rustdoc: show implementations on `#[fundamental]` wrappersMichael Howell-1/+10
Fixes #92940
2022-04-19Rollup merge of #96142 - cjgillot:no-crate-def-index, r=petrochenkovDylan DPC-2/+2
Stop using CRATE_DEF_INDEX outside of metadata encoding. `CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want. We should not manipulate raw `DefIndex` outside of metadata encoding.
2022-04-17Fix rustdoc duplicated blanket impls issueGuillaume Gomez-3/+18