On Thu, Sep 3, 2026 at 12:00 AM Gary Guo <[email protected]> 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/[email protected]/
> [1]
>
> Signed-off-by: Gary Guo <[email protected]>
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