From: "Gary Guo" <gary@garyguo.net>
To: "David Gow" <david@davidgow.net>, "Gary Guo" <gary@garyguo.net>,
"Brendan Higgins" <brendan.higgins@linux.dev>,
"Rae Moar" <raemoar63@gmail.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Igor Korotin" <igor.korotin@linux.dev>
Cc: <rust-for-linux@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, <kunit-dev@googlegroups.com>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] rust: doctest: trim function name for reproducbility
Date: Sun, 14 Jun 2026 14:01:56 +0100 [thread overview]
Message-ID: <DJ8SIY9SCW97.ZOTSZPBIKMWV@garyguo.net> (raw)
In-Reply-To: <5f5c5555-466d-41ac-8187-8b9ddc14965f@davidgow.net>
On Sun Jun 14, 2026 at 8:07 AM BST, David Gow wrote:
> Le 13/06/2026 à 10:04 PM, Gary Guo a écrit :
>> From: Gary Guo <gary@garyguo.net>
>>
>> Currently rustdoc will generate function names like
>> "_doctest_main__home_gary_Projects_linux_rust_kernel_io_rs_824_0" for a
>> doctest located at rust/kernel/io.rs:824, when building with separate
>> outdir using `O=`. This creates overlong symbol names and is also not
>> reproducible.
>>
>> Fix it by doing a custom remapping to trim it to something like
>> `_doctest_main_rust_kernel_io_rs_824_0`.
>>
>> Signed-off-by: Gary Guo <gary@garyguo.net>
>> ---
>
> Hi Gary,
>
> This seems to break older versions of rustc. For example, with
> rust 1.93.1, the build now fails with errors like:
>
> ERROR:root:error[E0425]: cannot find function `_doctest_main_rust_kernel_alloc_allocator_rs_176_0` in this scope
> --> rust/doctests_kernel_generated.rs:74:27
> |
> 74 | } let test_return_value = _doctest_main_rust_kernel_alloc_allocator_rs_176_0(); assert!(test_return_value.is_ok()); }
> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
>
>
> Am I missing something? I'm using kunit.py to build:
> ./tools/testing/kunit/kunit.py run --kconfig_add CONFIG_RUST=y rust_doctests_kernel
>
> Seems to be working okay with 1.96, though.
It looks like upstream rustdoc is using fully qualified path from 1.87+, so the
replacement doesn't find it anymore. Not sure why it works in 1.96, though.
Sashiko suggested doing a full text replacement which I think makes more sense
anyway and would work for all versions (and also for unit-returning functions).
Will do it for the next version.
Best,
Gary
>
> Cheers,
> -- David
>
>> scripts/rustdoc_test_builder.rs | 14 +++++++++-----
>> 1 file changed, 9 insertions(+), 5 deletions(-)
>>
>> diff --git a/scripts/rustdoc_test_builder.rs b/scripts/rustdoc_test_builder.rs
>> index 2b1f9ba01839..fda7284355f8 100644
>> --- a/scripts/rustdoc_test_builder.rs
>> +++ b/scripts/rustdoc_test_builder.rs
>> @@ -47,11 +47,18 @@ fn main() {
>> })
>> .expect("No test function found in `rustdoc`'s output.");
>>
>> + // Figure out a smaller test name based on the generated function name.
>> + let name = rustdoc_function_name.split_once("_rust_kernel_").unwrap().1;
>> +
>> + // The rustdoc function name can include the absolute path when building with `O=` which is
>> + // undesireable and create overlong symbol names. Remap it to relative path.
>> + let trimmed_function_name = format!("_doctest_main_rust_kernel_{name}");
>> +
>> // Qualify `Result` to avoid the collision with our own `Result` coming from the prelude.
>> let body = body.replace(
>> &format!("{rustdoc_function_name}() -> Result<(), impl core::fmt::Debug> {{"),
>> &format!(
>> - "{rustdoc_function_name}() -> ::core::result::Result<(), impl ::core::fmt::Debug> {{"
>> + "{trimmed_function_name}() -> ::core::result::Result<(), impl ::core::fmt::Debug> {{"
>> ),
>> );
>>
>> @@ -62,12 +69,9 @@ fn main() {
>> // We save the result in a variable so that the failed assertion message looks nicer.
>> let body = body.replace(
>> &format!("}} {rustdoc_function_name}().unwrap() }}"),
>> - &format!("}} let test_return_value = {rustdoc_function_name}(); assert!(test_return_value.is_ok()); }}"),
>> + &format!("}} let test_return_value = {trimmed_function_name}(); assert!(test_return_value.is_ok()); }}"),
>> );
>>
>> - // Figure out a smaller test name based on the generated function name.
>> - let name = rustdoc_function_name.split_once("_rust_kernel_").unwrap().1;
>> -
>> let path = format!("rust/test/doctests/kernel/{name}");
>>
>> std::fs::write(path, body.as_bytes()).unwrap();
prev parent reply other threads:[~2026-06-14 13:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-13 14:04 [PATCH 1/2] rust: doctest: fix incorrect pattern in replacement Gary Guo
2026-06-13 14:04 ` [PATCH 2/2] rust: doctest: trim function name for reproducbility Gary Guo
2026-06-14 7:07 ` David Gow
2026-06-14 13:01 ` Gary Guo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DJ8SIY9SCW97.ZOTSZPBIKMWV@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=brendan.higgins@linux.dev \
--cc=dakr@kernel.org \
--cc=david@davidgow.net \
--cc=gregkh@linuxfoundation.org \
--cc=igor.korotin@linux.dev \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=raemoar63@gmail.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox