summary refs log tree commit diff
path: root/src/librustdoc
AgeCommit message (Collapse)AuthorLines
2023-10-20Add some FIXMEs for remaining issues that we need to fix before using more ↵Oli Scherer-0/+4
const trait things in libcore (cherry picked from commit 16f8396f6df6902eeef580396785ab8888c3718b)
2023-10-20hide `host` param from generic parameter list of `~const` boundsOli Scherer-8/+17
(cherry picked from commit 6724f9926c9e8c2d37e3e68e44238897bd89fddf)
2023-10-20Hide host effect params from docsOli Scherer-13/+17
(cherry picked from commit c4e61faf2e078dc30b62488326404137600e5e11)
2023-09-30Auto merge of #116195 - fmease:rustdoc-investigate-perf-regression, ↵bors-27/+16
r=GuillaumeGomez rustdoc: speed up processing of cross-crate fns to fix a perf regression * The first commit doesn't affect perf but get's rid of a `.clone()` and a bunch of lines of code. I can drop it if you'd like me to * The second commit, *“reduce the amount of `asyncness` query executions”*, addresses the perf regression introduced in #116084 r? `@ghost`
2023-09-30rustdoc: reduce the amount of `asyncness` query executionsLeón Orell Valerian Liehr-1/+7
2023-09-29rustdoc: simplify sugared_async_return_typeLeón Orell Valerian Liehr-26/+9
2023-09-28Rollup merge of #116211 - matthiaskrgr:clippy3, r=compiler-errorsMatthias Krüger-1/+1
more clippy complextity fixes redundant_guards, useless_format, clone_on_copy
2023-09-28Auto merge of #116208 - matthiaskrgr:the_loop_that_wasnt, r=GuillaumeGomezbors-1/+1
rustdoc: while -> if we will always return once we step inside the while-loop thus `if` is sufficient here
2023-09-27Auto merge of #116148 - DaniPopes:rustdoc-type-layout-ws, r=jshabors-2/+2
Fix whitespace in rustdoc type_layout.html `Size: <size>` was missing a space after the colon: ![image](https://github.com/rust-lang/rust/assets/57450786/c5a672f3-a28a-4b56-91e7-a4e6ffc8106e)
2023-09-27fix clippy::{redundant_guards, useless_format}Matthias Krüger-1/+1
2023-09-27rustdoc: while -> ifMatthias Krüger-1/+1
we will always return once we step inside the while-loop thus `if` is sufficient here
2023-09-26Don't store lazyness in DefKindMichael Goulet-6/+6
2023-09-25Auto merge of #116084 - fmease:rustdoc-fix-x-crate-async-fn, r=GuillaumeGomezbors-30/+35
rustdoc: correctly render the return type of cross-crate async fns Fixes #115760.
2023-09-25Fix whitespace in rustdoc type_layout.htmlDaniPopes-2/+2
2023-09-25rustdoc: correctly render ret ty of cross-crate async fnsLeón Orell Valerian Liehr-30/+35
2023-09-23Remove GeneratorWitness and rename GeneratorWitnessMIR.Camille GILLOT-3/+1
2023-09-22Merge `ExternProviders` into the general `Providers` structOli Scherer-1/+1
2023-09-22Have a single struct for queries and hookOli Scherer-1/+1
2023-09-22Add a way to decouple the implementation and the declaration of a TyCtxt method.Oli Scherer-1/+1
2023-09-22Auto merge of #114776 - fee1-dead-contrib:enable-effects-in-libcore, r=oli-obkbors-0/+1
Enable effects for libcore ~~r? `@oli-obk~~` forgot you are on vacation, oops
2023-09-21Record asyncness span in HIRMichael Goulet-3/+7
2023-09-21Rollup merge of #116019 - dtolnay:percratesearch, r=GuillaumeGomezGuillaume Gomez-7/+0
Delete obsolete `--disable-per-crate-search` rustdoc flag This unstable flag is unused by rustdoc since https://github.com/rust-lang/rust/pull/92526/commits/ef96d573bff12330080d22f12cad96b818ea5da7. We should avoid landing this until after https://github.com/rust-lang/docs.rs/pull/2225 is deployed to docs.rs.
2023-09-21Rollup merge of #115972 - RalfJung:const-consistency, r=oli-obkGuillaume Gomez-4/+4
rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const Also, be more consistent with the `to/eval_bits` methods... we had some that take a type and some that take a size, and then sometimes the one that takes a type is called `bits_for_ty`. Turns out that `ty::Const`/`mir::ConstKind` carry their type with them, so we don't need to even pass the type to those `eval_bits` functions at all. However this is not properly consistent yet: in `ty` we have most of the methods on `ty::Const`, but in `mir` we have them on `mir::ConstKind`. And indeed those two types are the ones that correspond to each other. So `mir::ConstantKind` should actually be renamed to `mir::Const`. But what to do with `mir::Constant`? It carries around a span, that's really more like a constant operand that appears as a MIR operand... it's more suited for `syntax.rs` than `consts.rs`, but the bigger question is, which name should it get if we want to align the `mir` and `ty` types? `ConstOperand`? `ConstOp`? `Literal`? It's not a literal but it has a field called `literal` so it would at least be consistently wrong-ish... ``@oli-obk`` any ideas?
2023-09-21rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::ConstRalf Jung-4/+4
2023-09-20Delete obsolete --disable-per-crate-search rustdoc flagDavid Tolnay-7/+0
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-20ignore host effect params in rustdocDeadbeef-0/+1
2023-09-19Auto merge of #113955 - cjgillot:name-apit, r=WaffleLapkinbors-1/+1
Pretty-print argument-position impl trait to name it. This removes a corner case. RPIT and TAIT keep having no name, and it would be wrong to use the one in HIR (Ident::empty), so I make this case ICE.
2023-09-19Rollup merge of #115947 - ↵Guillaume Gomez-117/+185
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-19Auto merge of #115865 - RalfJung:mir-mod, r=oli-obkbors-5/+4
move things out of mir/mod.rs This moves a bunch of things out of `mir/mod.rs`: - all const-related stuff to a new file consts.rs - all statement/place/operand-related stuff to a new file statement.rs - all pretty-printing related stuff to pretty.rs `mod.rs` started out with 3100 lines and ends up with 1600. :) Also there was some pretty-printing stuff in terminator.rs, that also got moved to pretty.rs, and I reordered things in pretty.rs so that it can be grouped by functionality. Only the commit "use pretty_print_const_value from MIR constant 'extra' printing" has any behavior changes; it resolves the issue of having a fancy and a very crude pretty-printer for `ConstValue`. r? `@oli-obk`
2023-09-19Return early in `check_custom_code_classes` check if the feature is enabledGuillaume Gomez-1/+5
2023-09-19Rollup merge of #112725 - notriddle:notriddle/advanced-search, r=GuillaumeGomezGuillaume Gomez-409/+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-19move ConstValue into mirRalf Jung-5/+4
this way we have mir::ConstValue and ty::ValTree as reasonably parallel
2023-09-18Use old parser if `custom_code_classes_in_docs` feature is not enabledGuillaume Gomez-104/+135
2023-09-18Move mobile topbar title creation entirely into JSGuillaume Gomez-5/+6
2023-09-17Update src/librustdoc/markdown.rsManish Goregaokar-1/+1
Co-authored-by: Michael Howell <michael@notriddle.com>
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-32/+144
when its syntax is used.
2023-09-16Auto merge of #110800 - GuillaumeGomez:custom_code_classes_in_docs, r=t-rustdocbors-72/+618
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-11/+10
2023-09-15Improve error emitting codeGuillaume Gomez-6/+10
2023-09-15Fix compilation error "the trait bound `SubdiagnosticMessage: ↵Guillaume Gomez-2/+3
From<&std::string::String>` is not satisfied"
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/+318
`custom_code_classes_in_docs` feature