about summary refs log tree commit diff
path: root/src/librustdoc/html/render/mod.rs
AgeCommit message (Collapse)AuthorLines
2021-04-24Rollup merge of #84458 - jyn514:cleanup-after-krate, r=GuillaumeGomezYuki Okushi-4/+4
Remove unnecessary fields and parameters in rustdoc r? `@GuillaumeGomez`
2021-04-24Rollup merge of #84320 - jsha:details-implementors, ↵Yuki Okushi-3/+12
r=Manishearth,Nemo157,GuillaumeGomez Use details tag for trait implementors. Part of #83332 and following on from #83337 and #83355. This removes one category of JS-generated toggles (implementors), and replaces them with a `<details>` tag. This simplifies the JS, and fixes some bugs where things that were supposed to be hidden by the toggle were not hidden. Compare https://hoffman-andrews.com/rust/details-implementors/std/io/trait.Read.html#impl-Read vs https://doc.rust-lang.org/nightly/std/io/trait.Read.html#implementors. This introduces a `left: -23px` to put the toggle in the correct place, matching the current style for `.collapse-toggle`. It's worth noting this introduces a slight behavior change: since the entire line is now a `<summary>`, any part of the line is clickable. So for instance, in `impl Read for File`, clicking `impl` or `for` will collapse / expand the docs. Clicking `Read` or `File` still links to the appropriate documentation as before.
2021-04-23Use ItemType in cacheJoshua Nelson-5/+5
2021-04-22Remove unnecessary `edition` field on SharedContextJoshua Nelson-4/+4
2021-04-19rustdoc: use details tag for trait implementorsJacob Hoffman-Andrews-3/+12
This switches from JS-generated toggles to using the HTML <details> tag for expanding and collapsing entries in the "Implementors" section.
2021-04-19rustdoc: Simplify some document functionsArpad Borsos-45/+11
* Remove `prefix` param of `document_short/full`, `render_markdown`, as its always an empty string. * Remove `Option` wrapping of `document_short` `parent`, as its always `Some`.
2021-04-19Auto merge of #84283 - jsha:de-emphasize-attributes, r=GuillaumeGomezbors-1/+0
rustdoc: Reduce visual weight of attributes. Followup from #83337. As part of that PR, we stopped hiding attributes behind a toggle, because most things have just zero or one attributes. However, this made clear that the current rendering of attributes emphasizes them a lot, which distracts from function signatures. This PR changes their color of attributes to be the same as the toggles, and reduces their font weight. This also removes `#[lang]` from the list of ALLOWED_ATTRIBUTES. This attribute is an implementation detail rather than part of the public-facing documentation. ![image](https://user-images.githubusercontent.com/220205/115131061-cc407d80-9fa9-11eb-9a77-ad3f3217f391.png) Demo at https://hoffman-andrews.com/rust/de-emph-attr/std/string/struct.String.html#method.trim
2021-04-17rustdoc: get rid of CURRENT_DEPTHMichael Howell-3/+0
2021-04-17Reduce visual weight of attributes.Jacob Hoffman-Andrews-1/+0
2021-04-17rustdoc: move the cx argument to the end of the listMichael Howell-4/+4
This should help make things consistent.
2021-04-17rustdoc: use more precise relative URLSMichael Howell-87/+58
Instead of using a depth counter and adding "../" to get to the top, this commit makes rustdoc actually compare the path of what it's linking from to the path that it's linking to. This makes the resulting HTML shorter. Here's a comparison of one of the largest (non-source) files in the Rust standard library docs (about 4% improvement before gzipping). $ wc -c struct.Wrapping.old.html struct.Wrapping.new.html 2387389 struct.Wrapping.old.html 2298538 struct.Wrapping.new.html Most if it can be efficiently gzipped away. $ wc -c struct.Wrapping.old.html.gz struct.Wrapping.new.html.gz 70679 struct.Wrapping.old.html.gz 70050 struct.Wrapping.new.html.gz But it also makes a difference in the final DOM size, reducing it from 91MiB to 82MiB.
2021-04-16Rollup merge of #83337 - Manishearth:item-hide, r=GuillaumeGomezDylan DPC-38/+26
rustdoc: Hide item contents, not items This tweaks rustdoc to hide item contents instead of items, and only when there are too many of them. This means that users will _always_ see the type parameters, and will _often_ see fields/etc as long as they are small. Traits have some heuristics for hiding only the methods or only the methods and the consts, since the associated types are super important. I'm happy to play around with the heuristics here; we could potentially make it so that structs/enums/etc are always hidden but traits will try really hard to show type aliases. This needs a test, but you can see it rendered at https://manishearth.net/sand/doc_render/bar/ <details> <summary> Code example </summary> ```rust pub struct PubStruct { pub a: usize, pub b: usize, } pub struct BigPubStruct { pub a: usize, pub b: usize, pub c: usize, pub d: usize, pub e: usize, pub f: usize, } pub union BigUnion { pub a: usize, pub b: usize, pub c: usize, pub d: usize, pub e: usize, pub f: usize, } pub union Union { pub a: usize, pub b: usize, pub c: usize, } pub struct PrivStruct { a: usize, b: usize, } pub enum Enum { A, B, C, D { a: u8, b: u8 } } pub enum LargeEnum { A, B, C, D, E, F, G, H, I, J } pub trait Trait { type A; #[must_use] fn foo(); fn bar(); } pub trait GinormousTrait { type A; type B; type C; type D; type E; type F; const N: usize = 1; #[must_use] fn foo(); fn bar(); } pub trait HugeTrait { type A; const M: usize = 1; const N: usize = 1; const O: usize = 1; const P: usize = 1; const Q: usize = 1; #[must_use] fn foo(); fn bar(); } pub trait BigTrait { type A; #[must_use] fn foo(); fn bar(); fn baz(); fn quux(); fn frob(); fn greeble(); } #[macro_export] macro_rules! foo { (a) => {a}; } ``` </details> Fixes https://github.com/rust-lang/rust/issues/82114
2021-04-13tidy format rustFrançois Mockers-10/+28
2021-04-13fix source link when in a trait implementationFrançois Mockers-8/+30
2021-04-13add anchors links on hover to items from trait implFrançois Mockers-6/+13
2021-04-13fix links from trait impl methods to trait declarationFrançois Mockers-3/+4
2021-04-12Add css classesManish Goregaokar-1/+1
2021-04-12Improve CSS for "hide contents, not items"Jacob Hoffman-Andrews-27/+25
Introduce a first use of the `<details>` and `<summary>` tags as replacements for the JS-built toggles. I think this has the potential to replace all the JS toggles and generally clean up the JS, CSS, and HTML. Split rendering of attributes into two cases: in the case where they are rendered as descendents of a `<pre>` tag, where they use indent spaces and newlines for formatting, matching their surrounding markup. In the case where they are rendered as descendants of a `<code>` tag, they are rendered as `<div>`. This let me clean up some fragile CSS that was adjusting the margin-left of attributes depending on context. Remove toggles for attributes. With the ALLOWED_ATTRIBUTES filter, it's rare for an item to have more than one attribute, so hiding attributes behind a toggle doesn't save any screen space in the common case. Fix a couple of invocations of `matches!` that didn't compile on my machine. Fix a boolean for the JS `createToggle` call that was causing "Expand description" to show up spuriously on already-expanded descriptions. Add JS for auto-hide settings and hide all / show all. Remove a z-index property and some font color tweaks made unnecessary by the <details> toggles. Add CSS for the <details> toggles.
2021-04-12rustdoc: Add setting for hiding large itemsManish Goregaokar-0/+1
2021-04-12rustdoc: Stop hiding entire item declarationsManish Goregaokar-11/+0
2021-04-06Rollup merge of #82963 - camelid:move-sharedcontext, r=GuillaumeGomezDylan DPC-76/+5
Move `SharedContext` to `context.rs` It is tightly connected to `Context` and is primarily used as a field in `Context`. Thus, it should be next to `Context`.
2021-04-05Move `SharedContext` to `context.rs`Camelid-76/+5
It is tightly connected to `Context` and is primarily used as a field in `Context`. Thus, it should be next to `Context`.
2021-04-06Rollup merge of #83835 - notriddle:sort-index, r=ollie27Yuki Okushi-0/+1
rustdoc: sort search index items for compression This should not affect the appearance of the docs pages themselves. This makes the pre-compressed search index smaller, thanks to the empty-string path duplication format, and also the gzipped version, by giving the algorithm more structure to work with. rust$ wc -c search-index-old.js search-index-new.js 2628334 search-index-old.js 2586181 search-index-new.js 5214515 total rust$ gzip search-index-* rust$ wc -c search-index-old.js.gz search-index-new.js.gz 239486 search-index-old.js.gz 237386 search-index-new.js.gz 476872 total
2021-04-05Rollup merge of #83826 - slightlyoutofphase:rustdoc-sidebar-order-shuffle, ↵Dylan DPC-7/+8
r=jyn514 List trait impls before deref methods in doc's sidebar This PR is acting directly on a suggestion made by ```````@jyn514``````` in #83133. I've tested the changes locally, and can confirm that it does in fact properly achieve what he thought it would. This PR also in turn closes #83133.
2021-04-04Rollup merge of #83809 - GuillaumeGomez:remove-initial-ids, r=camelidDylan DPC-18/+0
Remove unneeded INITIAL_IDS const Some IDs inside this map didn't exist anymore, some others were duplicates of what we have inside `IdMap`. So instead of keeping the two around and since `INITIAL_IDS` was only used by `IdMap`, no need to keep both of them.
2021-04-03rustdoc: sort search index items for compressionMichael Howell-0/+1
This should not affect the appearance of the docs pages themselves. This makes the pre-compressed search index smaller, thanks to the empty-string path duplication format, and also the gzipped version, by giving the algorithm more structure to work with. rust$ wc -c search-index-old.js search-index-new.js 2628334 search-index-old.js 2586181 search-index-new.js 5214515 total rust$ gzip search-index-* rust$ wc -c search-index-old.js.gz search-index-new.js.gz 239486 search-index-old.js.gz 237386 search-index-new.js.gz 476872 total
2021-04-03Remove unneeded INITIAL_IDS constGuillaume Gomez-18/+0
2021-04-03Remove trailing whitespaceSlightlyOutOfPhase-1/+1
2021-04-03List trait impls before methods from deref in the sidebar of Rustdoc's outputSlightlyOutOfPhase-7/+8
2021-04-02rustdoc: Rename internal uses of `spotlight`Camelid-6/+8
I didn't make these renames in #80965 because I didn't want the PR to conflict with #80914.
2021-03-24Store tcx and cache when they are used multiple times instead of calling ↵Guillaume Gomez-58/+66
functions every time
2021-03-24Rework rustdoc const typeGuillaume Gomez-33/+63
2021-03-23Use &str instead of StringGuillaume Gomez-3/+3
2021-03-23Fix sidebar trait items sortGuillaume Gomez-3/+3
2021-03-22Auto merge of #82855 - jyn514:no-temporaries, r=GuillaumeGomezbors-18/+26
Avoid temporary allocations in `render_assoc_item` `render_assoc_item` came up as very hot in a profile of rustdoc on `bevy`. This avoids some temporary allocations just to calculate the length of the header. This should be a strict improvement, since all string formatting was done twice before. cc #82845
2021-03-10rustdoc: tweak the search index formatMichael Howell-17/+0
This essentially switches search-index.js from a "array of struct" to a "struct of array" format, like this: { "doc": "Crate documentation", "t": [ 1, 1, 2, 3, ... ], "n": [ "Something", "SomethingElse", "whatever", "do_stuff", ... ], "q": [ "a::b", "", "", "", ... ], "d": [ "A Struct That Does Something", "Another Struct", "a function", "another function", ... ], "i": [ 0, 0, 1, 1, ... ], "f": [ null, null, [], [], ... ], "p": ..., "a": ... } So `{ty: 1, name: "Something", path: "a::b", desc: "A Struct That Does Something", parent_idx: 0, search_type: null}` is the first item. This makes the uncompressed version smaller, but it really shows on the compressed version: notriddle:rust$ wc -c new-search-index1.52.0.js 2622427 new-search-index1.52.0.js notriddle:rust$ wc -c old-search-index1.52.0.js 2725046 old-search-index1.52.0.js notriddle:rust$ gzip new-search-index1.52.0.js notriddle:rust$ gzip old-search-index1.52.0.js notriddle:rust$ wc -c new-search-index1.52.0.js.gz 239385 new-search-index1.52.0.js.gz notriddle:rust$ wc -c old-search-index1.52.0.js.gz 296328 old-search-index1.52.0.js.gz notriddle:rust$ That's a 4% improvement on the uncompressed version (fewer `[]`), and 20% improvement after gzipping it, thanks to putting like-typed data next to each other. Any compression algorithm based on a sliding window will probably show this kind of improvement.
2021-03-09Simplify some of the rendering code in the indexMichael Howell-5/+1
It's kinda silly using serde seq for fixed-length stuff.
2021-03-09Auto merge of #82356 - camelid:render-cleanup, r=GuillaumeGomezbors-5/+15
rustdoc: Cleanup `html::render::Context` - Move most shared fields to `SharedContext` (except for `cache`, which isn't mutated anyway) - Replace a use of `Arc` with `Rc` - Make a bunch of fields private - Add static size assertion for `Context` - Don't share `id_map` and `deref_id_map`
2021-03-07Avoid temporary allocations in `render_assoc_item`Joshua Nelson-18/+26
`render_assoc_item` came up as very hot in a profile of rustdoc on `bevy`. This avoids some temporary allocations just to calculate the length of the header. This should be a strict improvement, since all string formatting was done twice before.
2021-03-05Don't share `id_map` and `deref_id_map`Camelid-13/+7
All the tests passed, so it doesn't seem they need to be shared. Plus they should be item/page-specific. I'm not sure why they were shared before. I think the reason `id_map` worked as a shared value before is that it is cleared before rendering each item (in `render_item`). And then I'm guessing `deref_id_map` worked because it's a hashmap keyed by `DefId`, so there was no overlap (though I'm guessing we could have had issues in the future). Note that `id_map` currently still has to be cleared because otherwise child items would inherit the `id_map` of their parent. I'm hoping to figure out a way to stop cloning `Context`, but until then we have to reset `id_map`.
2021-03-05rustdoc: Make a bunch of fields privateCamelid-7/+8
Also create issue for removing shared mutable state.
2021-03-05rustdoc: Move most shared fields to `SharedContext`Camelid-7/+22
...and remove `Rc`s for the moved fields. The only shared one that I didn't move was `cache`; see the doc-comment I added to `cache` for details.
2021-03-05Add an unstable option to print all unversioned filesJoshua Nelson-0/+1
This allows sharing those files between different doc invocations without having to know their names ahead of time.
2021-03-04Corrected imports for render tests and mod filesNicholas-Baron-2/+0
Due to a rebase, some edits were needed in the mod file.
2021-03-04Moved `write_shared` to its own fileNicholas-Baron-535/+6
2021-03-04Moved the `make_item_keywords` function to `context.rs` as it is only used thereNicholas-Baron-3/+0
2021-03-04Moved `print_item` and helpers to a separate fileNicholas-Baron-1402/+7
2021-03-04Moved Context and its impls to a separate fileNicholas-Baron-593/+7
2021-03-04Rollup merge of #82310 - jsha:rustdoc-search-onfocus, r=GuillaumeGomezYuki Okushi-7/+10
Load rustdoc's JS search index on-demand. Instead of being loaded on every page, the JS search index is now loaded when either (a) there is a `?search=` param, or (b) the search input is focused. This saves both CPU and bandwidth. As of Feb 2021, https://doc.rust-lang.org/search-index1.50.0.js is 273,838 bytes gzipped or 2,544,939 bytes uncompressed. Evaluating it takes 445 ms of CPU time in Chrome 88 on a i7-10710U CPU (out of a total ~2,100 ms page reload). Tested on Firefox and Chrome. New: https://jacob.hoffman-andrews.com/rust/search-on-demand/std/primitive.slice.html https://jacob.hoffman-andrews.com/rust/search-on-demand/std/primitive.slice.html?search=fn Old: https://jacob.hoffman-andrews.com/rust/search-on-load/std/primitive.slice.html https://jacob.hoffman-andrews.com/rust/search-on-load/std/primitive.slice.html?search=fn
2021-03-03Rollup merge of #81223 - GuillaumeGomez:generate-redirect-map, r=jyn514Yuki Okushi-10/+43
[rustdoc] Generate redirect map file Fixes #81134. So with this code: ```rust #![crate_name = "foo"] pub use private::Quz; pub use hidden::Bar; mod private { pub struct Quz; } #[doc(hidden)] pub mod hidden { pub struct Bar; } #[macro_export] macro_rules! foo { () => {} } ``` It generates: ```json { "foo/macro.foo!.html": "foo/macro.foo.html", "foo/private/struct.Quz.html": "foo/struct.Quz.html", "foo/hidden/struct.Bar.html": "foo/struct.Bar.html" } ``` Do the pathes look as you expected ````@pietroalbini?```` r? ````@jyn514````