about summary refs log tree commit diff
path: root/src/librustdoc/html
AgeCommit message (Collapse)AuthorLines
2023-09-21Record asyncness span in HIRMichael Goulet-1/+1
2023-09-20rustdoc: add comment about numeric spacingMichael Howell-0/+4
2023-09-19rustdoc: add test cases, and fix, search tabsMichael Howell-6/+15
2023-09-19Rollup merge of #115947 - ↵Guillaume Gomez-116/+180
GuillaumeGomez:custom_code_classes_in_docs-warning, r=notriddle Custom code classes in docs warning Fixes https://github.com/rust-lang/rust/issues/115938. This PR does two things: 1. Unless the `custom_code_classes_in_docs` feature is enabled, it will use the old codeblock tag parser. 2. If there is a codeblock tag that starts with a `.`, it will emit a behaviour change warning. Hopefully this is the last missing part for this feature until stabilization. Follow-up of https://github.com/rust-lang/rust/pull/110800. r? `@notriddle`
2023-09-19Allow more characters in custom classesGuillaume Gomez-12/+45
2023-09-19Rollup merge of #112725 - notriddle:notriddle/advanced-search, r=GuillaumeGomezGuillaume Gomez-405/+636
rustdoc-search: add support for type parameters r? `@GuillaumeGomez` ## Preview * https://notriddle.com/rustdoc-html-demo-4/advanced-search/rustdoc/read-documentation/search.html * https://notriddle.com/rustdoc-html-demo-4/advanced-search/std/index.html?search=option%3Coption%3CT%3E%3E%20-%3E%20option%3CT%3E * https://notriddle.com/rustdoc-html-demo-4/advanced-search/std/index.html?search=option%3CT%3E,%20E%20-%3E%20result%3CT,%20E%3E * https://notriddle.com/rustdoc-html-demo-4/advanced-search/std/index.html?search=-%3E%20option%3CT%3E ## Description When writing a type-driven search query in rustdoc, specifically one with more than one query element, non-existent types become generic parameters instead of auto-correcting (which is currently only done for single-element queries) or giving no result. You can also force a generic type parameter by writing `generic:T` (and can force it to not use a generic type parameter with something like `struct:T` or whatever, though if this happens it means the thing you're looking for doesn't exist and will give you no results). There is no syntax provided for specifying type constraints for generic type parameters. When you have a generic type parameter in a search query, it will only match up with generic type parameters in the actual function, not concrete types that match, not concrete types that implement a trait. It also strictly matches based on when they're the same or different, so `option<T>, option<U> -> option<U>` matches `Option::and`, but not `Option::or`. Similarly, `option<T>, option<T> -> option<T>` matches `Option::or`, but not `Option::and`. ## Motivation This feature is motivated by the many "combinitor"-type functions found in generic libraries, such as Option, Future, Iterator, and Entry. These highly-generic functions have names that are almost completely arbitrary, and a type signature that tells you what it actually does. This PR is a major step towards[^closure] being able to easily search for generic functions by their type signature instead of by name. Some examples of combinators that can be found using this PR (try them out in the preview): * `option<option<T>> -> option<T>` returns Option::flatten * `option<T> -> result<T>` returns Option::ok_or * `option<result<T>> -> result<option<T>>` returns Option::transpose * `entry<K, V>, FnOnce -> V` returns `Entry::or_insert_with` (and `or_insert_with_key`, since there's no way to specify the generics on FnOnce) [^closure]: For this feature to be as useful as it ought to be, you should be able to search for *trait-associated types* and *closures*. This PR does not implement either of these: they are **Future possibilities**. Trait-associated types would allow queries like `option<T> -> iterator<item=T>` to return `Option::iter`. We should also allow `option<T> -> iterator<T>` to match the associated type version. Closures would make a good way to query for things like `Option::map`. Closure support needs associated types to be represented in the search index, since `FnOnce() -> i32` desugars to `FnOnce<Output=i32, ()>`, so associated trait types should be implemented first. Also, we'd want to expose an easy way to query closures without specifying which of the three traits you want.
2023-09-18Use old parser if `custom_code_classes_in_docs` feature is not enabledGuillaume Gomez-104/+135
2023-09-18rustdoc: hide repr(transparent) if it isn't part of the public ABILeón Orell Valerian Liehr-20/+19
2023-09-18Move mobile topbar title creation entirely into JSGuillaume Gomez-5/+6
2023-09-17Update tests for `custom_code_classes_in_docs` featureGuillaume Gomez-2/+5
2023-09-17Don't emit an error if the `custom_code_classes_in_docs` feature is disabled ↵Guillaume Gomez-18/+86
when its syntax is used.
2023-09-16rustdoc: stop preloading Source Serif 4 BoldMichael Howell-1/+0
According to 4198fac7390509128c42757fcfb89a0effde4a8e, 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 | [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
2023-09-16Auto merge of #110800 - GuillaumeGomez:custom_code_classes_in_docs, r=t-rustdocbors-72/+536
Accept additional user-defined syntax classes in fenced code blocks Part of #79483. This is a re-opening of https://github.com/rust-lang/rust/pull/79454 after a big update/cleanup. I also converted the syntax to pandoc as suggested by `@notriddle:` the idea is to be as compatible as possible with the existing instead of having our own syntax. ## Motivation From the original issue: https://github.com/rust-lang/rust/issues/78917 > The technique used by `inline-c-rs` can be ported to other languages. It's just super fun to see C code inside Rust documentation that is also tested by `cargo doc`. I'm sure this technique can be used by other languages in the future. Having custom CSS classes for syntax highlighting will allow tools like `highlight.js` to be used in order to provide highlighting for languages other than Rust while not increasing technical burden on rustdoc. ## What is the feature about? In short, this PR changes two things, both related to codeblocks in doc comments in Rust documentation: * Allow to disable generation of `language-*` CSS classes with the `custom` attribute. * Add your own CSS classes to a code block so that you can use other tools to highlight them. #### The `custom` attribute Let's start with the new `custom` attribute: it will disable the generation of the `language-*` CSS class on the generated HTML code block. For example: ```rust /// ```custom,c /// int main(void) { /// return 0; /// } /// ``` ``` The generated HTML code block will not have `class="language-c"` because the `custom` attribute has been set. The `custom` attribute becomes especially useful with the other thing added by this feature: adding your own CSS classes. #### Adding your own CSS classes The second part of this feature is to allow users to add CSS classes themselves so that they can then add a JS library which will do it (like `highlight.js` or `prism.js`), allowing to support highlighting for other languages than Rust without increasing burden on rustdoc. To disable the automatic `language-*` CSS class generation, you need to use the `custom` attribute as well. This allow users to write the following: ```rust /// Some code block with `{class=language-c}` as the language string. /// /// ```custom,{class=language-c} /// int main(void) { /// return 0; /// } /// ``` fn main() {} ``` This will notably produce the following HTML: ```html <pre class="language-c"> int main(void) { return 0; }</pre> ``` Instead of: ```html <pre class="rust rust-example-rendered"> <span class="ident">int</span> <span class="ident">main</span>(<span class="ident">void</span>) { <span class="kw">return</span> <span class="number">0</span>; } </pre> ``` To be noted, we could have written `{.language-c}` to achieve the same result. `.` and `class=` have the same effect. One last syntax point: content between parens (`(like this)`) is now considered as comment and is not taken into account at all. In addition to this, I added an `unknown` field into `LangString` (the parsed code block "attribute") because of cases like this: ```rust /// ```custom,class:language-c /// main; /// ``` pub fn foo() {} ``` Without this `unknown` field, it would generate in the DOM: `<pre class="language-class:language-c language-c">`, which is quite bad. So instead, it now stores all unknown tags into the `unknown` field and use the first one as "language". So in this case, since there is no unknown tag, it'll simply generate `<pre class="language-c">`. I added tests to cover this. Finally, I added a parser for the codeblock attributes to make it much easier to maintain. It'll be pretty easy to extend. As to why this syntax for adding attributes was picked: it's [Pandoc's syntax](https://pandoc.org/MANUAL.html#extension-fenced_code_attributes). Even if it seems clunkier in some cases, it's extensible, and most third-party Markdown renderers are smart enough to ignore Pandoc's brace-delimited attributes (from [this comment](https://github.com/rust-lang/rust/pull/110800#issuecomment-1522044456)). ## Raised concerns #### It's not obvious when the `language-*` attribute generation will be added or not. It is added by default. If you want to disable it, you will need to use the `custom` attribute. #### Why not using HTML in markdown directly then? Code examples in most languages are likely to contain `<`, `>`, `&` and `"` characters. These characters [require escaping](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre) when written inside the `<pre>` element. Using the \`\`\` code blocks allows rustdoc to take care of escaping, which means doc authors can paste code samples directly without manually converting them to HTML. cc `@poliorcetics` r? `@notriddle`
2023-09-15Add `custom` tag for markdown codeblocksGuillaume Gomez-3/+41
2023-09-15Update to new `emit_error` APIGuillaume Gomez-8/+8
2023-09-15Improve error emitting codeGuillaume Gomez-6/+10
2023-09-15Add eBNF and documentation on TagIteratorGuillaume Gomez-0/+30
2023-09-15Implement new eBNF for codeblock attributesGuillaume Gomez-134/+227
2023-09-15Add support for double quotes in markdown codeblock attributesGuillaume Gomez-49/+84
2023-09-15Add tests for `custom_code_classes_in_docs` featureGuillaume Gomez-27/+104
2023-09-15Implement custom classes for rustdoc code blocks with ↵Guillaume Gomez-49/+236
`custom_code_classes_in_docs` feature
2023-09-15rustdoc: avoid calling `document.write` after the page loadsMichael Howell-2/+12
2023-09-15rustdoc: merge theme css into rustdoc.cssMichael Howell-420/+641
Based on https://github.com/rust-lang/rust/pull/115812#issuecomment-1717960119 Having them in separate files used to make more sense, before the migration to CSS variables made the theme files as small as they are nowadays. This is already how docs.rs and mdBook do it.
2023-09-13Rollup merge of #115812 - GuillaumeGomez:merge-settings-into-rustdoc-css, ↵Matthias Krüger-76/+64
r=notriddle Merge settings.css into rustdoc.css There aren't that many CSS rules in `settings.css`, however quite some code is needed around it, making it more costly than useful. I think it's better to merge into `rustdoc.css` to simplify this. r? `@notriddle`
2023-09-13Merge settings.css into rustdoc.cssGuillaume Gomez-76/+64
2023-09-11Add missing ID into the ID mapGuillaume Gomez-0/+1
2023-09-11Add missing "Aliased type" title in the sidebarGuillaume Gomez-0/+1
2023-09-10Auto merge of #115682 - notriddle:notriddle/impl-sidebar, r=GuillaumeGomezbors-48/+66
rustdoc: add impl items from aliased type into sidebar Follow-up of https://github.com/rust-lang/rust/pull/115201.
2023-09-10rustdoc: filter before storing in vecMichael Howell-4/+10
2023-09-09rustdoc: factor all-impls-for-item out into its own methodMichael Howell-78/+55
2023-09-09rustdoc-search: fix bugs when unboxing and reordering combineMichael Howell-235/+275
2023-09-09Auto merge of #115669 - GuillaumeGomez:js-anonymous-functions, r=notriddlebors-18/+18
rustdoc: Change syntax for anonymous functions set in JS This function is not very useful in itself but it slightly reduces the JS size so it's always that I suppose... No changes in behaviour. r? `@notriddle`
2023-09-08rustdoc: add impl items from aliased type into sidebarMichael Howell-5/+40
2023-09-08Rollup merge of #115201 - notriddle:notriddle/type-alias-impl-list, ↵Guillaume Gomez-4/+43
r=GuillaumeGomez rustdoc: list matching impls on type aliases Fixes https://github.com/rust-lang/rust/issues/32077 Fixes #99952 Remake of https://github.com/rust-lang/rust/pull/112429 Partially reverts https://github.com/rust-lang/rust/pull/112543, but keeps the test case. This version of the PR avoids the infinite loop by structurally matching types instead of using full unification. This version does not support type alias trait bounds, but the compiler does not enforce those anyway (https://github.com/rust-lang/rust/issues/21903). r? `@GuillaumeGomez` CC `@lcnr`
2023-09-08Change syntax for anonymous functions setGuillaume Gomez-18/+18
2023-09-08Rollup merge of #115655 - notriddle:notriddle/rustdoc-fe-cleanup, ↵Matthias Krüger-3/+1
r=GuillaumeGomez rustdoc: remove unused ID `mainThemeStyle` This was added in https://github.com/rust-lang/rust/pull/47620 and used to build the URL of the theme stylesheets. It isn't used any more, because https://github.com/rust-lang/rust/pull/101702 changed it so that the URL was supplied in a `<meta>` tag, which also provides the hashes of the files.
2023-09-08Rollup merge of #115604 - GuillaumeGomez:private-fields-tuple-struct, ↵Matthias Krüger-14/+30
r=notriddle rustdoc: Render private fields in tuple struct as `/* private fields */` Reopening of https://github.com/rust-lang/rust/pull/110552. All that was missing was a test for the different cases so I added it into the second commit. Description from the original PR: > I've gotten some feedback that the current rustdoc rendering of... > > ``` > struct HasPrivateFields(_); > ``` > > ...is confusing, and I agree with that feedback, especially compared to the field struct case: > > ``` > struct HasPrivateFields { /* private fields */ } > ``` > > So this PR makes it so that when all of the fields of a tuple variant are private, just render it with the `/* private fields */` comment. We can't *always* render it like that, for example when there's a mix of private and public fields. cc ````@jsha```` r? ````@notriddle````
2023-09-07rustdoc: remove unused ID `mainThemeStyle`Michael Howell-3/+1
This was added in 003b2bc1c65251ec2fc80b78ed91c43fb35402ec and used to build the URL of the theme stylesheets. It isn't used any more, because f9e1f6ffdf03ec33cb29e20c88fc7bcc938c7f42 changed it so that the URL was supplied in a `<meta>` tag, which also provides the hashes of the files.
2023-09-07Auto merge of #114855 - Urgau:rustdoc-typedef-inner-variants, r=GuillaumeGomezbors-133/+290
rustdoc: show inner enum and struct in type definition for concrete type This PR implements the [Display enum variants for generic enum in type def page](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/Display.20enum.20variants.20for.20generic.20enum.20in.20type.20def.20page) #rustdoc/zulip proposal. This proposal comes from looking at [`TyKind`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/sty/type.TyKind.html) typedef from the compiler. On that page, the documentation is able to show the layout for each variant, but not the variants themselves. This proposal suggests showing the fields and variants for those "concrete type". This would mean that instead of having many unresolved generics, like in `IrTyKind`: ```rust Array(I::Ty, I::Const), Slice(I::Ty), RawPtr(I::TypeAndMut), Ref(I::Region, I::Ty, I::Mutability), FnDef(I::DefId, I::GenericArgsRef), ``` those would be resolved with direct links to the proper types in the `TyKind` typedef page: ```rust Array(Ty<'tcx>, Const<'tcx>), Slice(Ty<'tcx>), RawPtr(TypeAndMut<'tcx>), Ref(Region<'tcx>, Ty<'tcx>, Mutability<'tcx>), FnDef(DefId<'tcx>, GenericArgsRef<'tcx>), ``` Saving both time and confusion. ----- <details> <summary>Old description</summary> I've chosen to add the enums and structs under the "Show Aliased Type" details, as well as showing the variants and fields under the usual "Variants" and "Fields" sections. ~~*under new the `Inner Variants` and `Inner Fields` sections (except for their names, they are identical to the one found in the enum, struct and union pages). Those sections are complementary and do not replace anything else.*~~ This PR proposes the following condition for showing the aliased type (basically, has the aliased type some generics that are all of them resolved): - the typedef does NOT have any generics (modulo lifetimes) - AND the aliased type has some generics </details> ### Examples ```rust pub enum IrTyKind<'a, I: Interner> { /// Doc comment for AdtKind AdtKind(&'a I::Adt), /// and another one for TyKind TyKind(I::Adt, I::Ty), // no comment StructKind { a: I::Adt, }, } pub type TyKind<'a> = IrTyKind<'a, TyCtxt>; ``` ![TyKind](https://github.com/rust-lang/rust/assets/3616612/13307679-6d48-40d6-ad50-6db0b7f36ac7) <details> <summary>Old</summary> ![image](https://github.com/rust-lang/rust/assets/3616612/4147c049-d056-42d4-8a01-d43ebe747308) ![TyKind](https://user-images.githubusercontent.com/3616612/260988247-34831aa9-470d-4286-ad9f-3e8002153a92.png) ![TyKind](https://github.com/rust-lang/rust/assets/3616612/62381bb3-fa0f-4b05-926d-77759cf9115a) </details> ```rust pub struct One<T> { pub val: T, #[doc(hidden)] pub inner_tag: u64, __hidden: T, } /// `One` with `u64` as payload pub type OneU64 = One<u64>; ``` ![OneU64](https://github.com/rust-lang/rust/assets/3616612/d551b474-ce88-4f8c-bc94-5c88aba51424) <details> <summary>Old</summary> ![image](https://github.com/rust-lang/rust/assets/3616612/1a3f53c0-17bf-4aa7-894d-3fedc15b33da) ![OneU64](https://github.com/rust-lang/rust/assets/3616612/7b124a5b-e287-4efb-b9ca-fdcd1cdeeba8) ![OneU64](https://github.com/rust-lang/rust/assets/3616612/ddd962be-4f76-4ecd-81bd-531f3dd23832) </details> r? `@GuillaumeGomez`
2023-09-06Render missing fields in tuple struct/enum as /* private fields */Michael Goulet-14/+30
2023-09-05Auto merge of #115507 - cjgillot:relative-source-file, r=oli-obkbors-1/+1
Use relative positions inside a SourceFile. This allows to remove the normalization of start positions for hashing, and simplify allocation of global address space. cc `@Zoxc`
2023-09-03rustdoc: fix test case for generics that look like namesMichael Howell-1/+2
2023-09-03rustdoc: bug fix for `-> option<t>`Michael Howell-1/+5
2023-09-03rustdoc-search: add support for type parametersMichael Howell-286/+472
When writing a type-driven search query in rustdoc, specifically one with more than one query element, non-existent types become generic parameters instead of auto-correcting (which is currently only done for single-element queries) or giving no result. You can also force a generic type parameter by writing `generic:T` (and can force it to not use a generic type parameter with something like `struct:T` or whatever, though if this happens it means the thing you're looking for doesn't exist and will give you no results). There is no syntax provided for specifying type constraints for generic type parameters. When you have a generic type parameter in a search query, it will only match up with generic type parameters in the actual function, not concrete types that match, not concrete types that implement a trait. It also strictly matches based on when they're the same or different, so `option<T>, option<U> -> option<U>` matches `Option::and`, but not `Option::or`. Similarly, `option<T>, option<T> -> option<T>`` matches `Option::or`, but not `Option::and`.
2023-09-03rustdoc-search: `null`, not `-1`, for missing idMichael Howell-14/+14
This allows us to use negative numbers for others purposes.
2023-09-03Rollup merge of #115490 - pitaj:rustdoc-searchjs-comment, r=GuillaumeGomezGuillaume Gomez-8/+17
rustdoc: update comment in search.js for #107629 Addressing https://github.com/rust-lang/rust/pull/107629#issuecomment-1693460106 r? `@jsha`
2023-09-03Use relative positions inside a SourceFile.Camille GILLOT-1/+1
2023-09-02rustdoc: update comment in search.js for #107629Peter Jaszkowiak-8/+17
2023-09-02Correctly handle paths from foreign itemsGuillaume Gomez-11/+46
2023-09-01Merge all loops into one when generating search indexGuillaume Gomez-92/+65