Re: [PATCH 2/3] rust: kunit: use `line!()` inside `kunit_assert!`
From: Gary Guo
Date: Mon Jun 22 2026 - 09:02:05 EST
On Tue Jun 16, 2026 at 4:24 PM BST, Gary Guo wrote:
> The `diff` parameter is needed currently because doctests want to override
> the line number. Simplify it by changing it to use `line!()`. Have doctests
> override `line!()` macro to achieve the current behavior.
>
> A few current doctests (or their invoked macros) require `line!()` to
> expand to literal; they're updated to use `::core::line!()` instead.
I've found a way to make `concat!()` still work by having a proc macro thats
does the compute at expansion time (which would eliminate the device_id/str.rs
changes). However, doing so would require the full `proc_macro_span` feature, as
it needs to use `.source()` to replicate the
behaviour of `line!()` (which returns the line number of the out-most
macro invocation, not just the caller one-level up).
Alternatively, this can be implemented by using `expand_expr` to invoke
`::core::line!()` itself, however that is also unstable.
Best,
Gary
>
> Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>
> ---
> rust/kernel/device_id.rs | 2 +-
> rust/kernel/kunit.rs | 8 ++++----
> rust/kernel/str.rs | 2 +-
> rust/macros/kunit.rs | 4 ++--
> scripts/rustdoc_test_gen.rs | 16 ++++++++++++----
> 5 files changed, 20 insertions(+), 12 deletions(-)