[PATCH] rust: fix off-by-one line number in rustdoc tests

1 view
Skip to first unread message

Gary Guo

unread,
Dec 11, 2025, 1:22:48 PM12/11/25
to Brendan Higgins, David Gow, Rae Moar, Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich, linux-k...@vger.kernel.org, kuni...@googlegroups.com, rust-fo...@vger.kernel.org, linux-...@vger.kernel.org
From: Gary Guo <ga...@garyguo.net>

When the `#![allow]` line was added, the doctest line number anchor
isn't updated which causes the line number printed in kunit test to be
off-by-one.

Fixes: ab844cf32058 ("rust: allow `unreachable_pub` for doctests")
Signed-off-by: Gary Guo <ga...@garyguo.net>
---
scripts/rustdoc_test_gen.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/rustdoc_test_gen.rs b/scripts/rustdoc_test_gen.rs
index be05610496605..6fd9f5c84e2e4 100644
--- a/scripts/rustdoc_test_gen.rs
+++ b/scripts/rustdoc_test_gen.rs
@@ -206,7 +206,7 @@ macro_rules! assert_eq {{

/// The anchor where the test code body starts.
#[allow(unused)]
- static __DOCTEST_ANCHOR: i32 = ::core::line!() as i32 + {body_offset} + 1;
+ static __DOCTEST_ANCHOR: i32 = ::core::line!() as i32 + {body_offset} + 2;
{{
#![allow(unreachable_pub, clippy::disallowed_names)]
{body}

base-commit: 559e608c46553c107dbba19dae0854af7b219400
--
2.51.2

David Gow

unread,
Dec 19, 2025, 5:38:22 AM12/19/25
to Gary Guo, Brendan Higgins, Rae Moar, Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich, linux-k...@vger.kernel.org, kuni...@googlegroups.com, rust-fo...@vger.kernel.org, linux-...@vger.kernel.org
On Fri, 12 Dec 2025 at 02:22, Gary Guo <ga...@kernel.org> wrote:
>
> From: Gary Guo <ga...@garyguo.net>
>
> When the `#![allow]` line was added, the doctest line number anchor
> isn't updated which causes the line number printed in kunit test to be
> off-by-one.
>
> Fixes: ab844cf32058 ("rust: allow `unreachable_pub` for doctests")
> Signed-off-by: Gary Guo <ga...@garyguo.net>
> ---

Nice catch!

Reviewed-by: David Gow <davi...@google.com>

Cheers,
-- David

Miguel Ojeda

unread,
Jan 4, 2026, 5:55:01 PM (14 days ago) Jan 4
to Gary Guo, Brendan Higgins, David Gow, Rae Moar, Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich, linux-k...@vger.kernel.org, kuni...@googlegroups.com, rust-fo...@vger.kernel.org, linux-...@vger.kernel.org
On Thu, Dec 11, 2025 at 7:22 PM Gary Guo <ga...@kernel.org> wrote:
>
> From: Gary Guo <ga...@garyguo.net>
>
> When the `#![allow]` line was added, the doctest line number anchor
> isn't updated which causes the line number printed in kunit test to be
> off-by-one.
>
> Fixes: ab844cf32058 ("rust: allow `unreachable_pub` for doctests")
> Signed-off-by: Gary Guo <ga...@garyguo.net>

Applied to `rust-fixes` -- thanks everyone!

Cheers,
Miguel
Reply all
Reply to author
Forward
0 new messages