about summary refs log tree commit diff
path: root/src/librustdoc/html/render
AgeCommit message (Collapse)AuthorLines
2022-08-11Rollup merge of #99337 - jsha:simplify-highlight, r=GuillaumeGomezMatthias Krüger-13/+2
rustdoc: simplify highlight.rs Split render_with_highlighting, which took many optional parameters, into three functions for specific purposes, which each take a smaller number of mostly required parameters. Remove some plumbing to pass through an "edition" parameter, which was used solely to avoid highlighting some 2021 Edition keywords in non-2021 code. I've tested a build of std docs before and after, and this does not change the generated HTML at all. Followup from https://github.com/rust-lang/rust/pull/91264#discussion_r901151101 r? ```@GuillaumeGomez```
2022-08-09rustdoc: simplify highlight.rsJacob Hoffman-Andrews-13/+2
Split render_with_highlighting, which took many optional parameters, into three functions for specific purposes, which each take a smaller number of mostly required parameters. Remove some plumbing to pass through an "edition" parameter, which was used solely to avoid highlighting some 2021 Edition keywords in non-2021 code.
2022-08-09Auto merge of #100150 - notriddle:notriddle/implementors-js, r=GuillaumeGomezbors-17/+62
rustdoc: use a more compact encoding for implementors/trait.*.js The exact amount that this reduces the size of an implementors file depends on whether most of the impls are synthetic or not. For `Send`, it reduces the file from 128K to 112K, while for `Clone` it went from 64K to 44K.
2022-08-07Don't document impossible to call default trait items on implsMichael Goulet-0/+9
2022-08-05rustdoc: use serde, which can escape strings more quicklyMichael Howell-35/+15
This means we don't gain as much as we did from using single-quotes, since serde_json can only produce double-quoted strings, but it's still a win.
2022-08-05rustdoc: reduce the number of intermediate Strings allocatedMichael Howell-12/+21
2022-08-04rustdoc: use a more compact encoding for implementors/trait.*.jsMichael Howell-17/+73
The exact amount that this reduces the size of an implementors file depends on whether most of the impls are synthetic or not. For `Send`, it reduces the file from 128K to 116K, while for `Clone` it went from 64K to 52K.
2022-08-03Rollup merge of #100083 - notriddle:notriddle/source-files-js, r=GuillaumeGomezMatthias Krüger-13/+20
rustdoc: use a more compact encoding for source-files.js This reduces the compiler-doc file from 40K to 36K, a 10% reduction in size.
2022-08-02rustdoc: use a more compact encoding for source-files.jsMichael Howell-13/+20
This reduces the compiler-doc file from 40K to 36K, a 10% reduction in size.
2022-08-02Remove Clean trait implementation for ast::Attribute and cleanup ↵Guillaume Gomez-1/+1
Attributes::from_ast function by splitting it in two
2022-07-30Rollup merge of #99904 - GuillaumeGomez:cleanup-html-whitespace, r=notriddleYuki Okushi-10/+12
Cleanup html whitespace I realized while looking at the raw HTML that we generated some unwanted white space characters. This PR cleans up the one coming directly from rustdoc. I'll check from `pulldown-cmark` for the remaining ones. Some numbers now: the difference is small, it goes from `63009` to `62859`. But multiplied by the number of files, it becomes quite interesting overall. r? `@notriddle`
2022-07-29Box TypedefItem, ImplItem, AssocTypeItem variants of ItemKindest31-2/+2
This reduces ItemKind size from 224 bytes to 160 bytes.
2022-07-29Remove unwanted extra white space characters from HTMLGuillaume Gomez-10/+12
2022-07-27Rollup merge of #99700 - est31:rustdoc_layout_heading, r=GuillaumeGomezYuki Okushi-1/+5
Add a clickable link to the layout section The layout section (activated by `--show-type-layout`) is currently not linkable to (outside of chrome's link to text feature). This PR makes it linkable via `#layout`.
2022-07-25apply review suggestionsMaybe Waffle-1/+1
2022-07-25Add a clickable link to the layout sectionest31-1/+5
2022-07-24add backticksMaybe Waffle-2/+2
2022-07-24Add support for `#[rustc_must_implement_one_of]` to rustdocMaybe Waffle-5/+16
2022-07-22Auto merge of #99598 - GuillaumeGomez:clean-trait-fields-on-demand, r=notriddlebors-5/+5
Make some clean::Trait fields computation on demand r? `@notriddle`
2022-07-22Make some clean::Trait fields computation on demandGuillaume Gomez-5/+5
2022-07-21Remove unused field in ItemKind::KeywordItemGuillaume Gomez-2/+2
2022-07-08add opt in attribute for stable-in-unstable itemsJane Lusby-1/+1
2022-07-07Rollup merge of #99017 - GuillaumeGomez:rustdoc-ending-enum, r=notriddleMatthias Krüger-13/+13
Replace boolean argument for print_where_clause with an enum to make code more clear As you suggested ``@notriddle.`` Just not sure if the naming seems good to you? r? ``@notriddle``
2022-07-07Replace boolean argument for print_where_clause with an enum to make code ↵Guillaume Gomez-13/+13
more clear
2022-07-07Rollup merge of #98973 - GuillaumeGomez:inherent-impl-anchors, r=notriddleDylan DPC-4/+16
Remove (unused) inherent impl anchors This is something `@notriddle` realized a few days ago: we have unused anchors in the DOM. This PR removes them. You can test it [here](https://rustdoc.crud.net/imperio/inherent-impl-anchors/foo/index.html). r? `@notriddle`
2022-07-06Rollup merge of #98939 - GuillaumeGomez:rustdoc-disamb-impls, r=notriddleGuillaume Gomez-42/+20
rustdoc: Add more semantic information to impl IDs Take over of #92745. I fixed the last remaining issue for the links in the sidebar (mentioned by `@jsha)` and fixed the few links broken in the std/core docs. cc `@camelid` r? `@notriddle`
2022-07-06Don't generate anchors on inherent impl methodsGuillaume Gomez-4/+16
2022-07-05Fix invalid add of whitespace when there is where clauseGuillaume Gomez-14/+41
2022-07-05Fix link generation in the sidebar for implsGuillaume Gomez-15/+12
2022-07-05rustdoc: Add more semantic information to impl idspierwill-27/+8
Instead of generating `#impl`, `#impl-1`, etc., generate IDs like `#impl-Foo<M>`. Co-authored-by: Noah Lev <camelidcamel@gmail.com>
2022-07-04Rollup merge of #98814 - fmease:minimal-fix-for-issue-97933, r=GuillaumeGomezMatthias Krüger-1/+12
rustdoc: Censor certain complex unevaluated const exprs Fixes #97933. This is more of a hotfix for the aforementioned issue. By that, I mean that my proposed patch is not the best solution but one that does not change as much existing code. It treats symptoms rather than the root cause. This PR “censors” certain complex unevaluated constant expressions like `match`es, blocks, function calls, struct literals etc. by pretty-printing them as `_` / `{ _ }` (number and string literals, paths and `()` are still printed as one would expect). Resorting to this placeholder is preferable to printing the full expression verbatim since they can be quite large and verbose resulting in an unreadable mess in the generated documentation. Further, mindlessly printing the const would leak private and `doc(hidden)` struct fields (#97933), at least in the current stable & nightly implementations which rely on `span_to_snippet` (!) and `rustc_hir_pretty::id_to_string`. The censoring of _verbose_ expressions is probably going to stay longer term. However, in regards to private and `doc(hidden)` struct fields, I have a more proper fix in mind which I have already partially implemented locally and for which I am going to open a separate PR sometime soon. For that, I was already in contact with `@GuillaumeGomez.` The proper fix involves rustdoc not falling back on pretty-printing unevaluated consts so easily (what this PR is concerned about) and instead preferring to print evaluated consts which contain more information allowing it to selectively hide private and `doc(hidden)` fields, create hyperlinks etc. generally making the output more granular and precise (compared to the brutal `_` placeholder). Unfortunately, I was a bit too late and the issue just hit stable (1.62). Should this be backported to beta or even a potential 1.62.1? r? `@GuillaumeGomez`
2022-07-04rustdoc: censor certain complex unevaluated const exprsLeón Orell Valerian Liehr-1/+12
2022-06-29Replace `sort_modules_alphabetically` boolean with enumNoah Lev-9/+16
This fixes the long-standing FIXME there and makes the code easier to understand. The reference to modules in both the old and new names seems potentially wrong since I believe it applies to all items.
2022-06-27Add comments, fixes for `0` sentinelMichael Howell-1/+27
2022-06-27Put back, fix ()-output optimizationMichael Howell-0/+1
2022-06-24Fix rustdoc under `#[no_core]`Michael Howell-28/+32
2022-06-24rustdoc: reference function signature types from the `p` arrayMichael Howell-88/+146
This reduces the size of the function signature index, because it's common to have many functions that operate on the same types. $ wc -c search-index-old.js search-index-new.js 5224374 search-index-old.js 3932314 search-index-new.js By my math, this reduces the uncompressed size of the search index by 32%. On compressed signatures, the wins are less drastic, a mere 8%: $ wc -c search-index-old.js.gz search-index-new.js.gz 404532 search-index-old.js.gz 371635 search-index-new.js.gz
2022-06-24Rollup merge of #91264 - GuillaumeGomez:macro-jump-to-def, r=jshaYuki Okushi-17/+66
Add macro support in jump to definition feature Fixes #91174. To do so, I check if the span comes from an expansion, and if so, I infer the original macro `DefId` or `Span` depending if it's a defined in the current crate or not. There is one limitation due to macro expansion though: ```rust macro_rules! yolo { () => {}} fn foo() { yolo!(); } ``` In `foo`, `yolo!` won't be linked because after expansion, it is replaced by nothing (which seems logical). So I can't get an item from the `Visitor` from which I could tell if its `Span` comes from an expansion. I added a test for this specific limitation alongside others. Demo: https://rustdoc.crud.net/imperio/macro-jump-to-def/src/foo/check-source-code-urls-to-def-std.rs.html As for the empty macro issue that cannot create a jump to definition, you can see it [here](https://rustdoc.crud.net/imperio/macro-jump-to-def/src/foo/check-source-code-urls-to-def-std.rs.html#35). r? ```@jyn514```
2022-06-23Don't test the rustdoc rendering context size on Windows.Dan Gohman-1/+1
This assert is just making sure the size of `Context` doens't grow unexpectedly, and it's already not being checked on every platform. `PathBuf` now has a different size on Windows, so adjust this to avoid checking the size on Windows.
2022-06-20Improve code readability and documentationGuillaume Gomez-28/+40
2022-06-20Improve loading of crates.js and sidebar-items.jsJacob Hoffman-Andrews-25/+2
Now that the "All Crates" dropdown is only rendered on the search results page, there is no need to load crates.js on most pages. Load it only on crate pages. Also, add the `defer` attribute so it does not block page rendering. For sidebar-items.js, move the script tag to `<head>`. Since it already has the defer attribute it won't block loading. The defer attribute does preserve ordering between scripts, so instead of the callback on load, it can set a global variable on load, which is slightly simpler. Also, since it is required to finish rendering the page, beginning its load earlier is better. Remove generation and handling of sidebar-vars. Everything there can be computed with information available in JS via other means. Remove the "other" wrapper in the sidebar. It was unnecessary. Remove excess script fields
2022-06-20Add support for macro in "jump to def" featureGuillaume Gomez-17/+54
2022-06-16Move/rename `lazy::Sync{OnceCell,Lazy}` to `sync::{Once,Lazy}Lock`Maybe Waffle-1/+1
2022-06-09Auto merge of #97772 - GuillaumeGomez:minifier-update, r=notriddlebors-4/+6
Update minifier version to 0.2.1 This change and these changes come from an idea of `@camelid:` instead of creating a string, we just `write` the type into the file directly. I don't think it'll have a big impact on perf but it's still a potential small improvement. r? `@notriddle`
2022-06-07Update minifier version to 0.2.1Guillaume Gomez-4/+6
2022-06-06Rollup merge of #90905 - GuillaumeGomez:empty-impl-blocks, r=jshaMatthias Krüger-0/+7
Add empty impl blocks if they have documentation Fixes https://github.com/rust-lang/rust/issues/90866. The update for the test script is needed to count the number of impl blocks we have with only the struct. To be noted that with https://github.com/rust-lang/rust/pull/89676 merged, it wouldn't be needed (I don't know what is the status of it btw. cc ```@Mark-Simulacrum).``` It looks like this: ![Screenshot from 2021-11-14 16-51-28](https://user-images.githubusercontent.com/3050060/141689100-e57123c0-bf50-4c42-adf5-d991e169a0e4.png) cc ```@jyn514``` r? ```@camelid```
2022-06-04Don't generate "Impls on Foreign Types" for stdJacob Hoffman-Andrews-4/+3
Hack: many traits and types in std are re-exported from core or alloc. In general, rustdoc is capable of recognizing these implementations as being on local types. However, in at least one case, rustdoc gets confused and labels an implementation as being on a foreign type. To make sure that confusion doesn't pass on to the reader, consider all implementations in std, core, and alloc to be on local types.
2022-06-02Rollup merge of #97613 - jsha:implementation-is-on-local-type, r=GuillaumeGomezYuki Okushi-6/+3
rustdoc: Improve calculation of "Impls on Foreign Types" The existing code to calculate whether an implementation was on a "Foreign Type" was duplicated across the sidebar generation and the page generation. It also came to the wrong conclusion for some cases where both the trait and the "for" type were re-exports. This PR extracts the logic into a method of `Impl`, breaks it into a multi-line method so it can be commented, and adds a case for when the trait and the "for" type came from the same crate. This fixes some cases - like the platform-specific integer types (`__m256`, `__m128`, etc). But it doesn't fix all cases. See the screenshots below. [Before](https://doc.rust-lang.org/nightly/std/clone/trait.Clone.html#foreign-impls): <img src="https://user-images.githubusercontent.com/220205/171338226-59ce6daf-3d76-4bad-bc8d-72a8259a8f43.png" width=200> [After](https://rustdoc.crud.net/jsha/implementation-is-on-local-type/std/clone/trait.Clone.html): <img src="https://user-images.githubusercontent.com/220205/171338147-28308a65-1597-4223-be47-9550062404dd.png" width=200> The remaining types (`CString`, `NulError`, etc) are all from the `alloc` crate, while the `Clone` trait is from the `core` crate. Since `CString` and `Clone` are both re-exported by `std`, they are logically local to each other, but I couldn't figure out a good way to detect that in this code. I figure this is still a good step forward. Related: #97610 r? `@camelid`
2022-06-01Improve calculation of "Impls on Foreign Types"Jacob Hoffman-Andrews-6/+3
2022-05-31rustdoc: also index raw pointersMichael Howell-2/+3
Co-authored-by: Noah Lev <camelidcamel@gmail.com>