about summary refs log tree commit diff
path: root/src/doc/rustdoc
AgeCommit message (Collapse)AuthorLines
2025-06-29Update the-doc-attribute.md (#1)Eeshvar Das-1/+1
2025-06-11Update extracted-doctest feature documentationGuillaume Gomez-5/+19
2025-06-07Rollup merge of #140560 - Urgau:test_attr-module-level, r=GuillaumeGomezGuillaume Gomez-9/+23
Allow `#![doc(test(attr(..)))]` everywhere This PR adds the ability to specify [`#![doc(test(attr(..)))]`](https://doc.rust-lang.org/nightly/rustdoc/write-documentation/the-doc-attribute.html#testattr) ~~at module level~~ everywhere in addition to allowing it at crate-root. This is motivated by a recent PR #140323 (by ````@tgross35)```` where we have to duplicate 2 attributes to every single `f16` and `f128` doctests, by allowing `#![doc(test(attr(..)))]` at module level (and everywhere else) we can omit them entirely and just have (in both module): ```rust #![doc(test(attr(feature(cfg_target_has_reliable_f16_f128))))] #![doc(test(attr(expect(internal_features))))] ``` Those new attributes are appended to the one found at crate-root or at a previous module. Those "global" attributes are compatible with merged doctests (they already were before). Given the small addition that this is, I'm proposing to insta-stabilize it, but I can feature-gate it if preferred. Best reviewed commit by commit. r? ````@GuillaumeGomez````
2025-05-24rustdoc book: add argument explanation for `html_playground_url`xizheyin-2/+4
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-22Allow `#![doc(test(attr(..)))]` at every levelUrgau-28/+23
2025-05-22Allow `#![doc(test(attr(..)))]` at module level tooUrgau-0/+19
2025-05-12update version placeholdersPietro Albini-1/+1
2025-04-25Rollup merge of #140290 - styvane:patch0001-fix-typo-in-rusdoc-search, ↵Matthias Krüger-1/+1
r=GuillaumeGomez rustdoc: fix typo change from equivelent to equivalent This PR fixes a typo in the search section in `rustdoc` book.
2025-04-25rustdoc: fix typo change from equivelent to equivalentSede Soukossi-1/+1
2025-03-27Try to more clearly specify exactly what the runtool flags doEric Huss-3/+8
2025-03-27Show an example of using multiple ignore attributesEric Huss-0/+9
2025-03-27Remove and stabilize --enable-per-target-ignoresEric Huss-35/+28
This removes the `--enable-per-target-ignores` and enables it unconditionally.
2025-03-27Stabilize --test-runtool and --test-runtool-argEric Huss-19/+17
2025-03-27Rename `--runtool` and `--runtool-arg`Eric Huss-3/+3
This renames `--runtool` and `--runtool-arg` to `--test-runtool` and `--test-runtool-arg` to maintain consistency with other `--test-*` arguments.
2025-02-27Add missing case explanation for doc inlined re-export of doc hidden itemGuillaume Gomez-1/+16
2025-02-21Rollup merge of #132876 - lolbinarycat:rustdoc-document-hidden-items, ↵Matthias Krüger-4/+23
r=GuillaumeGomez rustdoc book: acknowledge --document-hidden-items
2025-02-20rustdoc book: acknowlage --document-hidden-itemsbinarycat-4/+23
2025-02-01rustdoc-book: Clean up section on `--output-format`Alona Enraght-Moony-5/+11
2025-01-29Add documentation for `--output-format=doctest`Guillaume Gomez-0/+64
2025-01-16Treat other items as functions for the purpose of type-based searchbinarycat-1/+13
constants and statics are nullary functions, and struct fields are unary functions. functions (along with methods and trait methods) are prioritized over other items, like fields and constants.
2024-12-29docs: fix typosdxsullivan-1/+1
2024-12-20Add test to ensure passing `--doctest_compilation_args` multiple times workGuillaume Gomez-1/+1
2024-12-20Add explanations on how arguments are splitGuillaume Gomez-0/+19
2024-12-20Add explanations about `--doctest-compilation-args` in rustdoc bookGuillaume Gomez-18/+76
2024-12-17Rollup merge of #134202 - nnethercote:rm-existing_doc_keyword, r=GuillaumeGomezJacob Pratt-1/+1
Remove `rustc::existing_doc_keyword` lint The check doesn't require a lint. r? ``@GuillaumeGomez``
2024-12-17Remove `rustc::existing_doc_keyword` lint.Nicholas Nethercote-1/+1
`CheckAttrVisitor::check_doc_keyword` checks `#[doc(keyword = "..")]` attributes to ensure they are on an empty module, and that the value is a non-empty identifier. The `rustc::existing_doc_keyword` lint checks these attributes to ensure that the value is the name of a keyword. It's silly to have two different checking mechanisms for these attributes. This commit does the following. - Changes `check_doc_keyword` to check that the value is the name of a keyword (avoiding the need for the identifier check, which removes a dependency on `rustc_lexer`). - Removes the lint. - Updates tests accordingly. There is one hack: the `SelfTy` FIXME case used to used to be handled by disabling the lint, but now is handled with a special case in `is_doc_keyword`. That hack will go away if/when the FIXME is fixed. Co-Authored-By: Guillaume Gomez <guillaume1.gomez@gmail.com>
2024-12-13rustdoc-search: update documentation with notes about unboxingMichael Howell-7/+18
2024-11-30Extend documentation for `missing_doc_code_examples` rustdoc lint in the ↵Guillaume Gomez-0/+4
rustdoc book
2024-11-22Stabilize the 2024 editionEric Huss-1/+1
2024-11-18rustdoc book: Move `--test-builder(--wrapper)?` docs to unstable section.Alona Enraght-Moony-29/+33
2024-11-11Auto merge of #127589 - notriddle:notriddle/search-sem-3, r=GuillaumeGomezbors-5/+7
rustdoc-search: simplify rules for generics and type params **Heads up!**: This PR is a follow-up that depends on #124544. It adds 12dc24f46007f82b93ed85614347a42d47580afa, a change to the filtering behavior, and 9900ea48b566656fb12b5fcbd0a1b20aaa96e5ca, a minor ranking tweak. Part of https://github.com/rust-lang/rust-project-goals/issues/112 This PR overturns https://github.com/rust-lang/rust/pull/109802 ## Preview * no results: [`Box<[A]> -> Vec<B>`](http://notriddle.com/rustdoc-html-demo-12/search-sem-3/std/index.html?search=Box%3C%5BA%5D%3E%20-%3E%20Vec%3CB%3E) * results: [`Box<[A]> -> Vec<A>`](http://notriddle.com/rustdoc-html-demo-12/search-sem-3/std/index.html?search=Box%3C%5BA%5D%3E%20-%3E%20Vec%3CA%3E) * [`T -> U`](http://notriddle.com/rustdoc-html-demo-12/search-sem-3/std/index.html?search=T%20-%3E%20U) * [`Cx -> TyCtxt`](http://notriddle.com/rustdoc-html-demo-12/search-sem-3-compiler/rustdoc/index.html?search=Cx%20-%3E%20TyCtxt) ![image](https://github.com/user-attachments/assets/015ae28c-7469-4f7f-be03-157d28d7ec97) ## Description This commit is a response to feedback on the displayed type signatures results, by making generics act stricter. - Order within generics is significant. This means `Vec<Allocator>` now matches only with a true vector of allocators, instead of matching the second type param. It also makes unboxing within generics stricter, so `Result<A, B>` only matches if `B` is in the error type and `A` is in the success type. The top level of the function search is unaffected. - Generics are only "unboxed" if a type is explicitly opted into it. References and tuples are hardcoded to allow unboxing, and Box, Rc, Arc, Option, Result, and Future are opted in with an unstable attribute. Search result unboxing is the process that allows you to search for `i32 -> str` and get back a function with the type signature `&Future<i32> -> Box<str>`. - Instead of ranking by set overlap, it ranks by the number of items in the type signature. This makes it easier to find single type signatures like transmute. ## Find the discussion on * <https://rust-lang.zulipchat.com/#narrow/stream/393423-t-rustdoc.2Fmeetings/topic/meeting.202024-07-08/near/449965149> * <https://github.com/rust-lang/rust/pull/124544#issuecomment-2204272265> * <https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/deciding.20on.20semantics.20of.20generics.20in.20rustdoc.20search>
2024-11-02Rename target triple to target tuple in many places in the compilerNoratrieb-1/+1
This changes the naming to the new naming, used by `--print target-tuple`. It does not change all locations, but many.
2024-10-30rustdoc-search: simplify rules for generics and type paramsMichael Howell-5/+7
This commit is a response to feedback on the displayed type signatures results, by making generics act stricter. Generics are tightened by making order significant. This means `Vec<Allocator>` now matches only with a true vector of allocators, instead of matching the second type param. It also makes unboxing within generics stricter, so `Result<A, B>` only matches if `B` is in the error type and `A` is in the success type. The top level of the function search is unaffected. Find the discussion on: * <https://rust-lang.zulipchat.com/#narrow/stream/393423-t-rustdoc.2Fmeetings/topic/meeting.202024-07-08/near/449965149> * <https://github.com/rust-lang/rust/pull/124544#issuecomment-2204272265> * <https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/deciding.20on.20semantics.20of.20generics.20in.20rustdoc.20search/near/476841363>
2024-10-01Auto merge of #130587 - coolreader18:field-variant-doclink-disambig, ↵bors-2/+2
r=notriddle,jyn514 Add `field@` and `variant@` doc-link disambiguators I'm not sure if this is big enough to need an fcp or not, but this is something I found missing when trying to refer to a field in macro-generated docs, not knowing if a method might be defined as well. Obviously, there are definitely other uses. In the case where it's not disambiguated, methods (and I suppose other associated items in the value namespace) still take priority, which `@jyn514` said was an oversight but I think is probably the desired behavior 99% of the time anyway - shadowing a field with an accessor method is a very common pattern. If fields and methods with the same name started conflicting, it would be a breaking change. Though, to quote them: > jyn: maybe you can break this only if both [the method and the field] are public > jyn: rustc has some future-incompat warning level > jyn: that gets through -A warnings and --cap-lints from cargo That'd be out of scope of this PR, though. Fixes #80283
2024-09-29Rename doctest attribute `standalone-crate` into `standalone_crate` for ↵Guillaume Gomez-2/+2
coherency
2024-09-28Rename `standalone` doctest attribute into `standalone-crate`Guillaume Gomez-2/+2
2024-09-19Add `field@` and `variant@` doc-link disambiguatorsNoa-2/+2
2024-08-15Rollup merge of #128963 - GuillaumeGomez:output-to-stdout, r=aDotInTheVoidMatthias Krüger-0/+3
Add possibility to generate rustdoc JSON output to stdout Fixes #127165. I think it's likely common to want to get rustdoc json output directly instead of reading it from a file so I added this option to allow it. It's unstable and only works with `--output-format=json`. r? `@aDotInTheVoid`
2024-08-13Add documentation for the doctest `standalone` attributeGuillaume Gomez-0/+51
2024-08-12Add documentation for `-o -`Guillaume Gomez-0/+3
2024-07-22Rollup merge of #117932 - GuillaumeGomez:update-rustdoc-book, r=notriddleTrevor Gross-25/+2
Correct rustdoc section where we talk about rustdoc emitting errors on invalid code As discussed on [zulip](https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/stop.20accepting.20broken.20code/near/401760318). r? `@notriddle`
2024-07-09`#[doc(alias)]`'s doc: say that ASCII spaces are allowedLieselotte-1/+2
2024-06-19Rework doc-test attribute documentation exampleUrgau-2/+2
2024-06-01Auto merge of #124577 - ↵bors-44/+38
GuillaumeGomez:stabilize-custom_code_classes_in_docs, r=rustdoc Stabilize `custom_code_classes_in_docs` feature Fixes #79483. This feature has been around for quite some time now, I think it's fine to stabilize it now. ## Summary ## 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. EDIT(camelid): This description is out-of-date. Using `custom,class:language-c` will generate the output `<pre class="language-class:language-c">` as would be expected; it treats `class:language-c` as just the name of a language (similar to the langstring `c` or `js` or what have you) since it does not use the designed class syntax. 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)). r? `@notriddle`
2024-05-18Auto merge of #124611 - Urgau:rustdoc-stdin, r=GuillaumeGomezbors-0/+6
Add `-` (stdin) support in rustdoc This PR adds support for the special `-` input which threats the input as coming from *stdin* instead of being a filepath. Doing this also makes `rustdoc` consistent with `rustc` and ~~every~~ other tools. Full [motivation](https://github.com/rust-lang/rust/pull/124611#issuecomment-2094234876). Fixes https://github.com/rust-lang/rust/issues/123671 r? `@fmease`
2024-05-12fix hidden title in command-line-arguments docsickk-1/+1
2024-05-05Rollup merge of #124148 - notriddle:notriddle/reference, r=GuillaumeGomezGuillaume Gomez-1/+9
rustdoc-search: search for references This feature extends rustdoc with syntax and search index information for searching borrow references. Part of https://github.com/rust-lang/rust/issues/60485 ## Preview - [`&mut`](https://notriddle.com/rustdoc-html-demo-11/reference/std/index.html?search=%26mut) - [`&Option<T> -> Option<&T>`](https://notriddle.com/rustdoc-html-demo-11/reference/std/index.html?search=%26Option%3CT%3E%20-%3E%20Option%3C%26T%3E) - [`&mut Option<T> -> Option<&mut T>`](https://notriddle.com/rustdoc-html-demo-11/reference/std/index.html?search=%26mut%20Option%3CT%3E%20-%3E%20Option%3C%26mut%20T%3E) Updated chapter of the book: https://notriddle.com/rustdoc-html-demo-11/reference/rustdoc/read-documentation/search.html ## Motivation See https://github.com/rust-lang/rust/pull/119676 ## Guide-level explanation You can't search by lifetimes, but other than that it's the same syntax references normally use. ## Reference-level description <table> <thead> <tr> <th>Shorthand</th> <th>Explicit names</th> </tr> </thead> <tbody> <tr><td colspan="2">Before this PR</td></tr> <tr> <td><code>[]</code></td> <td><code>primitive:slice</code> and/or <code>primitive:array</code></td> </tr> <tr> <td><code>[T]</code></td> <td><code>primitive:slice&lt;T&gt;</code> and/or <code>primitive:array&lt;T&gt;</code></td> </tr> <tr> <td><code>!</code></td> <td><code>primitive:never</code></td> </tr> <tr> <td><code>()</code></td> <td><code>primitive:unit</code> and/or <code>primitive:tuple</code></td> </tr> <tr> <td><code>(T)</code></td> <td><code>T</code></td> </tr> <tr> <td><code>(T,)</code></td> <td><code>primitive:tuple&lt;T&gt;</code></td> </tr> <tr> <td><code>(T, U -> V, W)</code></td> <td><code>fn(T, U) -> (V, W)</code>, Fn, FnMut, and FnOnce</td> </tr> <tr><td colspan="2">New additions with this PR</td></tr> <tr> <td><code>&</code></td> <td><code>primitive:reference</td> </tr> <tr> <td><code>&mut</code></td> <td><code>primitive:reference&lt;keyword:mut&gt;</td> </tr> <tr> <td><code>&T</code></td> <td><code>primitive:reference&lt;T&gt;</td> </tr> <tr> <td><code>&mut T</code></td> <td><code>primitive:reference&lt;keyword:mut, T&gt;</td> </tr> </tbody> </table> ### Search query grammar <code><pre><strong>borrow-ref = AMP *WS [MUT] *WS [arg]</strong> arg = [type-filter *WS COLON *WS] (path [generics] / slice-like / tuple-like / <strong>borrow-ref</strong>)</pre></code> ``` AMP = "&" MUT = "mut" ``` ## Future direction As described in https://github.com/rust-lang/rust/pull/118194 and https://github.com/rust-lang/rust/pull/119676 * The remaining type expression grammar (this is another step in the type expression grammar: `ReferenceType` is now supported) * Search subtyping and traits
2024-05-04Add `-` (stdin) support to rustdocUrgau-0/+6
2024-05-01Stabilize `custom_code_classes_in_docs` featureGuillaume Gomez-44/+38
2024-04-24chore: fix some typos in commentswhosehang-2/+2
Signed-off-by: whosehang <whosehang@outlook.com>