about summary refs log tree commit diff
path: root/src/librustdoc/html/render
AgeCommit message (Collapse)AuthorLines
2020-12-14Switch to Symbol for item.nameJoshua Nelson-16/+13
This decreases the size of `Item` from 680 to 616 bytes. It also does a lot less work since it no longer has to copy as much.
2020-12-14Get rid of `clean::Deprecation`Joshua Nelson-6/+13
This brings the size of `item.deprecation` from 56 to 16 bytes.
2020-12-12Auto merge of #79957 - jyn514:smaller-span, r=GuillaumeGomezbors-9/+17
[rustdoc] Calculate span information on demand instead of storing it ahead of time This brings `size_of<clean::types::Span>()` down from over 100 bytes (!!) to only 12, the same as rustc. It brings `Item` down even more, from `784` to `680`. ~~TODO: I need to figure out how to do this for the JSON backend too. That uses `From` impls everywhere, which don't allow passing in the `Session` as an argument. `@P1n3appl3,` `@tmandry,` maybe one of you have ideas?~~ Figured it out, fortunately only two functions needed to be changed. I like the `convert_x()` format better than `From` everywhere but I'm open to feedback. Helps with #79103
2020-12-12Calculate span info on-demand instead of ahead of timeJoshua Nelson-11/+14
This should *vastly* reduce memory usage.
2020-12-12Pass Session into rendererJoshua Nelson-0/+5
2020-12-07Dogfood 'str_split_once() with librustdocEric Arellano-4/+2
2020-12-03Render Markdown in search resultsCamelid-37/+10
Previously Markdown documentation was not rendered to HTML for search results, which led to the output not being very readable, particularly for inline code. This PR fixes that by rendering Markdown to HTML with the help of pulldown-cmark (the library rustdoc uses to parse Markdown for the main text of documentation). However, the text for the title attribute (the text shown when you hover over an element) still uses the plain-text rendering since it is displayed in browsers as plain-text. Only these styles will be rendered; everything else is stripped away: * *italics* * **bold** * `inline code`
2020-11-29Add support for stable-const-since in docs on items (standalone or assoc)Rune Tynan-17/+73
2020-11-24Clean up document_item_info callsGuillaume Gomez-7/+20
2020-11-24Rename "stability" CSS class to "item-info"Guillaume Gomez-23/+28
2020-11-18add [src] links to methods on a trait's pageNixon Enraght-Moony-19/+12
2020-11-18Extract write_srclink to its own methodNixon Enraght-Moony-30/+24
2020-11-17Rollup merge of #79126 - jyn514:auto, r=GuillaumeGomezMara Bos-3/+3
Remove duplicate `Trait::auto` field It was exactly the same as `is_auto`. I found this while working on #78082, but it's not required for that PR. r? `@GuillaumeGomez`
2020-11-17Remove duplicate `Trait::auto` fieldJoshua Nelson-3/+3
It was exactly the same as `is_auto`.
2020-11-16Get rid of clean::MethodJoshua Nelson-5/+9
Replace it instead with `(clean::Function, Option<hir::Defaultness>)`.
2020-11-16Get rid of clean::TyMethodJoshua Nelson-2/+1
It's the same as clean::Function.
2020-11-16Rollup merge of #79061 - jyn514:no-pub, r=GuillaumeGomezMara Bos-46/+46
Make all rustdoc functions and structs crate-private This gives warnings when code is no longer used, which will be helpful when https://github.com/rust-lang/rust/pull/77820 and https://github.com/rust-lang/rust/pull/78082 land. AFAIK no one is using this API. r? ``@GuillaumeGomez`` cc ``@rust-lang/rustdoc``
2020-11-16Rollup merge of #78678 - Nemo157:doc-cfg-w-traits, r=jyn514,GuillaumeGomezMara Bos-29/+43
Add tests and improve rendering of cfgs on traits Shows the additional features required to get the trait implementation, suppressing any already shown on the current page. One interesting effect from this is if you have a cfg-ed type, implementing a cfg-ed trait (so the implementation depends on both cfgs), you will get the inverted pair of cfgs shown on each page: ![image](https://user-images.githubusercontent.com/81079/97904671-207bdc00-1d41-11eb-8144-707e8017d2b6.png) ![image](https://user-images.githubusercontent.com/81079/97904700-27a2ea00-1d41-11eb-8b9f-e925ba339044.png) The hidden items on the trait implementation also now get the correct cfgs displayed on them. Tests are blocked on #78673. fixes #68100 cc #43781
2020-11-15Make all rustdoc functions and structs crate-privateJoshua Nelson-46/+46
This gives warnings about dead code.
2020-11-15Rollup merge of #79041 - jyn514:inner-to-kind, r=petrochenkovJonas Schievink-30/+29
Rename clean::{ItemEnum -> ItemKind}, clean::Item::{inner -> kind} r? ````@petrochenkov```` cc ````@GuillaumeGomez```` Follow-up to https://github.com/rust-lang/rust/pull/77820#discussion_r502931757.
2020-11-15Rollup merge of #77802 - jyn514:bootstrap-specific, r=nikomatsakisJonas Schievink-2/+2
Allow making `RUSTC_BOOTSTRAP` conditional on the crate name Motivation: This came up in the [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Require.20users.20to.20confirm.20they.20know.20RUSTC_.E2.80.A6.20compiler-team.23350/near/208403962) for https://github.com/rust-lang/compiler-team/issues/350. See also https://github.com/rust-lang/cargo/pull/6608#issuecomment-458546258; this implements https://github.com/rust-lang/cargo/issues/6627. The goal is for this to eventually allow prohibiting setting `RUSTC_BOOTSTRAP` in build.rs (https://github.com/rust-lang/cargo/issues/7088). ## User-facing changes - `RUSTC_BOOTSTRAP=1` still works; there is no current plan to remove this. - Things like `RUSTC_BOOTSTRAP=0` no longer activate nightly features. In practice this shouldn't be a big deal, since `RUSTC_BOOTSTRAP` is the opposite of stable and everyone uses `RUSTC_BOOTSTRAP=1` anyway. - `RUSTC_BOOTSTRAP=x` will enable nightly features only for crate `x`. - `RUSTC_BOOTSTRAP=x,y` will enable nightly features only for crates `x` and `y`. ## Implementation changes The main change is that `UnstableOptions::from_environment` now requires an (optional) crate name. If the crate name is unknown (`None`), then the new feature is not available and you still have to use `RUSTC_BOOTSTRAP=1`. In practice this means the feature is only available for `--crate-name`, not for `#![crate_name]`; I'm interested in supporting the second but I'm not sure how. Other major changes: - Added `Session::is_nightly_build()`, which uses the `crate_name` of the session - Added `nightly_options::match_is_nightly_build`, a convenience method for looking up `--crate-name` from CLI arguments. `Session::is_nightly_build()`should be preferred where possible, since it will take into account `#![crate_name]` (I think). - Added `unstable_features` to `rustdoc::RenderOptions` I'm not sure whether this counts as T-compiler or T-lang; _technically_ RUSTC_BOOTSTRAP is an implementation detail, but it's been used so much it seems like this counts as a language change too. r? `@joshtriplett` cc `@Mark-Simulacrum` `@hsivonen`
2020-11-14Add tests and improve rendering of features on traitsWim Looman-29/+43
2020-11-14Rename ItemEnum -> ItemKind, inner -> kindJoshua Nelson-30/+29
2020-11-10Changed unwrap_or to unwrap_or_else in some places.Nicholas-Baron-1/+1
The discussion seems to have resolved that this lint is a bit "noisy" in that applying it in all places would result in a reduction in readability. A few of the trivial functions (like `Path::new`) are fine to leave outside of closures. The general rule seems to be that anything that is obviously an allocation (`Box`, `Vec`, `vec![]`) should be in a closure, even if it is a 0-sized allocation.
2020-11-07Allow making `RUSTC_BOOTSTRAP` conditional on the crate nameJoshua Nelson-2/+2
The main change is that `UnstableOptions::from_environment` now requires an (optional) crate name. If the crate name is unknown (`None`), then the new feature is not available and you still have to use `RUSTC_BOOTSTRAP=1`. In practice this means the feature is only available for `--crate-name`, not for `#![crate_name]`; I'm interested in supporting the second but I'm not sure how. Other major changes: - Added `Session::is_nightly_build()`, which uses the `crate_name` of the session - Added `nightly_options::match_is_nightly_build`, a convenience method for looking up `--crate-name` from CLI arguments. `Session::is_nightly_build()`should be preferred where possible, since it will take into account `#![crate_name]` (I think). - Added `unstable_features` to `rustdoc::RenderOptions` There is a user-facing change here: things like `RUSTC_BOOTSTRAP=0` no longer active nightly features. In practice this shouldn't be a big deal, since `RUSTC_BOOTSTRAP` is the opposite of stable and everyone uses `RUSTC_BOOTSTRAP=1` anyway. - Add tests Check against `Cheat`, not whether nightly features are allowed. Nightly features are always allowed on the nightly channel. - Only call `is_nightly_build()` once within a function - Use booleans consistently for rustc_incremental Sessions can't be passed through threads, so `read_file` couldn't take a session. To be consistent, also take a boolean in `write_file_header`.
2020-10-30Pull theme picker keyboard code into main.jsMichael Howell-50/+0
Most of the code in mod.rs should be code that really needs to have the list of available themes inlined into it.
2020-10-30Add comment describing the Escape key weirdnessMichael Howell-2/+8
2020-10-30Allow the theme picker to work with arrow keysMichael Howell-2/+46
This is mostly motivated by docs.rs. It's really weird when arrow keys work in the top dropdown menu, but don't work in other dropdown menus on the same page.
2020-10-28rustdoc: Provide a way to set the default settings from Rust codeIan Jackson-0/+2
rustdoc has various user-configurable preferences. These are recorded in web Local Storage (where available). But we want to provide a way to configure the default default, including for when web storage is not available. getSettingValue is the function responsible for looking up these settings. Here we make it fall back some in-DOM data, which ultimately comes from RenderOptions.default_settings. Using HTML data atrtributes is fairly convenient here, dsspite the need to transform between snake and kebab case to avoid the DOM converting kebab case to camel case (!) We cache the element and dataset lookup in a global variable, to ensure that getSettingValue remains fast. The DOM representation has to be in an element which precedes the inclusion of storage.js. That means it has to be in the <head> and we should not use an empty <div> as the container (although most browsers will accept that). An empty <script> element provides a convenient and harmless container object. <meta> would be another possibility but runs a greater risk of having unwanted behaviours on weird browsers. We trust the RenderOptions not to contain unhelpful setting names, which don't fit nicely into an HTML attribute. It's awkward to quote dataset keys. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-10-23Rollup merge of #77920 - ayazhafiz:i/mut-ident-spacing, r=jyn514Yuki Okushi-1/+1
Avoid extraneous space between visibility kw and ident for statics Today, given a static like `static mut FOO: usize = 1`, rustdoc would emit `static mut FOO: usize = 1`, as it emits both the mutability kw with a space and reserves a space after the mutability kw. This patch fixes that misformatting. This patch also adds some tests for emit of other statics, as I could not find an existing test devoted to statics.
2020-10-17Fix some double quote that cause CI failureIvan Tham-3/+3
Co-authored-by: Oliver Middleton <olliemail27@gmail.com>
2020-10-17Use double quote for rustdoc htmlIvan Tham-126/+133
2020-10-16Auto merge of #77809 - nasso:master, r=jyn514,guillaumegomezbors-17/+85
Add settings to rustdoc to use the system theme This PR adds new settings to `rustdoc` to use the operating system color scheme. ![click](https://user-images.githubusercontent.com/11479594/95668052-bf604e80-0b6e-11eb-8a17-473aaae510c9.gif) `rustdoc` actually had [basic support for this](https://github.com/rust-lang/rust/blob/b1af43bc63bc7417938df056f7f25d456cc11b0e/src/librustdoc/html/static/storage.js#L121), but the setting wasn't visible and couldn't be set back once the theme was explicitly set by the user. It also didn't update if the operating system theme preference changed while viewing a page. I'm using [this method](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Testing_media_queries#Receiving_query_notifications) to query and listen to changes to the `(prefers-color-scheme: dark)` media query. I kept the old method (based on `getComputedStyle`) as a fallback in case the user-agent doesn't support `window.matchMedia` (so like... [pretty much nobody](https://caniuse.com/?search=matchMedia)). Since there's now more than one official ""dark"" theme in `rustdoc` (and also to support custom/third-party themes), the preferred dark and light themes can be configured in the settings page (the defaults are just "dark" and "light"). This is also my very first "proper" PR to Rust! Please let me know if I did anything wrong :).
2020-10-16Rollup merge of #77672 - Nemo157:simplify-cfg, r=jyn514Dylan DPC-33/+71
Simplify doc-cfg rendering based on the current context For sub-items on a page don't show cfg that has already been rendered on a parent item. At its simplest this means not showing anything that is shown in the portability message at the top of the page, but also for things like fields of an enum variant if that variant itself is cfg-gated then don't repeat those cfg on each field of the variant. This does not touch trait implementation rendering, as that is more complex and there are existing issues around how it deals with doc-cfg that need to be fixed first. ### Screenshots, left is current, right is new: ![image](https://user-images.githubusercontent.com/81079/95387261-c2e6a200-08f0-11eb-90d4-0a9734acd922.png) ![image](https://user-images.githubusercontent.com/81079/95387458-06411080-08f1-11eb-81f7-5dd7f37695dd.png) ![image](https://user-images.githubusercontent.com/81079/95387702-6637b700-08f1-11eb-82f4-46b6cd9b24f2.png) ![image](https://user-images.githubusercontent.com/81079/95387905-b9aa0500-08f1-11eb-8d95-8b618d31d419.png) ![image](https://user-images.githubusercontent.com/81079/95388300-5bc9ed00-08f2-11eb-9ac9-b92cbdb60b89.png) cc #43781
2020-10-13Avoid extraneous space between visibility kw and ident for staticsayazhafiz-1/+1
Today, given a static like `static mut FOO: usize = 1`, rustdoc would emit `static mut FOO: usize = 1`, as it emits both the mutability kw with a space and reserves a space after the mutability kw. This patch fixes that misformatting. This patch also adds some tests for emit of other statics, as I could not find an existing test devoted to statics.
2020-10-13Make portability log at debug levelWim Looman-2/+2
2020-10-13Coding style fixesnasso-4/+4
2020-10-13Remove unnecessary refsnasso-10/+5
2020-10-13Add a setting to use the system themenasso-15/+88
2020-10-11Move `PartialOrd` impl out of rustcJoshua Nelson-6/+6
Rustdoc's ordering requirements are probably not relevant to the rest of the compiler.
2020-10-11Switch rustdoc from `clean::Stability` to `rustc_attr::Stability`Joshua Nelson-21/+29
This gives greater type safety and is less work to maintain on the rustdoc end.
2020-10-09Simplify included import items handlingGuillaume Gomez-10/+9
2020-10-09Correctly handle "pub use" reexportsGuillaume Gomez-6/+8
2020-10-07Simplify doc-cfg rendering based on the current contextWim Looman-33/+71
For sub-items on a page don't show cfg that has already been rendered on a parent item. At its simplest this means not showing anything that is shown in the portability message at the top of the page, but also for things like fields of an enum variant if that variant itself is cfg-gated then don't repeat those cfg on each field of the variant. This does not touch trait implementation rendering, as that is more complex and there are existing issues around how it deals with doc-cfg that need to be fixed first.
2020-10-06Fix toolsMatthew Jasper-1/+1
2020-09-23Use theme-adaptive SVG favicon from other Rust sitesJarek Samic-1/+3
2020-09-05Rollup merge of #76078 - jyn514:no-disambiguator, r=manishearthDylan DPC-4/+3
Remove disambiguators from intra doc link text Closes https://github.com/rust-lang/rust/issues/65354. r? @Manishearth The commits are mostly atomic, but there might be some mix between them here and there. I recommend reading 'refactor ItemLink' and 'refactor RenderedLink' on their own though, lots of churn without any logic changes.
2020-09-03Auto merge of #73819 - euclio:rustdoc-summaries, r=jyn514,GuillaumeGomezbors-32/+36
rustdoc: do not use plain summary for trait impls Fixes #38386. Fixes #48332. Fixes #49430. Fixes #62741. Fixes #73474. Unfortunately this is not quite ready to go because the newly-working links trigger a bunch of linkcheck failures. The failures are tough to fix because the links are resolved relative to the implementor, which could be anywhere in the module hierarchy. (In the current docs, these links end up rendering as uninterpreted markdown syntax, so I don't think these failures are any worse than the status quo. It might be acceptable to just add them to the linkchecker whitelist.) Ideally this could be fixed with intra-doc links ~~but it isn't working for me: I am currently investigating if it's possible to solve it this way.~~ Opened #73829. EDIT: This is now ready!
2020-09-03Remove disambiguators from link textJoshua Nelson-2/+1
Related to https://github.com/rust-lang/rust/issues/65354 - Pass through the replacement text to `markdown.rs` - Add some tests - Add a state machine that actually replaces the text when parsing Markdown
2020-09-03Refactor RenderedLink into its own typeJoshua Nelson-2/+2