about summary refs log tree commit diff
path: root/src/librustdoc/html/render/write_shared.rs
AgeCommit message (Collapse)AuthorLines
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
2023-10-22rustdoc: rename `/implementors` to `/impl.trait`Michael Howell-1/+1
This is shorter, avoids potential conflicts with a crate named `implementors`[^1], and will be less confusing when JS include files are added for type aliases. [^1]: AFAIK, this couldn't actually cause any problems right now, but it's simpler just to make it impossible than relying on never having a file named `trait.Foo.js` in the crate data area.
2023-10-08rustdoc: clean up the In [name] up-pointerMichael Howell-1/+1
This commit makes three changes for consistency and readability: - It shows the sibling navigation on module pages. It's weird that it didn't work before, and is inconsistent with everything else (even Crates have sibling navigation with other Crates). - It hides the "In [parent]" header if it's the same as the current crate, and if there's no other header between them. We need to keep it on modules and types, since they have their own header and data between them, and we don't want to show siblings under a header implying that they're children. - It adds a margin to deal with the headers butting directly into the branding lockup.
2023-10-08rustdoc: remove rust logo from non-Rust cratesMichael Howell-0/+1
2023-08-16Use more named format argsGuillaume Gomez-3/+3
2023-08-16Improve code readability by moving fmt args directly into the stringGuillaume Gomez-10/+9
2023-07-14rustdoc: use `src` consistently over `source` in JavaScriptMichael Howell-4/+4
Since the directory that contains source files is called `src`, it makes sense to name the scripts that way, too.
2023-02-02Auto merge of #107000 - GuillaumeGomez:fix-items-in-doc-hidden-block, ↵bors-1/+1
r=notriddle,petrochenkov Fix handling of items inside a `doc(hidden)` block Fixes #106373. cc `@aDotInTheVoid` r? `@notriddle`
2023-01-30rustdoc: remove meta keywords from HTMLMichael Howell-2/+1
Discussed in <https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/.60.3Cmeta.20name.3D.22keywords.22.3E.60>
2023-01-27Improve code readabilityGuillaume Gomez-1/+1
2023-01-19Revert "Improve code readability"Guillaume Gomez-1/+1
This reverts commit eb93d1bedeab64c6f5d661df6a309a5b8a9273ca.
2023-01-13rustdoc: remove unnecessary DOM class `h1.fqn`Michael Howell-1/+1
It's misleading. The main heading sometimes isn't an fully qualified name at all. It's also redundant. It's always a child of `div.main-heading`, so just use that.
2023-01-06Correctly render sidebar for relative module pathsclubby789-21/+41
2022-12-07Improve code readabilityGuillaume Gomez-1/+1
2022-10-29Generate static file hashes onceJacob Hoffman-Andrews-6/+5
2022-10-29Make --static-root-path point to static.filesJacob Hoffman-Andrews-3/+6
2022-10-29rustdoc: add hash to filename of toolchain filesJacob Hoffman-Andrews-241/+47
All static files used by rustdoc are now stored in static.files/ and include a hash of their contents. They no longer include the contents of the --resource-suffix flag. This clarifies caching semantics. Anything in static.files can use Cache-Control: immutable because any updates will show up as a new URL. Invocation-specific files like crates-NN.js, search-index-NN.js, and sidebar-items-NN.js still get the resource suffix. The --disable-minification flag is removed because it would vary the output of static files based on invocation flags. Instead, for rustdoc development purposes it's preferable to symlink static files to a non-minified copy for quick iteration.
2022-10-05rustdoc: remove unused CSS class `in-band`Michael Howell-3/+1
Since a7c25b29575c17434406b69773f8c2961af343b3 removed `in-band` from code headers, the only remaining uses of the `in-band` class are: https://github.com/rust-lang/rust/blob/02cd79afb8080fce8c8ce35533c54d8ecf8f390e/src/librustdoc/html/render/write_shared.rs#L520-L521 https://github.com/rust-lang/rust/blob/02cd79afb8080fce8c8ce35533c54d8ecf8f390e/src/librustdoc/html/templates/print_item.html#L2-L3 https://github.com/rust-lang/rust/blob/02cd79afb8080fce8c8ce35533c54d8ecf8f390e/src/librustdoc/html/render/context.rs#L637-L638 https://github.com/rust-lang/rust/blob/02cd79afb8080fce8c8ce35533c54d8ecf8f390e/src/librustdoc/html/render/mod.rs#L368-L369 https://github.com/rust-lang/rust/blob/02cd79afb8080fce8c8ce35533c54d8ecf8f390e/src/librustdoc/html/render/mod.rs#L401-L402 https://github.com/rust-lang/rust/blob/02cd79afb8080fce8c8ce35533c54d8ecf8f390e/src/librustdoc/html/static/js/main.js#L525 Since all of these uses are nested below `h1.fqn`, we can get rid of it, and the support code that was used for when `in-band` was part of item rendering.
2022-09-16rustdoc: clean up CSS for All Items and All Crates listsMichael Howell-2/+2
This reduces the amount of CSS, and makes these two pages more consistent (which, necessarily, means changing them a bit).
2022-09-03more clippy::perf fixesMatthias Krüger-1/+1
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-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-06-20Improve loading of crates.js and sidebar-items.jsJacob Hoffman-Andrews-2/+0
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-16Move/rename `lazy::Sync{OnceCell,Lazy}` to `sync::{Once,Lazy}Lock`Maybe Waffle-1/+1
2022-06-07Update minifier version to 0.2.1Guillaume Gomez-4/+6
2022-05-27Pass Context as a &mut to allow to remove RefCell fieldsGuillaume Gomez-5/+7
2022-05-17rustdoc: make search.js a moduleJacob Hoffman-Andrews-1/+7
Previously, search.js relied on the DOM and the `window` object. It can now be loaded in the absence of the DOM, for instance by Node. The same is true of search-index.js. This allows removing a lot of code from src/tools/rustdoc-js/tester.js that tried to parse search.js and extract specific functions that were needed for testing.
2022-05-14Remove theme picker buttonGuillaume Gomez-1/+0
2022-05-12rustdoc: remove weird, unused variable from source-files.jsMichael Howell-1/+1
2022-05-05rustdoc: ensure HTML/JS side implementors don't have dupsMichael Howell-3/+6
2022-04-21Remove .woff font filesGuillaume Gomez-18/+9
2022-04-16Rename `def_id` into `item_id` when the type is `ItemId` for readabilityGuillaume Gomez-1/+1
2022-01-14Auto merge of #91948 - nnethercote:rustdoc-more-Symbols, r=GuillaumeGomezbors-1/+1
rustdoc: avoid many `Symbol` to `String` conversions. Particularly when constructing file paths and fully qualified paths. This avoids a lot of allocations, speeding things up on almost all examples. r? `@GuillaumeGomez`
2022-01-14rustdoc: avoid many `Symbol` to `String` conversions.Nicholas Nethercote-1/+1
Particularly when constructing file paths and fully qualified paths. This avoids a lot of allocations, speeding things up on almost all examples.
2022-01-13Use the updated Rust logo and change it's format to SVGLoïc BRANSTETT-1/+1
2022-01-10Migrate rustdoc from Tera to AskamaDirkjan Ochtman-8/+1
See #84419.
2021-12-15Remove unnecessary sigils around `Symbol::as_str()` calls.Nicholas Nethercote-3/+3
2021-11-24Consistentize the system for image URLs in CSS.Jacob Hoffman-Andrews-28/+20
2021-11-24Move themes and version into rustdoc-varsJacob Hoffman-Andrews-32/+2
We had been injecting the list of themes and the rustdoc version into main.js by rewriting it at doc generation time. By avoiding this rewrite, we can make it easier to edit main.js without regenerating all the docs. Added a more convenient accessor for rustdoc-vars. Changed storage.js to not rely on resourcesSuffix. It could in theory use rustdoc-vars, but because rustdoc-vars is at the end of the HTML, it's not available when storage.js runs (very early in page load).
2021-11-24Simplify rendering of stylesheet links into HTMLJacob Hoffman-Andrews-2/+2
We carry around a list of stylesheets that can carry two different types of thing: 1. Internal stylesheets specific to a page type (only for settings) 2. Themes In this change I move the link generation for settings.css into settings(), so Context.style_files is reserved just for themes. We had two places where we extracted a base theme name from a list of StylePaths. I consolidated that code to be a method on StylePath. I moved generation of link tags for stylesheets into the page.html template. With that change, I made the template responsible for special handling of light.css (making it the default theme) and of the other themes (marking them disabled). That allowed getting rid of the `disabled` field on StylePath.
2021-11-07rustdoc: Remove top-level wrappers for `ImplKind` methodsNoah Lev-1/+1
The `ImplKind` methods can just be used directly instead.
2021-11-07rustdoc: Refactor `Impl.{synthetic,blanket_impl}` into enumNoah Lev-1/+1
This change has two advantages: 1. It makes the possible states clearer, and it makes it impossible to construct invalid states, such as a blanket impl that is also an auto trait impl. 2. It shrinks the size of `Impl` a bit, since now there is only one field, rather than two.