about summary refs log tree commit diff
path: root/src/librustdoc/doctest
AgeCommit message (Collapse)AuthorLines
2025-09-27fmtGuillaume Gomez-5/+3
2025-09-27Implement RFC 3631Guillaume Gomez-5/+6
2025-09-09Strip frontmatter in fewer placesLeón Orell Valerian Liehr-8/+11
2025-07-24Display total time and compilation time of merged doctestsGuillaume Gomez-3/+8
2025-07-19Fix clippy lints in librustdocGuillaume Gomez-1/+1
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-1/+1
2025-06-19Extract Translator structCameron Steffen-6/+3
2025-06-11Update extracted-doctest feature documentationGuillaume Gomez-0/+1
2025-06-10Add more tests to check extracted doctests featureGuillaume Gomez-3/+55
2025-06-10Improve naming of variables in `DocTestBuilder::generate_unique_doctest`Guillaume Gomez-7/+38
Improve code
2025-06-10Give more information into extracted doctest informationGuillaume Gomez-46/+130
2025-05-22Collect and use `#[doc(test(attr(..)))]` at every levelUrgau-34/+23
2025-05-22Collect and use `#![doc(test(attr(..)))]` at module level tooUrgau-38/+109
2025-05-22Auto merge of #140527 - GuillaumeGomez:doctest-main-fn, r=notriddlebors-59/+160
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-22/+0
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-0/+1
failed
2025-05-02Create a builder for DocTestBuilder typeGuillaume Gomez-57/+108
2025-05-02Emit a warning if the doctest `main` function will not be runGuillaume Gomez-11/+61
2025-05-01rustdoc: Fix doctest heuristic for main fn wrappingLeón Orell Valerian Liehr-37/+28
2025-04-28Rollup merge of #140220 - GuillaumeGomez:doctest-main-wrapping, r=fmeaseGuillaume Gomez-5/+22
Fix detection of main function if there are expressions around it Fixes #140162. Fixes #139651. Once this is merged, we can backport and I'll send a follow-up to emit a warning in case a `main` function is about to be "wrapped" (and therefore not run). r? `@fmease` try-job: x86_64-mingw-1
2025-04-27Auto merge of #140291 - GuillaumeGomez:doctest-2024-stdout, r=notriddlebors-1/+16
Correctly display stdout and stderr in case a doctest is failing Fixes https://github.com/rust-lang/rust/issues/140289. Since the doctest is actually running itself, we need to handle the output directly inside it. cc `@fmease` r? `@notriddle`
2025-04-27Fix bad handling of macros if there is already a `main` functionGuillaume Gomez-1/+4
2025-04-25If there is a `;` alone, we consider that the doctest needs to be put inside ↵Guillaume Gomez-2/+0
a function
2025-04-25Improve codeGuillaume Gomez-4/+7
2025-04-25Correctly display stdout and stderr in case a doctest is failingGuillaume Gomez-1/+16
2025-04-25Rollup merge of #137096 - ehuss:stabilize-doctest-xcompile, r=fmeaseMatthias Krüger-11/+3
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-23Fix detection of `main` function if there are expressions around itGuillaume Gomez-4/+17
2025-04-17Replace infallible `name_or_empty` methods with fallible `name` methods.Nicholas Nethercote-9/+5
I'm removing empty identifiers everywhere, because in practice they always mean "no identifier" rather than "empty identifier". (An empty identifier is impossible.) It's better to use `Option` to mean "no identifier" because you then can't forget about the "no identifier" possibility. Some specifics: - When testing an attribute for a single name, the commit uses the `has_name` method. - When testing an attribute for multiple names, the commit uses the new `has_any_name` method. - When using `match` on an attribute, the match arms now have `Some` on them. In the tests, we now avoid printing empty identifiers by not printing the identifier in the `error:` line at all, instead letting the carets point out the problem.
2025-04-15Replace flag `--doctest-compilation-args` with a simpler one: ↵León Orell Valerian Liehr-22/+0
`--doctest-build-arg` More notably, the value of the new flag does *not* get lexed shell-like and ad hoc.
2025-04-04Rollup merge of #139328 - GuillaumeGomez:fix-panic-output-137970, r=fmeaseMatthias Krüger-3/+5
Fix 2024 edition doctest panic output Fixes #137970. The problem was that the output was actually displayed by rustc itself because we're exiting with `Result<(), String>`, and the display is really not great. So instead, we get the output, we print it and then we return an `ExitCode`. r? ````@aDotInTheVoid````
2025-04-03Rollup merge of #139255 - GuillaumeGomez:unused-var-merged-doctest, r=fmeaseMatthias Krüger-1/+0
Remove unused variables generated in merged doctests The variable is unused so no need to keep it around. cc `@notriddle` r? `@camelid`
2025-04-03Use `eprint!` instead of `eprintln!`Guillaume Gomez-1/+1
2025-04-03Fix 2024 edition doctest panic outputGuillaume Gomez-3/+5
2025-04-02Remove unused variables generated in merged doctestsGuillaume Gomez-1/+0
2025-04-02Move methods from `Map` to `TyCtxt`, part 5.Nicholas Nethercote-1/+1
This eliminates all methods on `Map`. Actually removing `Map` will occur in a follow-up PR.
2025-04-01Move `ast::Item::ident` into `ast::ItemKind`.Nicholas Nethercote-4/+4
`ast::Item` has an `ident` field. - It's always non-empty for these item kinds: `ExternCrate`, `Static`, `Const`, `Fn`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`, `Trait`, `TraitAlias`, `MacroDef`, `Delegation`. - It's always empty for these item kinds: `Use`, `ForeignMod`, `GlobalAsm`, `Impl`, `MacCall`, `DelegationMac`. There is a similar story for `AssocItemKind` and `ForeignItemKind`. Some sites that handle items check for an empty ident, some don't. This is a very C-like way of doing things, but this is Rust, we have sum types, we can do this properly and never forget to check for the exceptional case and never YOLO possibly empty identifiers (or possibly dummy spans) around and hope that things will work out. The commit is large but it's mostly obvious plumbing work. Some notable things. - `ast::Item` got 8 bytes bigger. This could be avoided by boxing the fields within some of the `ast::ItemKind` variants (specifically: `Struct`, `Union`, `Enum`). I might do that in a follow-up; this commit is big enough already. - For the visitors: `FnKind` no longer needs an `ident` field because the `Fn` within how has one. - In the parser, the `ItemInfo` typedef is no longer needed. It was used in various places to return an `Ident` alongside an `ItemKind`, but now the `Ident` (if present) is within the `ItemKind`. - In a few places I renamed identifier variables called `name` (or `foo_name`) as `ident` (or `foo_ident`), to better match the type, and because `name` is normally used for `Symbol`s. It's confusing to see something like `foo_name.name`.
2025-03-27Remove and stabilize --enable-per-target-ignoresEric Huss-11/+3
This removes the `--enable-per-target-ignores` and enables it unconditionally.
2025-03-27Only take outer attributes into account when generating content between ↵Guillaume Gomez-120/+19
first non-crate items and the crate items
2025-03-27Remove recursion in `check_item`Guillaume Gomez-16/+4
2025-03-27Add new regression test for doctestGuillaume Gomez-0/+131
2025-03-27Improve codeGuillaume Gomez-34/+29
2025-03-27Add `expect` to the list of non-crate attributes for doctest generationGuillaume Gomez-1/+1
2025-03-27Improve code commentGuillaume Gomez-2/+2
2025-03-27Improve comment and test for generated doctest with code commentsGuillaume Gomez-3/+26
2025-03-27Correctly handle line comments in attributes and generate extern cratesGuillaume Gomez-18/+62
outside of wrapping function
2025-03-27Correctly handle `fn main` in macroGuillaume Gomez-18/+35
2025-03-27Greatly simplify doctest parsing and information extractionGuillaume Gomez-323/+136
2025-03-23Rollup merge of #138293 - clubby789:doc-cfg-gate, r=GuillaumeGomezMichael Goulet-1/+1
rustdoc: Gate unstable `doc(cfg())` predicates Fixes #138113 Since the extraction process treats `cfg(true)` as having no cfg attribute, we have to do the gating during parsing; so we remove the unused `features` arg from `Cfg::matches`
2025-03-18Move `hir::Item::ident` into `hir::ItemKind`.Nicholas Nethercote-17/+33
`hir::Item` has an `ident` field. - It's always non-empty for these item kinds: `ExternCrate`, `Static`, `Const`, `Fn`, `Macro`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`, Trait`, TraitAalis`. - It's always empty for these item kinds: `ForeignMod`, `GlobalAsm`, `Impl`. - For `Use`, it is non-empty for `UseKind::Single` and empty for `UseKind::{Glob,ListStem}`. All of this is quite non-obvious; the only documentation is a single comment saying "The name might be a dummy name in case of anonymous items". Some sites that handle items check for an empty ident, some don't. This is a very C-like way of doing things, but this is Rust, we have sum types, we can do this properly and never forget to check for the exceptional case and never YOLO possibly empty identifiers (or possibly dummy spans) around and hope that things will work out. The commit is large but it's mostly obvious plumbing work. Some notable things. - A similar transformation makes sense for `ast::Item`, but this is already a big change. That can be done later. - Lots of assertions are added to item lowering to ensure that identifiers are empty/non-empty as expected. These will be removable when `ast::Item` is done later. - `ItemKind::Use` doesn't get an `Ident`, but `UseKind::Single` does. - `lower_use_tree` is significantly simpler. No more confusing `&mut Ident` to deal with. - `ItemKind::ident` is a new method, it returns an `Option<Ident>`. It's used with `unwrap` in a few places; sometimes it's hard to tell exactly which item kinds might occur. None of these unwraps fail on the test suite. It's conceivable that some might fail on alternative input. We can deal with those if/when they happen. - In `trait_path` the `find_map`/`if let` is replaced with a loop, and things end up much clearer that way. - `named_span` no longer checks for an empty name; instead the call site now checks for a missing identifier if necessary. - `maybe_inline_local` doesn't need the `glob` argument, it can be computed in-function from the `renamed` argument. - `arbitrary_source_item_ordering::check_mod` had a big `if` statement that was just getting the ident from the item kinds that had one. It could be mostly replaced by a single call to the new `ItemKind::ident` method. - `ItemKind` grows from 56 to 64 bytes, but `Item` stays the same size, and that's what matters, because `ItemKind` only occurs within `Item`.
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.