Re: [PATCH v2 0/3] rust: doctest: unify with other kunit tests
From: Miguel Ojeda
Date: Sat Oct 03 2026 - 08:27:37 EST
On Thu, Sep 3, 2026 at 12:00 AM Gary Guo <gary@xxxxxxxxxxx> wrote:
>
> Currently in Rust, kunit tests are handled with `kunit_tests`, while the
> doctests generate a lot `extern "C"` functions and invoke them through a
> generated C wrapper.
>
> This is currently needed because of the special treatment of file name and
> line numbers from doctests. Convert them to override `file!()` and
> `line!()` macro instead, and use them inside `kunit_assert!`.
>
> With this it is possible to just generate `#[kunit_tests]` and `#[test]`
> for doctests.
>
> David mentioned in [1] that this should route via the Rust tree.
>
> Link: https://lore.kernel.org/rust-for-linux/e30d16ec-f5a3-4cd8-9b25-96e0dfa8b9d2@xxxxxxxxxxxx/ [1]
>
> Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>
Applied to `rust-next` -- thanks everyone!
[ Removed spurious `///`-to-`//` change and adjusted `line!` to match.
Added a comment to match `file!`'s. Made `NOTE:` more precise. Reworded
to say it is only one doctest being updated. - Miguel ]
[ Removed generated file from `rust/.gitignore` and added it to
`scripts/remove-stale-files`. - Miguel ]
Cheers,
Miguel