about summary refs log tree commit diff
path: root/src/librustdoc/html
AgeCommit message (Collapse)AuthorLines
2021-03-10Rollup merge of #82962 - notriddle:cleanup-index, r=jyn514Dylan DPC-5/+3
Treat header as first paragraph for shortened markdown descriptions "The Rust Standard LibraryThe Rust Standard Library is the …" is an awful description.
2021-03-10Rollup merge of #82807 - notriddle:cleanup-js, r=jyn514Dylan DPC-10/+2
rustdoc: Remove redundant enableSearchInput function enableSearchInput was called from two places: - setupSearchLoader - addSearchOptions, which is itself called from setupSearchLoader only This commit can safely get rid of the addSearchOptions calls entirely, and since the setupSearchLoader call is immediately preceded by other method calls on search_input, there's no need to check if it's set.
2021-03-10Fix "run" button position in error indexGuillaume Gomez-1/+1
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-09Treat header as first paragraph for shortened markdown descriptionsMichael Howell-0/+2
"The Rust Standard LibraryThe Rust Standard Library is the …" is an awful description.
2021-03-09Fix typoGuillaume Gomez-1/+1
2021-03-09Fix CSS issues when javascript is disabledGuillaume Gomez-0/+10
2021-03-09Auto merge of #82356 - camelid:render-cleanup, r=GuillaumeGomezbors-57/+74
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/+30
`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-07Update Source Code Pro and include italicsTrevor Spiteri-9/+22
2021-03-07Rollup merge of #82803 - jyn514:unversioned-files, r=GuillaumeGomezYuki Okushi-15/+25
rustdoc: Add an unstable option to print all unversioned files This allows sharing those files between different doc invocations without having to know their names ahead of time. Helps with https://github.com/rust-lang/docs.rs/issues/1302. r? ````@GuillaumeGomez```` cc ````@pietroalbini```` ````@Nemo157````
2021-03-05Undo addition of boxesCamelid-8/+7
I don't think the boxing helped performance, in fact I think it potentially made it worse. The data was still being copied, but now it was through a pointer. Thinking about it more, I think boxing might only help when you're passing a big object around by value all the time, rather than the slowdown being that you're cloning it.
2021-03-05Don't unnecessarily clone some fields in `Context`Camelid-19/+18
There was no need to clone `id_map` because it was reset before each item was rendered. `deref_id_map` was not reset, but it was keyed by `DefId` and thus was unlikely to have collisions (at least for now). Now we just clone the fields that need to be cloned, and instead create fresh versions of the others.
2021-03-05Box some fields to reduce `Context` sizeCamelid-5/+5
Reduced from 152 bytes to 88 bytes.
2021-03-05Don't share `id_map` and `deref_id_map`Camelid-21/+20
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: Add static size assertion for `Context`Camelid-0/+4
It's cloned a lot, so we don't want it to grow in size unexpectedly. Only run the assert on x86-64 since the size is architecture-dependent.
2021-03-05rustdoc: Make a bunch of fields privateCamelid-12/+18
Also create issue for removing shared mutable state.
2021-03-05rustdoc: Replace `Arc` around `SharedContext` with `Rc`Camelid-6/+5
It doesn't look like it's shared across threads, so it doesn't need to be thread-safe. Of course, since we're using Rust, we'll get an error if we try to share it across threads, so this should be safe :)
2021-03-05rustdoc: Move most shared fields to `SharedContext`Camelid-37/+48
...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-05Rollup merge of #82809 - notriddle:microoptimize-main-js, r=GuillaumeGomezGuillaume Gomez-3/+3
rustdoc: Use substrings instead of split to grab enum variant paths Both versions are about equally readable, but this version avoids scanning the entire path and building an intermediate array (`split()` in Rust is a lazy iterator, but not in JavaScript).
2021-03-05Rollup merge of #80845 - GuillaumeGomez:item-kind-transition, r=jyn514Guillaume Gomez-3/+3
Make ItemKind::ExternCrate looks like hir::ItemKind::ExternCrate to make transition over hir::ItemKind simpler It was surprisingly difficult to make this change, mostly because of two issues: * We now store the `ExternCrate` name in the parent struct (`clean::Item`), which forced me to modify the json conversion code a bit more than expected. * The second problem was that, since we now have a `Some(name)`, it was trying to render it, ending up in a panic because we ended up in a `unreachable` statement. The solution was simply to add `!item.is_extern_crate()` in `formats::renderer` before calling `cx.item(item, &cache)?;`. I'll continue to replace all the `clean::ItemKind` variants one by one until it looks exactly like `hir::ItemKind`. Then we'll simply discard the rustdoc type. Once this done, we'll be able to discard `clean::Item` too to use `hir::Item`. r? ``@jyn514``
2021-03-05Add an unstable option to print all unversioned filesJoshua Nelson-18/+22
This allows sharing those files between different doc invocations without having to know their names ahead of time.
2021-03-05Use substrings instead of split to grab enum variant pathsMichael Howell-3/+3
Both versions are about equally readable, but this version avoids scanning the entire path and building an intermediate array (`split()` in Rust is a lazy iterator, but not in JavaScript).
2021-03-05Remove redundant enableSearchInput functionMichael Howell-10/+2
enableSearchInput was called from two places: - setupSearchLoader - addSearchOptions, which is itself called from setupSearchLoader only This commit can safely get rid of the addSearchOptions calls entirely, and since the setupSearchLoader call is immediately preceded by other method calls on search_input, there's no need to check if it's set.
2021-03-05Store `UNVERSIONED_FILES` in a data structureJoshua Nelson-15/+21
This allows querying it programatically.
2021-03-05Use global variables instead of functions for DOM IDsGuillaume Gomez-16/+11
2021-03-05Clean up code around theme elementsGuillaume Gomez-11/+19
2021-03-05Remove theme.js file creation and move its code inside main.jsGuillaume Gomez-67/+74
2021-03-05Make ItemKind::ExternCrate looks like hir::ItemKind::ExternCrate to make ↵Guillaume Gomez-3/+3
transition over hir::ItemKind simpler
2021-03-05Auto merge of #82795 - m-ou-se:rollup-uzx0b92, r=m-ou-sebors-20/+0
Rollup of 10 pull requests Successful merges: - #80723 (Implement NOOP_METHOD_CALL lint) - #80763 (resolve: Reduce scope of `pub_use_of_private_extern_crate` deprecation lint) - #81136 (Improved IO Bytes Size Hint) - #81939 (Add suggestion `.collect()` for iterators in iterators) - #82289 (Fix underflow in specialized ZipImpl::size_hint) - #82728 (Avoid unnecessary Vec construction in BufReader) - #82764 (Add {BTreeMap,HashMap}::try_insert) - #82770 (Add assert_matches macro.) - #82773 (Add diagnostic item to `Default` trait) - #82787 (Remove unused code from main.js) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-03-04Remove unused code from main.jsMichael Howell-20/+0
It looks like `lev_distance` was used in a very old version of the function, since it was written but never read, and Blame reports that it was added before the `checkGenerics` function header itself. `convertHTMLToPlaintext` is was removed by 768d5e950953738a54480e530341964838d29da2
2021-03-04Corrected imports for render tests and mod filesNicholas-Baron-3/+4
Due to a rebase, some edits were needed in the mod file.
2021-03-04Moved `write_shared` to its own fileNicholas-Baron-535/+549
2021-03-04Moved the `make_item_keywords` function to `context.rs` as it is only used thereNicholas-Baron-5/+6
2021-03-04Moved `print_item` and helpers to a separate fileNicholas-Baron-1404/+1430
2021-03-04Moved Context and its impls to a separate fileNicholas-Baron-593/+618
2021-03-04Rollup merge of #82315 - jsha:font-display-swap, r=GuillaumeGomezYuki Okushi-5/+13
Improve page load performance in rustdoc Add an explicit height to icons (which already had an explicit width) to allow browsers to lay out the page more accurately before the icons have been loaded. https://web.dev/optimize-cls/. Add min-width: 115px to the crate search dropdown. When the HTML first loads, this dropdown includes only the text "All crates." Later, JS loads the items underneath it, some of which are wider. That causes the dropdown to get wider, causing a distracting reflow. This sets a min-width based on the size that the dropdown eventually becomes based on the crates on doc.rust-lang.org, reducing page movement during load. Add font-display: swap. Per https://web.dev/font-display/, this prevents "flash of invisible text" during load by using a system font until the custom font is available. I've noticed this flash of invisible text occasionally when reading Rust docs. Note that users without cached fonts will see text, and then see it reflow. For `docs.rust-lang.org`, [setting caching headers will help a lot](https://github.com/rust-lang/simpleinfra/issues/62). Generated output at https://jacob.hoffman-andrews.com/rust/flow-improvements/std/string/struct.String.html.
2021-03-04Rollup merge of #82310 - jsha:rustdoc-search-onfocus, r=GuillaumeGomezYuki Okushi-51/+69
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-04Rollup merge of #80527 - jyn514:rustdoc-lints, r=GuillaumeGomezYuki Okushi-2/+1
Make rustdoc lints a tool lint instead of built-in - Rename `broken_intra_doc_links` to `rustdoc::broken_intra_doc_links` (and similar for other rustdoc lints; I don't expect any others to be used frequently, though). - Ensure that the old lint names still work and give deprecation errors - Register lints even when running doctests - Move lint machinery into a separate file - Add `declare_rustdoc_lint!` macro Unblocks https://github.com/rust-lang/rust/pull/80300, https://github.com/rust-lang/rust/pull/79816, https://github.com/rust-lang/rust/pull/80965. Makes the strangeness in https://github.com/rust-lang/rust/pull/77364 more apparent to the end user (note that `missing_docs` is *not* moved to rustdoc in this PR). Closes https://github.com/rust-lang/rust/issues/78786. ## Current status This is blocked on #82620 (see https://github.com/rust-lang/rust/pull/80527#issuecomment-787401519)
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````
2021-03-02Use Arial as fallback font instead of sans-serif.Jacob Hoffman-Andrews-3/+3
On most platforms and browsers, `sans-serif` is equivalent to Arial. However, on Firefox on Ubuntu (and possibly other Linuxes), `sans-serif` is DejaVu Sans, a much wider font. This creates a larger shift in text when the custom fonts finally load. Arial is a web-safe font, and specifying it explicitly gives us more cross-platform consistency, as well as reducing the layout shift that happens when fonts load.
2021-03-02Improve page load performance in rustdoc.Jacob Hoffman-Andrews-2/+10
Add font-display: swap. Per https://web.dev/font-display/, this prevents "flash of invisible text" during load by using a system font until the custom font is available. I've noticed this flash of invisible text occasionally when reading Rust docs. Add an explicit height to icons (which already had an explicit width) to allow browsers to lay out the page more accurately before the icons have been loaded. https://web.dev/optimize-cls/. Add min-width: 115px to the crate search dropdown. When the HTML first loads, this dropdown includes only the text "All crates." Later, JS loads the items underneath it, some of which are wider. That causes the dropdown to get wider, causing a distracting reflow. This sets a min-width based on the size that the dropdown eventually becomes based on the crates on doc.rust-lang.org, reducing page movement during load.
2021-03-02Load rustdoc's JS search index on-demand.Jacob Hoffman-Andrews-51/+69
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). Generate separate JS file with crate names. This is much smaller than the full search index, and is used in the "hot path" to draw the page. In particular it's used to crate the dropdown for the search bar, and to append a list of crates to the sidebar (on some pages). Skip early search that can bypass 500ms timeout. This was occurring when someone had typed some text during the load of search-index.js. Their query was usually not ready to execute, and the search itself is fairly expensive, delaying the overall load, which delayed the input / keyup events, which delayed eventually executing the query.
2021-03-01Move lint machinery into a separate fileJoshua Nelson-1/+1
2021-03-01Rename rustdoc lints to be a tool lint instead of built-in.Joshua Nelson-2/+1
- Rename `broken_intra_doc_links` to `rustdoc::broken_intra_doc_links` - Ensure that the old lint names still work and give deprecation errors - Register lints even when running doctests Otherwise, all `rustdoc::` lints would be ignored. - Register all existing lints as removed This unfortunately doesn't work with `register_renamed` because tool lints have not yet been registered when rustc is running. For similar reasons, `check_backwards_compat` doesn't work either. Call `register_removed` directly instead. - Fix fallout + Rustdoc lints for compiler/ + Rustdoc lints for library/ Note that this does *not* suggest `rustdoc::broken_intra_doc_links` for `rustdoc::intra_doc_link_resolution_failure`, since there was no time when the latter was valid.
2021-03-01Remove the dummy cache in `DocContext`Joshua Nelson-2/+1
The same information is available everywhere; the only reason the dummy cache was needed is because it waas previously stored in three different places. This consolidates the info a bit so the cache in `DocContext` is used throughout. As a bonus, it means `renderinfo` is used much much less. - Return a `Cache` from `run_global_ctxt`, not `RenderInfo` - Remove the unused `render_info` from `run_renderer` - Remove RefCell around `inlined` - Add intra-doc links
2021-02-27Add ARIA role to sidebar toggle in RustdocVincent Ambo-1/+1
This indicates that the div is an interactive element, and makes the sidebar toggle "clickable" in assistive technologies. Fixes #82582
2021-02-27Auto merge of #82511 - jsha:fix-bfcache2, r=GuillaumeGomezbors-6/+14
Fix back-forward cache in rustdoc frontend Rustdoc's frontend set a no-op unload handler, specifically to disable Firefox's back-forward cache because it caused a bug. It's nice to allow the back-forward cache because it permits faster navigations. This change addresses the issues that were caused by back-forward cache. https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/1.5/Using_Firefox_1.5_caching https://web.dev/bfcache/ Demo: https://jacob.hoffman-andrews.com/rust/fix-bfcache/std/string/struct.String.html Related: #72272
2021-02-26Rollup merge of #82549 - rust-lang:revert-82313-update-normalize-css, r=apirainoGuillaume Gomez-1/+1
Revert "Update normalize.css to 8.0.1" Reverts rust-lang/rust#82313 Fixes #82548 Fixes #82542 ``@jsha:`` I'm reverting until we can come up with a new version which is fully working. r? ``@jyn514``
2021-02-26Rollup merge of #82545 - jsha:woff2, r=GuillaumeGomezGuillaume Gomez-2/+14
rustdoc: add optional woff2 versions of FiraSans. For browsers that support woff2 (most modern ones: https://caniuse.com/woff2), this offers a reduction in download size for these two fonts from 362k to 257k (32% reduction). It decreases the total page size for `struct.String.html` (counting all subresources) by about 2.5%. If this is interesting, I'm happy to apply the same treatment to the other fonts, but these two are the biggest.