about summary refs log tree commit diff
path: root/src/librustdoc/doctest.rs
AgeCommit message (Collapse)AuthorLines
2025-10-03Rollup merge of #147292 - Urgau:rustdoc-test-unstable_opts, r=fmeaseMatthias Krüger-0/+2
Respect `-Z` unstable options in `rustdoc --test` This PR makes rustdoc respect `-Z` unstable options when collecting doctests (`rustdoc --test`). In the process I also realized that `--error-format` wasn't respected as well, making UI annotations impossible to write so I fixed that as well. Best reviewed commit by commit. Fixes https://github.com/rust-lang/rust/issues/147276 Fixes https://github.com/rust-lang/rust/issues/143930 r? fmease
2025-10-03Respect `--error-format` in `rustdoc --test`Urgau-0/+1
2025-10-03Respect `-Z` unstable options in `rustdoc --test`Urgau-0/+1
2025-09-25Correctly display merged doctest compilation timeGuillaume Gomez-3/+7
2025-08-14Do not pass duplicated `-L` arguments to merged doctestsJakub Beránek-2/+8
2025-08-09Use new public libtest `ERROR_EXIT_CODE` constant in rustdocGuillaume Gomez-3/+1
2025-07-31Fix CI build failure when using new libtest public constantGuillaume Gomez-2/+3
2025-07-31Make `libtest::ERROR_EXIT_CODE` const public to not redefine it in rustdocGuillaume Gomez-1/+1
2025-07-30Rollup merge of #144308 - GuillaumeGomez:merged-doctest-times, r=lolbinarycatSamuel Tardieu-15/+69
[rustdoc] Display total time and compilation time of merged doctests Fixes rust-lang/rust#144270. Does it look good to you `@kpreid?` <img width="908" height="263" alt="image" src="https://github.com/user-attachments/assets/cd5d082d-c4e0-42ed-91dd-bd263b413dcd" />
2025-07-24Display total time and compilation time of merged doctestsGuillaume Gomez-15/+69
2025-07-21Use serde for target spec json deserializeNoratrieb-1/+1
The previous manual parsing of `serde_json::Value` was a lot of complicated code and extremely error-prone. It was full of janky behavior like sometimes ignoring type errors, sometimes erroring for type errors, sometimes warning for type errors, and sometimes just ICEing for type errors (the icing on the top). Additionally, many of the error messages about allowed values were out of date because they were in a completely different place than the FromStr impls. Overall, the system caused confusion for users. I also found the old deserialization code annoying to read. Whenever a `key!` invocation was found, one had to first look for the right macro arm, and no go to definition could help. This PR replaces all this manual parsing with a 2-step process involving serde. First, the string is parsed into a `TargetSpecJson` struct. This struct is a 1:1 representation of the spec JSON. It already parses all the enums and is very simple to read and write. Then, the fields from this struct are copied into the actual `Target`. The reason for this two-step process instead of just serializing into a `Target` is because of a few reasons 1. There are a few transformations performed between the two formats 2. The default logic is implemented this way. Otherwise all the default field values would have to be spelled out again, which is suboptimal. With this logic, they fall out naturally, because everything in the json struct is an `Option`. Overall, the mapping is pretty simple, with the vast majority of fields just doing a 1:1 mapping that is captured by two macros. I have deliberately avoided making the macros generic to keep them simple. All the `FromStr` impls now have the error message right inside them, which increases the chance of it being up to date. Some "`from_str`" impls were turned into proper `FromStr` impls to support this. The new code is much less involved, delegating all the JSON parsing logic to serde, without any manual type matching. This change introduces a few breaking changes for consumers. While it is possible to use this format on stable, it is very much subject to change, so breaking changes are expected. The hope is also that because of the way stricter behavior, breaking changes are easier to deal with, as they come with clearer error messages. 1. Invalid types now always error, everywhere. Previously, they would sometimes error, and sometimes just be ignored (which meant the users JSON was still broken, just silently!) 2. This now makes use of `deny_unknown_fields` instead of just warning on unused fields, which was done previously. Serde doesn't make it easy to get such warning behavior, which was the primary reason that this now changed. But I think error behavior is very reasonable too. If someone has random stale fields in their JSON, it is likely because these fields did something at some point but no longer do, and the user likely wants to be informed of this so they can figure out what to do. This is also relevant for the future. If we remove a field but someone has it set, it probably makes sense for them to take a look whether they need this and should look for alternatives, or whether they can just delete it. Overall, the JSON is made more explicit. This is the only expected breakage, but there could also be small breakage from small mistakes. All targets roundtrip though, so it can't be anything too major.
2025-07-19Fix clippy lints in librustdocGuillaume Gomez-2/+2
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-1/+1
2025-06-24rustc_session: Add a structure for keeping both explicit and default sysrootsVadim Petrochenkov-3/+4
Also avoid creating and cloning sysroot unnecessarily.
2025-06-10Improve naming of variables in `DocTestBuilder::generate_unique_doctest`Guillaume Gomez-2/+2
Improve code
2025-06-10Give more information into extracted doctest informationGuillaume Gomez-2/+2
2025-05-22Allow `#![doc(test(attr(..)))]` doctests to be again merged togetherUrgau-7/+24
2025-05-22Collect and use `#![doc(test(attr(..)))]` at module level tooUrgau-13/+5
2025-05-22Auto merge of #140527 - GuillaumeGomez:doctest-main-fn, r=notriddlebors-13/+15
Emit a warning if the doctest `main` function will not be run Fixes #140310. I think we could try to go much further like adding a "link" (ie UI annotations) on the `main` function in the doctest. However that will require some more computation, not sure if it's worth it or not. Can still be done in a follow-up if we want it. For now, this PR does two things: 1. Pass the `DiagCtxt` to the doctest parser to emit the warning. 2. Correctly generate the `Span` to where the doctest is starting (I hope the way I did it isn't too bad either...). cc `@fmease` r? `@notriddle`
2025-05-09Rollup merge of #139863 - fmease:simp-doctest-build-arg-passing, ↵Matthias Krüger-43/+1
r=GuillaumeGomez rustdoc: Replace unstable flag `--doctest-compilation-args` with a simpler one: `--doctest-build-arg` Tracking issue: https://github.com/rust-lang/rust/issues/134172. Context: https://github.com/rust-lang/rust/pull/137096#issuecomment-2776318800 Yeets the ad hoc shell-like lexer for 'nested' program arguments. No FCP necessary since the flag is unstable. I've chosen to replace `compilation` with `build` because it's shorter (you now need to pass it multiple times in order to pass many arguments to the doctest compiler, so it matters a bit) and since I prefer it esthetically. **Issue**: Even though we don't process the argument passed to `--doctest-build-arg`, we end up passing it via an argument file (`rustc `@argfile`)` which delimits arguments by line break (LF or CRLF, [via](https://doc.rust-lang.org/rustc/command-line-arguments.html#path-load-command-line-flags-from-a-path)) meaning ultimately the arguments still get split which is unfortunate. Still, I think this change is an improvement over the status quo. I'll update the tracking issue if/once this PR merges. I'll also add the (CR)LF issue to 'unresolved question'. r? GuillaumeGomez r? notriddle
2025-05-06Ensure that temporary doctest folder is correctly removed even if doctests ↵Guillaume Gomez-3/+20
failed
2025-05-02Create a builder for DocTestBuilder typeGuillaume Gomez-11/+9
2025-05-02Emit a warning if the doctest `main` function will not be runGuillaume Gomez-4/+8
2025-04-25Rollup merge of #137096 - ehuss:stabilize-doctest-xcompile, r=fmeaseMatthias Krüger-4/+2
Stabilize flags for doctest cross compilation This makes the following changes in preparation for supporting doctest cross-compiling in cargo: - Renames `--runtool` and `--runtool-arg` to `--test-runtool` and `--test-runtool-arg` to maintain consistency with other `--test-*` arguments. - Stabilizes the `--test-runtool` and `--test-runtool-arg`. These are needed in order to support cargo's `target.runner` option which specifies a runner to execute a cross-compiled doctest (for example, qemu). - Stabilizes the `--enable-per-target-ignores` flag by removing it and making it unconditionally enabled. This makes it possible to disable a doctest on a per-target basis, which I think will be helpful for rolling out this feature. These changes were suggested in https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/stabilizing.20doctest.20xcompile/near/409281127 The intent is to stabilize the doctest-xcompile feature in cargo. This will help ensure that for projects that do cross-compile testing that their doctests are also covered. Currently there is a somewhat surprising behavior that they are ignored. Closes https://github.com/rust-lang/rust/issues/64245 try-job: x86_64-msvc-1
2025-04-15Replace flag `--doctest-compilation-args` with a simpler one: ↵León Orell Valerian Liehr-43/+1
`--doctest-build-arg` More notably, the value of the new flag does *not* get lexed shell-like and ad hoc.
2025-04-10Allow drivers to supply a list of extra symbols to internAlex Macleod-0/+1
2025-03-27Remove and stabilize --enable-per-target-ignoresEric Huss-2/+0
This removes the `--enable-per-target-ignores` and enables it unconditionally.
2025-03-27Rename `--runtool` and `--runtool-arg`Eric Huss-2/+2
This renames `--runtool` and `--runtool-arg` to `--test-runtool` and `--test-runtool-arg` to maintain consistency with other `--test-*` arguments.
2025-03-13Rollup merge of #138404 - bjorn3:sysroot_handling_cleanup, ↵Matthias Krüger-1/+1
r=petrochenkov,jieyouxu Cleanup sysroot locating a bit All commits should preserve existing behavior.
2025-03-12Make opts.maybe_sysroot non-optionalbjorn3-1/+1
build_session_options always uses materialize_sysroot anyway.
2025-03-12Move methods from `Map` to `TyCtxt`, part 4.Nicholas Nethercote-1/+1
Continuing the work from #137350. Removes the unused methods: `expect_variant`, `expect_field`, `expect_foreign_item`. Every method gains a `hir_` prefix.
2025-03-10doctests: build test bundle and harness separatelyMichael Howell-50/+125
This prevents the included test case from getting at nightly-only features when run on stable. The harness builds with RUSTC_BOOTSTRAP, but the bundle doesn't.
2025-03-10doctests: fix merging on stableMichael Howell-1/+6
Fixes #137898 The generated multi-test harness relies on nightly-only APIs, so the only way to run it on stable is to enable them. Since tests that use crate attrs don't be merged, there's no way to use nightly-only features on it anyway.
2025-03-03Use default field values for `ErrorOutputType`Esteban Küber-1/+1
Remove manual `Default` impl from `config::ErrorOutputType`.
2025-02-12Correctly escape hashtags when running `invalid_rust_codeblocks` lintGuillaume Gomez-0/+1
2025-01-29Improve code and add missing docs for new `doctest::extracted` moduleGuillaume Gomez-10/+12
2025-01-29Move extracted doctest code and types into its own fileGuillaume Gomez-46/+4
2025-01-29Add new output-formatGuillaume Gomez-6/+71
2025-01-23Remove the need to manually call set_using_internal_featuresbjorn3-1/+1
2024-12-25Improve rustdoc codeGuillaume Gomez-1/+1
2024-12-20Move test into the `tests.rs` fileGuillaume Gomez-23/+0
2024-12-20Split arguments from `--doctest-compilation-args` like a shell wouldGuillaume Gomez-8/+64
2024-12-20Add `--doctest-compilation-args` option to allow passing arguments to ↵Guillaume Gomez-0/+11
doctest compilation
2024-12-17Auto merge of #134302 - bjorn3:remove_driver_queries, r=oli-obk,jieyouxubors-20/+20
Remove queries from the driver interface All uses of driver queries in the public api of rustc_driver have been removed in https://github.com/rust-lang/rust/pull/134130 already. This removes driver queries from rustc_interface and does a couple of cleanups around TyCtxt construction and entering enabled by this removal. Finishes the removal of driver queries started with https://github.com/rust-lang/rust/pull/126834.
2024-12-15Add hir::AttributeJonathan Dönszelmann-2/+2
2024-12-14Remove the parse querybjorn3-23/+20
2024-12-14Get rid of of the global_ctxt querybjorn3-17/+20
2024-12-06Remove all threading through of ErrorGuaranteed from the driverbjorn3-15/+7
It was inconsistently done (sometimes even within a single function) and most of the rest of the compiler uses fatal errors instead, which need to be caught using catch_with_exit_code anyway. Using fatal errors instead of ErrorGuaranteed everywhere in the driver simplifies things a bit.
2024-11-28Fix new clippy lintsGuillaume Gomez-1/+1
2024-11-11Auto merge of #126597 - estebank:unicode-output, r=fmeasebors-0/+5
Add Unicode block-drawing compiler output support Add nightly-only theming support to rustc output using Unicode box drawing characters instead of ASCII-art to draw the terminal UI. In order to enable, the flags `-Zunstable-options=yes --error-format=human-unicode` must be passed in. After: ``` error: foo ╭▸ test.rs:3:3 │ 3 │ X0 Y0 Z0 │ ┌───╿──│──┘ │ ┌│───│──┘ │ ┏││━━━┙ │ ┃││ 4 │ ┃││ X1 Y1 Z1 5 │ ┃││ X2 Y2 Z2 │ ┃│└────╿──│──┘ `Z` label │ ┃└─────│──┤ │ ┗━━━━━━┥ `Y` is a good letter too │ `X` is a good letter ╰╴ note: bar ╭▸ test.rs:4:3 │ 4 │ ┏ X1 Y1 Z1 5 │ ┃ X2 Y2 Z2 6 │ ┃ X3 Y3 Z3 │ ┗━━━━━━━━━━┛ ├ note: bar ╰ note: baz note: qux ╭▸ test.rs:4:3 │ 4 │ X1 Y1 Z1 ╰╴ ━━━━━━━━ ``` Before: ``` error: foo --> test.rs:3:3 | 3 | X0 Y0 Z0 | ___^__-__- | |___|__| | ||___| | ||| 4 | ||| X1 Y1 Z1 5 | ||| X2 Y2 Z2 | |||____^__-__- `Z` label | ||_____|__| | |______| `Y` is a good letter too | `X` is a good letter | note: bar --> test.rs:4:3 | 4 | / X1 Y1 Z1 5 | | X2 Y2 Z2 6 | | X3 Y3 Z3 | |__________^ = note: bar = note: baz note: qux --> test.rs:4:3 | 4 | X1 Y1 Z1 | ^^^^^^^^ ``` After: ![rustc output with unicode box drawing characters](https://github.com/rust-lang/rust/assets/1606434/d210b79a-6579-4407-9706-ba8edc6e9f25) Before: ![current rustc output with ASCII art](https://github.com/rust-lang/rust/assets/1606434/5aecccf8-a6ee-4469-8b39-72fb0d979a9f)