about summary refs log tree commit diff
path: root/src/librustdoc/html/render/write_shared.rs
AgeCommit message (Collapse)AuthorLines
2025-07-17Improve path segment joining.Nicholas Nethercote-2/+2
There are many places that join path segments with `::` to produce a string. A lot of these use `join("::")`. Many in rustdoc use `join_with_double_colon`, and a few use `.joined("..")`. One in Clippy uses `itertools::join`. A couple of them look for `kw::PathRoot` in the first segment, which can be important. This commit introduces `rustc_ast::join_path_{syms,ident}` to do the joining for everyone. `rustc_ast` is as good a location for these as any, being the earliest-running of the several crates with a `Path` type. Two functions are needed because `Ident` printing is more complex than simple `Symbol` printing. The commit also removes `join_with_double_colon`, and `estimate_item_path_byte_length` with it. There are still a handful of places that join strings with "::" that are unchanged. They are not that important: some of them are in tests, and some of them first split a path around "::" and then rejoin with "::". This fixes one test case where `{{root}}` shows up in an error message.
2025-07-08Auto merge of #142869 - nnethercote:join_path-mini, r=camelidbors-2/+2
Use `join_with_double_colon` in `write_shared.rs`. For consistency. Also, it's faster because `join_with_double_colon` does a better job estimating the allocation size than `join` from `itertools`. r? `@camelid`
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-1/+1
2025-06-22Use `join_with_double_colon` in `write_shared.rs`.Nicholas Nethercote-2/+2
For consistency. Also, it's faster because `join_with_double_colon` does a better job estimating the allocation size than `join` from `itertools`.
2025-06-19`Option`s are `Iterator`sYotam Ofek-11/+4
2025-06-19avoid intermediately collecting into vectorsYotam Ofek-8/+4
2025-06-19one less pathbuf allocationYotam Ofek-2/+2
2025-06-18`Result::expect` instead of `match` and `panic!`Yotam Ofek-6/+2
2025-06-16rustdoc: make srcIndex no longer a global variablebinarycat-5/+1
this is one-time initialization data, it can just be a function parameter. we also move the json parsing into createSrcSidebar to save a few bytes.
2025-05-30Address review comments.Nicholas Nethercote-1/+1
2025-05-27Streamline `TypeAliasPart::get`.Nicholas Nethercote-17/+16
- `ret` only ever gets at most one entry, so it can be an `Option` instead of a `Vec`. - Which means we can use `filter_map` instead of `flat_map`. - Move `trait_` next to the `ret` assignment, which can only happen once. - No need for `impls` to be a `Vec`, it can remain an iterator. - Avoid `Result` when collecting `impls`.
2025-05-26Avoid some unnecessary cloning.Nicholas Nethercote-1/+1
2025-05-24Simplify things a little more.Nicholas Nethercote-6/+3
2025-05-24Move code inside the `else` in `TypeAliasPart::get`.Nicholas Nethercote-29/+33
This is a huge perf win for rustdoc on the `typenum` and `nalgebra` benchmarks, because the `else` branch doesn't get hit much.
2025-05-24Simplify the "is some" test in `TypeAliasPart::get`.Nicholas Nethercote-1/+1
The comparison against `text` seems to be unnecessary.
2025-03-03Rollup merge of #137684 - GuillaumeGomez:rustdoc-dep-info, r=notriddleMatthias Krüger-1/+1
Add rustdoc support for `--emit=dep-info[=path]` Fixes #91982. This PR adds the `--emit=dep-info` command line flag support. It will be helpful for `cargo` development. cc ````@epage```` r? ````@notriddle````
2025-02-26Use helper function instead of reimplementing the logic to check if rustdoc ↵Guillaume Gomez-1/+1
should emit crate
2025-02-23return `impl fmt::Display` in more places instead of writing to stringsYotam Ofek-20/+16
2025-02-12Nuke `Buffer` abstraction from `librustdoc` 💣Yotam Ofek-19/+20
2025-01-29rustdoc: run css and html minifier at build instead of runtimeMichael Howell-8/+2
This way, adding a bunch of comments to the JS files won't make rustdoc slower.
2025-01-11re-add --disable-minification to rustdocbinarycat-1/+9
this also makes the rust.docs-minification option work as advertised in config.toml nothing fancy this time, this is intended to be perma-unstable. it's only really here for the benefit of rustdoc devs. mitegates https://github.com/rust-lang/rust/issues/135345
2024-12-01Move `SharedContext` out of `Rc`Guillaume Gomez-14/+9
2024-12-01Stop cloning `Context` so muchGuillaume Gomez-1/+1
2024-11-28Fix new clippy lintsGuillaume Gomez-29/+27
2024-10-19rustdoc: Document `markdown` module.Alona Enraght-Moony-1/+1
Rustdoc markdown handling is currently split between: - html::markdown, which contains all the meaty login - markdown, which is only used for when rustdoc renders a standalone markdown file Adds module-level doc-comment to markdown, and rename the function so it's clear that it's doing IO (instead of just rendering to a string).
2024-10-06Handle `librustdoc` cases of `rustc::potential_query_instability` lintismailarilik-5/+5
2024-09-25don't clone `clean::Item` in `TypeImplCollector`Lukas Markeffsky-9/+9
2024-09-25rm higher-ranked lifetimes from `DocVisitor`Lukas Markeffsky-1/+1
This allows the visitor to borrow from the visitees.
2024-09-24Dogfood `feature(file_buffered)`Josh Stone-3/+2
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-5/+5
2024-09-10Auto merge of #129337 - EtomicBomb:rfc, r=notriddlebors-43/+135
rustdoc rfc#3662 changes under unstable flags * All new functionality is under unstable options * Adds `--merge=shared|none|finalize` flags * Adds `--parts-out-dir=<crate specific directory>` for `--merge=none` to write cross-crate info file for a single crate * Adds `--include-parts-dir=<previously specified directory>` for `--merge=finalize` to write cross-crate info files * `tests/rustdoc/` tests for the new flags
2024-09-07rustdoc: use a single box to store Attributes and ItemKindMichael Howell-1/+1
2024-09-07rfc#3662 changes under unstable flagsEtomicBomb-43/+135
* All new functionality is under unstable options * Adds `--merge=shared|none|finalize` flags * Adds `--parts-out-dir=<crate specific directory>` for `--merge=none` to write cross-crate info file for a single crate * Adds `--include-parts-dir=<previously specified directory>` for `--merge=finalize` to write cross-crate info files * update tests/run-make/rustdoc-default-output/rmake.rs golden
2024-09-06Auto merge of #128776 - Bryanskiy:deep-reject-ctxt, r=lcnrbors-2/+2
Use `DeepRejectCtxt` to quickly reject `ParamEnv` candidates The description is on the [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/.5Basking.20for.20help.5D.20.60DeepRejectCtxt.60.20for.20param.20env.20candidates) r? `@lcnr`
2024-09-02Use `DeepRejectCtxt` to quickly reject `ParamEnv` candidatesBryanskiy-2/+2
2024-08-26rustdoc: fix missing resource suffix on `crates.js`Michael Howell-6/+12
Fixes a regression introduced in #128252.
2024-08-08fix typos, more SelfEtomicBomb-2/+2
typos in comments, remove references to crate-info, Self type in ordered_json and sorted_template
2024-08-07rename sortedjson -> orderedjsonEtomicBomb-66/+75
2024-08-07added unit tests for write_sharedEtomicBomb-51/+48
2024-08-07initial implementation of mergable rustdoc cciEtomicBomb-655/+807
2024-06-30Uplift fast rejection to new solverMichael Goulet-2/+1
2024-03-16rustdoc-search: shard the search result descriptionsMichael Howell-2/+29
The descriptions are, on almost all crates[^1], the majority of the size of the search index, even though they aren't really used for searching. This makes it relatively easy to separate them into their own files. This commit also bumps us to ES8. Out of the browsers we support, all of them support async functions according to caniuse. https://caniuse.com/async-functions [^1]: <https://microsoft.github.io/windows-docs-rs/>, a crate with 44MiB of pure names and no descriptions for them, is an outlier and should not be counted.
2024-02-04rustdoc: trait.impl, type.impl: sort impls to make it not depend on ↵klensy-10/+21
serialization order
2023-12-15Simplify JS code a little bitGuillaume Gomez-2/+2
2023-12-14rustdoc-search: fix a race condition in search index loadingMichael Howell-2/+8
`var` declare it in the global scope, and `const` does not. It needs to be declared in global scope.
2023-12-14Use Map instead of Object for source files and search indexGuillaume Gomez-9/+10
2023-11-29rustdoc: Move `AssocItemRender` and `RenderMode` to `html::render`.Alona Enraght-Moony-2/+2
They're only used for HTML, so it makes more sense for them to live their.
2023-11-08rustdoc: minor changes suggested by clippy perf lints.Nicholas Nethercote-9/+6
2023-10-22rustdoc: make JS trait impls act more like HTMLMichael Howell-2/+19
2023-10-22rustdoc: use JS to inline target type impl docs into aliasMichael Howell-2/+250
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