about summary refs log tree commit diff
path: root/src/librustdoc/html
AgeCommit message (Collapse)AuthorLines
2023-11-18rustdoc-search: switch to recursive backtrackingMichael Howell-157/+87
This is significantly faster, because - It allows the one-element fast path to kick in on multi- element queries. - It constructs intermediate data structures more lazily than the old system did. It's measurably faster than the old algo even without the fast path, but that fast path still helps significantly.
2023-11-17rustdoc-search: fix accidental shared, mutable mapMichael Howell-30/+14
2023-11-17rustdoc-search: fast path for 1-query unificationMichael Howell-2/+76
Short queries, in addition to being common, are also the base case for a lot of more complicated queries. We can avoid most of the backtracking data structures, and use simple recursive matching instead, by special casing them. Profile output: https://notriddle.com/rustdoc-html-demo-5/profile-3/index.html
2023-11-17rustdoc-search: less new Maps in unifyFunctionTypeMichael Howell-16/+31
This is a major source of expense on generic queries, and this commit reduces them. Profile output: https://notriddle.com/rustdoc-html-demo-5/profile-2/index.html
2023-11-16Auto merge of #117875 - Mark-Simulacrum:bootstrap-bump, r=clubby789bors-106/+140
Bootstrap bump Bumps bootstrap compiler to just-released beta. https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2023-11-15Re-format code with new rustfmtMark Rousskov-106/+140
2023-11-15rustdoc-search: simplify the checkTypes fast pathMichael Howell-61/+10
This reduces code size while still matching the common case for plain, concrete types.
2023-11-14Auto merge of #117849 - compiler-errors:cycle, r=cjgillotbors-1/+1
make `LayoutError::Cycle` carry `ErrorGuaranteed` Addresses a FIXME, and also I think it's wise for error variants to carry their `ErrorGuaranteed` -- makes it easier to use that `ErrorGuaranteed` for creating, e.g. `TyKind::Error` and other error kinds. Splitting out from #117703.
2023-11-12rustdoc: use `.rustdoc` class instead of `body`Michael Howell-2/+2
This didn't show up in our local tests, because the problem is actually caused by docs.rs rewritten HTML (which relocates the classes that this code looked for from the body tag to a child div). Fixes #117290
2023-11-12make LayoutError::Cycle carry ErrorGuaranteedMichael Goulet-1/+1
2023-11-08rustdoc: minor changes suggested by clippy perf lints.Nicholas Nethercote-9/+6
2023-11-07Auto merge of #115904 - notriddle:notriddle/preload-bold, r=GuillaumeGomezbors-1/+0
rustdoc: stop preloading Source Serif 4 Bold According to #91170, italic fonts are not preloaded because they're rarely used, but bold fonts are. This seems to be true of bold Source Code Pro and bold Fira Sans, but bold and italic Source Serif Pro seem to be equally heavily used. This is, I assume, the result of using Fira Sans Bold and Source Code Bold headings, so you only get bold Serif text when the doc author uses strong `**` emphasis (or within certain kinds of tooltip, which shouldn't be preloaded because they only show up long after the page is loaded). To check this, run these two commands in the browser console to measure how much they're used. The measurement is extremely rough, but it gets the idea across: the two styles are about equally popular. // count bold elements Array.prototype.slice.call(document.querySelectorAll("*")).filter(x => { const y = document.defaultView.getComputedStyle(x); return y.fontFamily.indexOf("Source Serif 4") !== -1 && y.fontWeight > 400 }).length // count italic elements Array.prototype.slice.call(document.querySelectorAll("*")).filter(x => { const y = document.defaultView.getComputedStyle(x); return y.fontFamily.indexOf("Source Serif 4") !== -1 && y.fontStyle == "italic" }).length | URL | Bold | Italic | |--------------|-----:|-------:| | [std] | 2 | 9 | | [Vec] | 8 | 89 | | [regex] | 33 | 17 | | [test_suite] | 0 | 0 | [std]: https://doc.rust-lang.org/nightly/std/index.html [Vec]: https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html [regex]: https://docs.rs/regex/1.9.5/regex/index.html [test_suite]: https://docs.rs/test-suite/3.2.9/test_suite/
2023-11-04Auto merge of #117540 - ↵bors-2/+2
matthiaskrgr:baby_dont_clone_me_dont_clone_me_no_more, r=est31 clone less
2023-11-03Auto merge of #117507 - nnethercote:rustc_span, r=Nilstriebbors-4/+2
`rustc_span` cleanups Just some things I found while looking over this crate. r? `@oli-obk`
2023-11-03clone lessMatthias Krüger-2/+2
2023-11-02Fix order of implementations in the "implementations on foreign types" sectionGuillaume Gomez-1/+2
2023-11-02Minimize `pub` usage in `source_map.rs`.Nicholas Nethercote-4/+2
Most notably, this commit changes the `pub use crate::*;` in that file to `use crate::*;`. This requires a lot of `use` items in other crates to be adjusted, because everything defined within `rustc_span::*` was also available via `rustc_span::source_map::*`, which is bizarre. The commit also removes `SourceMap::span_to_relative_line_string`, which is unused.
2023-10-31Rollup merge of #113241 - poliorcetics:85138-doc-object-safety, r=GuillaumeGomezMatthias Krüger-0/+24
rustdoc: Document lack of object safety on affected traits Closes #85138 I saw the issue didn't have any recent activity, if there is another MR for it I missed it. I want the issue to move forward so here is my proposition. It takes some space just before the "Implementors" section and only if the trait is **not** object safe since it is the only case where special care must be taken in some cases and this has the benefit of avoiding generation of HTML in (I hope) the common case.
2023-10-30Descriptive variant name deprecation versions outside the standard libraryDavid Tolnay-1/+1
2023-10-30Represent absence of 'since' attribute as a variant of DeprecatedSinceDavid Tolnay-4/+4
2023-10-30Add a DeprecatedSince::Err variant for versions that fail to parseDavid Tolnay-9/+10
2023-10-30Move deprecation_in_effect to inherent method on DeprecationDavid Tolnay-8/+2
2023-10-29Store version of `deprecated` attribute in structured formDavid Tolnay-8/+5
2023-10-29Rename Since -> StableSince in preparation for a DeprecatedSinceDavid Tolnay-11/+11
2023-10-29feat: Add 'object-safety' ID to init_id_map() in rustdocAlexis (Poliorcetics) Bourget-1/+3
2023-10-29feat: render Object Safety informations non-object safe traitsAlexis (Poliorcetics) Bourget-0/+22
2023-10-28Rollup merge of #117256 - dtolnay:currentversion, r=compiler-errorsJubilee-2/+3
Parse rustc version at compile time This PR eliminates a couple awkward codepaths where it was not clear how the compiler should proceed if its own version number is incomprehensible. https://github.com/rust-lang/rust/blob/dab715641e96a61a534587fda9de1128b75b34dc/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs#L385 https://github.com/rust-lang/rust/blob/dab715641e96a61a534587fda9de1128b75b34dc/compiler/rustc_attr/src/builtin.rs#L630 We can guarantee that every compiled rustc comes with a working version number, so the ICE codepaths above shouldn't need to be written.
2023-10-27Auto merge of #116471 - notriddle:notriddle/js-trait-alias, r=GuillaumeGomezbors-103/+637
rustdoc: use JS to inline target type impl docs into alias Preview docs: - https://notriddle.com/rustdoc-html-demo-5/js-trait-alias/std/io/type.Result.html - https://notriddle.com/rustdoc-html-demo-5/js-trait-alias-compiler/rustc_middle/ty/type.PolyTraitRef.html This pull request also includes a bug fix for trait alias inlining across crates. This means more documentation is generated, and is why ripgrep runs slower (it's a thin wrapper on top of the `grep` crate, so 5% of its docs are now the Result type). - Before, built with rustdoc 1.75.0-nightly (aa1a71e9e 2023-10-26), Result type alias method docs are missing: http://notriddle.com/rustdoc-html-demo-5/ripgrep-js-nightly/rg/type.Result.html - After, built with this branch, all the methods on Result are shown: http://notriddle.com/rustdoc-html-demo-5/ripgrep-js-trait-alias/rg/type.Result.html *Review note: This is mostly just reverting https://github.com/rust-lang/rust/pull/115201. The last commit has the new work in it.* Fixes #115718 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-26Parse rustc version at compile timeDavid Tolnay-2/+3
2023-10-24Expose a non-Symbol way to access current rustc version stringDavid Tolnay-2/+2
2023-10-24Handle structured stable attribute 'since' version in rustdocDavid Tolnay-9/+22
2023-10-23Rollup merge of #105666 - notriddle:notriddle/stab-baseline, r=GuillaumeGomezMatthias Krüger-0/+1
rustdoc: align stability badge to baseline instead of bottom | desc | img | |------|-----| | before | ![image](https://user-images.githubusercontent.com/1593513/207412598-3a6468ca-a169-4810-a689-4797688385df.png) | | | | | after | ![image](https://user-images.githubusercontent.com/1593513/207412720-b120269a-48a3-40e9-a9b0-6769bb05e104.png) | Preview: http://notriddle.com/notriddle-rustdoc-demos/stab-baseline/test_dingus/index.html Based on comment from https://github.com/rust-lang/rust/pull/105509#discussion_r1044816673 r? ``@joshtriplett``
2023-10-22rustdoc: make JS trait impls act more like HTMLMichael Howell-6/+31
2023-10-22rustdoc: clean up and comment main.js `register_type_impls`Michael Howell-14/+44
2023-10-22rustdoc: clean up sidebar.html block classMichael Howell-5/+1
This line is longer than 100 characters, but apparently, [tidy's list of checked extensions] doesn't include html, so the line length doesn't matter. [tidy's list of checked extensions]: https://github.com/rust-lang/rust/blob/31be8cc41148983e742fea8f559aacca0f6647db/src/tools/tidy/src/style.rs#L245
2023-10-22rustdoc: use JS to inline target type impl docs into aliasMichael Howell-24/+563
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-22Revert "rustdoc: list matching impls on type aliases"Michael Howell-42/+4
This reverts commit 19edb3ce808ee2b1190026b9d56cc6187e1ad9b1.
2023-10-22Revert "Add note about lazy_type_alias"Michael Howell-2/+2
This reverts commit b3686c2fd6ad57912e1b0e778bedb0b9a05c73fa.
2023-10-22Revert "rustdoc: add impl items from aliased type into sidebar"Michael Howell-40/+5
This reverts commit d882b2118e505d86a9f770ef862fb1ee6e91ced8.
2023-10-22Revert "rustdoc: factor all-impls-for-item out into its own method"Michael Howell-55/+78
This reverts commit c3e5ad448b87be31e570c048cf7ba3b1e7daec44.
2023-10-22Revert "rustdoc: filter before storing in vec"Michael Howell-10/+4
This reverts commit c79b960747487f6724ebe5b163a22c82a2b636d3.
2023-10-22rustdoc: rename `/implementors` to `/impl.trait`Michael Howell-5/+5
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-21rustdoc: avoid allocating strings primitive link printingMichael Howell-26/+51
This is aimed at hitting the allocator less in a function that gets called a lot.
2023-10-17[RFC 3127 - Trim Paths]: Fix building tools (rustdoc, clippy, ...)Urgau-1/+2
2023-10-14Rollup merge of #115439 - fmease:rustdoc-priv-repr-transparent-heuristic, ↵Matthias Krüger-20/+19
r=GuillaumeGomez rustdoc: hide `#[repr(transparent)]` if it isn't part of the public ABI Fixes #90435. This hides `#[repr(transparent)]` when the non-1-ZST field the struct is "transparent" over is private. CC `@RalfJung` Tentatively nominating it for the release notes, feel free to remove the nomination. `@rustbot` label needs-fcp relnotes A-rustdoc-ui
2023-10-12Hide host effect params from docsOli Scherer-2/+1
2023-10-11Improve code documentation a bitGuillaume Gomez-2/+2
2023-10-11Show enum discriminant if a compatible repr is usedGuillaume Gomez-10/+24
2023-10-11rustdoc: fix resize trouble with mobileMichael Howell-0/+4
2023-10-11rustdoc: avoid whole page layout on each frameMichael Howell-9/+67
This makes two changes, based on experimenting with different browsers: - It debounces resizing the body text. This improves behavior on huge pages like struct.Vec.html, because it doesn't have to do layout. - It does the sidebar width updates directly on the sidebar instead of doing it on the `<HTML>` element. Doing it on `<HTML>` causes it to recalculate CSS for the entire document, also causing layout jank.