about summary refs log tree commit diff
path: root/src/librustdoc/formats
AgeCommit message (Collapse)AuthorLines
2024-08-30Remove `#[macro_use] extern crate tracing` from rustdoc.Nicholas Nethercote-0/+2
2024-08-29Rollup merge of #129743 - GuillaumeGomez:fix-rustdoc-clippy, r=notriddleGuillaume Gomez-6/+6
Fix rustdoc clippy lints Ran clippy on rustdoc and fixed the errors. r? `@notriddle`
2024-08-29Fix clippy lintsGuillaume Gomez-6/+6
2024-08-26Stop using a special inner body for the coroutine by-move body for async ↵Michael Goulet-1/+2
closures
2024-08-05Rollup merge of #128385 - its-the-shrimp:fix_114039, r=aDotInTheVoidMatthias Krüger-23/+15
rustdoc-json: discard non-local inherent impls for primitives Fixes #114039 at least it should r? `@aDotInTheVoid`
2024-08-05rustdoc-json: discard non-local inherent implsschvv31n-23/+15
2024-08-04Rollup merge of #128578 - camelid:cache-index-cleanup, r=notriddleMatthias Krüger-145/+159
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]: https://github.com/rust-lang/rust/pull/128471#discussion_r1699475342 r? ``@notriddle``
2024-08-03rustdoc: Re-add missing `stripped_mod` check; explain orphan implsNoah Lev-5/+26
Co-authored-by: Michael Howell <michael@notriddle.com>
2024-08-02Restructure `add_item_to_search_index` to eliminate code pathsNoah Lev-110/+103
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.
2024-08-02Extract local variablesNoah Lev-30/+33
2024-08-02Restructure a confusing `match`Noah Lev-62/+62
2024-08-02rustdoc: Simplify some search index codeNoah Lev-32/+28
2024-08-02rustdoc: Clarify construction of name for search indexNoah Lev-11/+14
2024-08-02rustdoc: Extract helper function to add item to search indexNoah Lev-137/+135
2024-08-01rustdoc: Remove OpaqueTyAlona Enraght-Moony-4/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-5/+4
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-06Revert "Rollup merge of #124976 - petrochenkov:usedcrates, r=oli-obk"Rémy Rakic-1/+1
This reverts commit eda4a35f365535af72118118a3597edf5a13c12d, reversing changes made to eb6b35b5bcb3c2a594cb29cd478aeb2893f49d30.
2024-05-22rustc: Use `tcx.used_crates(())` moreVadim Petrochenkov-1/+1
And explain when it should be used.
2024-04-18Auto merge of #119912 - notriddle:notriddle/reexport-dedup, r=GuillaumeGomezbors-0/+12
rustdoc-search: single result for items with multiple paths Part of #15723 Preview: https://notriddle.com/rustdoc-html-demo-9/reexport-dup/std/index.html?search=hashmap This change uses the same "exact" paths as trait implementors and type alias inlining to track items with multiple reachable paths. This way, if you search for `vec`, you get only the `std` exports of it, and not the one from `alloc`. It still includes all the items in the search index so that you can search for them by all available paths. For example, try `core::option` and `std::option`, and notice that the results page doesn't show duplicates, but still shows all the items in their respective crates.
2024-04-08rustdoc-search: single result for items with multiple pathsMichael Howell-0/+12
This change uses the same "exact" paths as trait implementors and type alias inlining to track items with multiple reachable paths. This way, if you search for `vec`, you get only the `std` exports of it, and not the one from `alloc`. It still includes all the items in the search index so that you can search for them by all available paths. For example, try `core::option` and `std::option`, and notice that the results page doesn't show duplicates, but still shows all the items in their respective crates.
2024-04-04Improve code a bitGuillaume Gomez-6/+4
2024-03-12Change `DefKind::Static` to a struct variantOli Scherer-1/+1
2024-02-09Correctly generate path for non-local items in source code pagesGuillaume Gomez-12/+25
2023-11-29rustdoc: Move `AssocItemRender` and `RenderMode` to `html::render`.Alona Enraght-Moony-15/+0
They're only used for HTML, so it makes more sense for them to live their.
2023-11-26merge `DefKind::Coroutine` into `DefKind::Closure`bohan-2/+1
2023-11-25is_{some,ok}_and for rustdocMichael Goulet-4/+4
2023-11-21rustdoc-search: make primitives and keywords less specialMichael Howell-22/+29
The search sorting code already sorts by item type discriminant, putting things with smaller discriminants first. There was also a special case for sorting keywords and primitives earlier, and this commit removes it by giving them lower discriminants. The sorting code has another criteria where items with descriptions appear earlier than items without, and that criteria has higher priority than the item type. This shouldn't matter, though, because primitives and keywords normally only appear in the standard library, and it always gives them descriptions.
2023-11-19rustdoc-search: add support for associated typesMichael Howell-0/+3
2023-11-18Remove unneeded `unknown` variable and `Symbol` creation when iterating over ↵Guillaume Gomez-4/+4
items in rustdoc rendering
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/+5
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-20s/Generator/Coroutine/Oli Scherer-1/+1
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-10-10Rollup merge of #109422 - notriddle:notriddle/impl-disambiguate-search, ↵Guillaume Gomez-31/+42
r=GuillaumeGomez rustdoc-search: add impl disambiguator to duplicate assoc items Preview (to see the difference, click the link and pay attention to the specific function that comes up): | Before | After | |--|--| | [`simd<i64>, simd<i64> -> simd<i64>`](https://doc.rust-lang.org/nightly/std/?search=simd%3Ci64%3E%2C%20simd%3Ci64%3E%20-%3E%20simd%3Ci64%3E) | [`simd<i64>, simd<i64> -> simd<i64>`](https://notriddle.com/rustdoc-demo-html-3/impl-disambiguate-search/std/index.html?search=simd%3Ci64%3E%2C%20simd%3Ci64%3E%20-%3E%20simd%3Ci64%3E) | | [`cow, vec -> bool`](https://doc.rust-lang.org/nightly/std/?search=cow%2C%20vec%20-%3E%20bool) | [`cow, vec -> bool`](https://notriddle.com/rustdoc-demo-html-3/impl-disambiguate-search/std/index.html?search=cow%2C%20vec%20-%3E%20bool) 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. ### The bug On the "Before" links, this example search calls for `i64`: ![image](https://github.com/rust-lang/rust/assets/1593513/9431d89d-41dc-4f68-bbb1-3e2704a973d2) But if I click any of the results, I get `f64` instead. ![image](https://github.com/rust-lang/rust/assets/1593513/6d89c692-1847-421a-84d9-22e359d9cf82) The PR fixes this problem by adding enough information to the search result `href` to disambiguate methods with different types but the same name. More detailed description of the problem at: https://github.com/rust-lang/rust/pull/109422#issuecomment-1491089293 > When a struct/enum/union has multiple impls with different type parameters, it can have multiple methods that have the same name, but which are on different impls. Besides Simd, [Any](https://doc.rust-lang.org/nightly/std/any/trait.Any.html?search=any%3A%3Adowncast) also demonstrates this pattern. It has three methods named `downcast`, on three different impls. > > When that happens, it presents a challenge in linking to the method. Normally we link like `#method.foo`. When there are multiple `foo`, we number them like `#method.foo`, `#method.foo-1`, `#method.foo-2`, etc. > > It also presents a challenge for our search code. Currently we store all the variants in the index, but don’t have any way to generate unambiguous URLs in the results page, or to distinguish them in the SERP. > > To fix this, we need three things: > > 1. A fragment format that fully specifies the impl type parameters when needed to disambiguate (`#impl-SimdOrd-for-Simd<i64,+LANES>/method.simd_max`) > 2. A search index that stores methods with enough information to disambiguate the impl they were on. > 3. A search results interface that can display multiple methods on the same type with the same name, when appropriate OR a disambiguation landing section on item pages? > > For reviewers: it can be hard to see the new fragment format in action since it immediately gets rewritten to the numbered form.
2023-09-26Don't store lazyness in DefKindMichael Goulet-1/+1
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-5/+5
2023-08-07Store the laziness of type aliases in the DefKindLeón Orell Valerian Liehr-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-07-12Re-format let-else per rustfmt updateMark Rousskov-2/+5
2023-07-08Replace RPITIT current impl with new strategy that lowers as a GATSantiago Pastorino-1/+0
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