summary refs log tree commit diff
path: root/src/librustdoc
AgeCommit message (Collapse)AuthorLines
2024-06-07Auto merge of #126134 - matthiaskrgr:rollup-vzlegsc, r=matthiaskrgrbors-1/+5
Rollup of 11 pull requests Successful merges: - #124012 (Stabilize `binary_heap_as_slice`) - #124214 (Parse unsafe attributes) - #125572 (Detect pub structs never constructed and unused associated constants) - #125781 (prefer `compile::stream_cargo` for building tools) - #126030 (Update `./x fmt` command in library/std/src/sys/pal/windows/c/README.md) - #126047 (Simplify the rayon calls in the installer) - #126052 (More `rustc_parse` cleanups) - #126077 (Revert "Use the HIR instead of mir_keys for determining whether something will have a MIR body.") - #126089 (Stabilize Option::take_if) - #126112 (Clean up source root in run-make tests) - #126119 (Improve docs for using custom paths with `--emit`) r? `@ghost` `@rustbot` modify labels: rollup
2024-06-07run fmtGuillaume Gomez-18/+16
2024-06-07Fix broken rustdoc unit testsNoah Lev-22/+37
2024-06-07Parse full doctest source; extract helper for parsing codeNoah Lev-90/+104
It doesn't really make sense to skip part of the source when we're parsing it, so parse the whole doctest. This simplifies things too.
2024-06-07Move logic for "making" doctests to submoduleNoah Lev-375/+387
This code turns the raw code given by the user into something actually runnable, e.g. by adding a `main` function if it doesn't already exist. I also made a couple other items private that didn't need to be crate-public.
2024-06-07Make doctests before running them; reintroduce `RunnableDoctest`Noah Lev-42/+54
2024-06-07Move some arguments to fields and reorganize fieldsNoah Lev-58/+54
I moved some local arguments and options to either the local options struct or, if it made sense, the global options struct.
2024-06-07Remove `RunnableDoctest`Noah Lev-24/+17
It should instead be the actual input to the running logic. Currently it's not actually quite runnable since it's still missing some information.
2024-06-07Make two fields computed on-demandNoah Lev-9/+15
2024-06-07rustdoc: Remove `DoctestVisitor::get_line`Noah Lev-24/+42
This was used to get the line number of the first line from the current docstring, which was then used together with an offset within the docstring. It's simpler to just pass the offset to the visitor and have it do the math because it's clearer and this calculation only needs to be done in one place (the Rust doctest visitor).
2024-06-07Remove global options from `IndividualTestOptions`Noah Lev-40/+21
2024-06-07Merge `RustDoctest` and `MdDoctest` into one typeNoah Lev-77/+42
2024-06-07rustdoc: Extract actual doctest running logic into functionNoah Lev-75/+126
2024-06-07Separate doctest collection from runningNoah Lev-188/+237
2024-06-07Move Markdown-specific doctest code into submoduleNoah Lev-47/+51
2024-06-07Start moving format-specific code into doctest submoduleNoah Lev-120/+136
2024-06-07rustdoc: Use `write_all` to ensure all content is writtenNoah Lev-1/+1
2024-06-07rustdoc: Rename `Tester` to `DoctestVisitor`Noah Lev-14/+14
The new name more accurately captures what it is.
2024-06-06Fix formattingcarbotaniuman-1/+1
2024-06-06Fix buildcarbotaniuman-5/+5
2024-06-06Parse unsafe attributescarbotaniuman-1/+5
2024-06-06Auto merge of #126068 - lqd:revert-124976, r=petrochenkovbors-5/+5
Revert "use `tcx.used_crates(())` more" before it reaches beta There are more open issues caused by #124976 than will be fixed by #125493 alone. The beta cut is soon, so let's revert it and buy some time to analyze and fix these issues in our own time. fixes https://github.com/rust-lang/rust/issues/125474 fixes https://github.com/rust-lang/rust/issues/125484 fixes https://github.com/rust-lang/rust/issues/125646 fixes https://github.com/rust-lang/rust/issues/125707 fixes #126066 fixes #125934 fixes https://github.com/rust-lang/rust/issues/126021 r? `@petrochenkov` `@bors` p=1
2024-06-06Revert "Rollup merge of #124976 - petrochenkov:usedcrates, r=oli-obk"Rémy Rakic-5/+5
This reverts commit eda4a35f365535af72118118a3597edf5a13c12d, reversing changes made to eb6b35b5bcb3c2a594cb29cd478aeb2893f49d30.
2024-06-06Auto merge of #124482 - spastorino:unsafe-extern-blocks, r=oli-obkbors-4/+12
Unsafe extern blocks This implements RFC 3484. Tracking issue #123743 and RFC https://github.com/rust-lang/rfcs/pull/3484 This is better reviewed commit by commit.
2024-06-05Remove `Type` from rustdoc `Const`Boxy-54/+50
2024-06-05Make top-level `rustc_parse` functions fallible.Nicholas Nethercote-16/+20
Currently we have an awkward mix of fallible and infallible functions: ``` new_parser_from_source_str maybe_new_parser_from_source_str new_parser_from_file (maybe_new_parser_from_file) // missing (new_parser_from_source_file) // missing maybe_new_parser_from_source_file source_str_to_stream maybe_source_file_to_stream ``` We could add the two missing functions, but instead this commit removes of all the infallible ones and renames the fallible ones leaving us with these which are all fallible: ``` new_parser_from_source_str new_parser_from_file new_parser_from_source_file source_str_to_stream source_file_to_stream ``` This requires making `unwrap_or_emit_fatal` public so callers of formerly infallible functions can still work. This does make some of the call sites slightly more verbose, but I think it's worth it for the simpler API. Also, there are two `catch_unwind` calls and one `catch_fatal_errors` call in this diff that become removable thanks this change. (I will do that in a follow-up PR.)
2024-06-05Reorder `source_str_to_stream` arguments.Nicholas Nethercote-1/+1
It's the only one of these functions where `psess` isn't the first argument.
2024-06-05Don't use the word "parse" for lexing operations.Nicholas Nethercote-8/+3
Lexing converts source text into a token stream. Parsing converts a token stream into AST fragments. This commit renames several lexing operations that have "parse" in the name. I think these names have been subtly confusing me for years. This is just a `s/parse/lex/` on function names, with one exception: `parse_stream_from_source_str` becomes `source_str_to_stream`, to make it consistent with the existing `source_file_to_stream`. The commit also moves that function's location in the file to be just above `source_file_to_stream`. The commit also cleans up a few comments along the way.
2024-06-04Rollup merge of #125946 - Sergi-Ferrez:master, r=notriddle,fmeaseGuillaume Gomez-8/+11
Include trailing commas in wrapped function declarations [RustDoc] Fixes #125901.
2024-06-04Add safe/unsafe to static inside extern blocksSantiago Pastorino-2/+6
2024-06-04Handle safety keyword for extern block inner itemsSantiago Pastorino-2/+6
2024-06-04Use checked_subSergi-Ferrez-6/+7
2024-06-04Update code format and testsSergi-Ferrez-2/+2
2024-06-04Include trailing commas in functionsSergi-Ferrez-10/+12
2024-06-03check_is_object_safe -> is_object_safeMichael Goulet-1/+1
2024-06-01Auto merge of #124577 - ↵bors-251/+24
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-31Rollup merge of #125635 - fmease:mv-type-binding-assoc-item-constraint, ↵Matthias Krüger-116/+139
r=compiler-errors Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanup Rename `hir::TypeBinding` and `ast::AssocConstraint` to `AssocItemConstraint` and update all items and locals using the old terminology. Motivation: The terminology *type binding* is extremely outdated. "Type bindings" not only include constraints on associated *types* but also on associated *constants* (feature `associated_const_equality`) and on RPITITs of associated *functions* (feature `return_type_notation`). Hence the word *item* in the new name. Furthermore, the word *binding* commonly refers to a mapping from a binder/identifier to a "value" for some definition of "value". Its use in "type binding" made sense when equality constraints (e.g., `AssocTy = Ty`) were the only kind of associated item constraint. Nowadays however, we also have *associated type bounds* (e.g., `AssocTy: Bound`) for which the term *binding* doesn't make sense. --- Old terminology (HIR, rustdoc): ``` `TypeBinding`: (associated) type binding ├── `Constraint`: associated type bound └── `Equality`: (associated) equality constraint (?) ├── `Ty`: (associated) type binding └── `Const`: associated const equality (constraint) ``` Old terminology (AST, abbrev.): ``` `AssocConstraint` ├── `Bound` └── `Equality` ├── `Ty` └── `Const` ``` New terminology (AST, HIR, rustdoc): ``` `AssocItemConstraint`: associated item constraint ├── `Bound`: associated type bound └── `Equality`: associated item equality constraint OR associated item binding (for short) ├── `Ty`: associated type equality constraint OR associated type binding (for short) └── `Const`: associated const equality constraint OR associated const binding (for short) ``` r? compiler-errors
2024-05-30Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanupLeón Orell Valerian Liehr-116/+139
2024-05-30remove tracing tree indent lineslcnr-1/+0
2024-05-29Make `body_owned_by` return the body directly.Oli Scherer-9/+12
Almost all callers want this anyway, and now we can use it to also return fed bodies
2024-05-29Don't require `visit_body` to take a lifetime that must outlive the function ↵Oli Scherer-1/+1
call
2024-05-27Auto merge of #125599 - camelid:clarify-stability, r=notriddle,GuillaumeGomezbors-27/+51
rustdoc: Clarify const-stability with regard to normal stability Fixes #125511. - Elide const-unstable if also unstable overall - Show "const" for const-unstable if also overall unstable
2024-05-27Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercotebors-35/+94
[perf] Delay the construction of early lint diag structs Attacks some of the perf regressions from https://github.com/rust-lang/rust/pull/124417#issuecomment-2123700666. See individual commits for details. The first three commits are not strictly necessary. However, the 2nd one (06bc4fc67145e3a7be9b5a2cf2b5968cef36e587, *Remove `LintDiagnostic::msg`*) makes the main change way nicer to implement. It's also pretty sweet on its own if I may say so myself.
2024-05-26rustdoc: Show "const" for const-unstable if also overall unstableNoah Lev-19/+38
If a const function is unstable overall (and thus, in all circumstances I know of, also const-unstable), we should show the option to use it as const. You need to enable a feature to use the function at all anyway. If the function is stabilized without also being const-stabilized, then we do not show the const keyword and instead show "const: unstable" in the version info.
2024-05-25rustdoc: Elide const-unstable if also unstable overallNoah Lev-8/+13
It's confusing because if a function is unstable overall, there's no need to highlight the constness is also unstable. Technically, these attributes (overall stability and const-stability) are separate, but in practice, we don't even show the const-unstable's feature flag (it's normally the same as the overall function).
2024-05-23Remove `LintDiagnostic::msg`León Orell Valerian Liehr-35/+94
* instead simply set the primary message inside the lint decorator functions * it used to be this way before [#]101986 which introduced `msg` to prevent good path delayed bugs (which no longer exist) from firing under certain circumstances when lints were suppressed / silenced * this is no longer necessary for various reasons I presume * it shaves off complexity and makes further changes easier to implement
2024-05-19Don't strip items with inherited visibility in AliasedNonLocalStripperMichael Goulet-2/+7
2024-05-18Auto merge of #125077 - spastorino:add-new-fnsafety-enum2, r=jackh726bors-34/+34
Rename Unsafe to Safety Alternative to #124455, which is to just have one Safety enum to use everywhere, this opens the posibility of adding `ast::Safety::Safe` that's useful for unsafe extern blocks. This leaves us today with: ```rust enum ast::Safety { Unsafe(Span), Default, // Safe (going to be added for unsafe extern blocks) } enum hir::Safety { Unsafe, Safe, } ``` We would convert from `ast::Safety::Default` into the right Safety level according the context.
2024-05-18Rollup merge of #125117 - dev-ardi:improve-parser, r=wesleywiser,fmeaseMatthias Krüger-2/+2
Improve parser Fixes #124935. - Add a few more help diagnostics to incorrect semicolons - Overall improved that function - Addded a few comments - Renamed diff_marker fns to git_diff_marker
2024-05-18Auto merge of #124611 - Urgau:rustdoc-stdin, r=GuillaumeGomezbors-29/+54
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`