Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH v2 1/2] rust: doctest: fix incorrect pattern in replacement
@ 2026-06-16 13:25 Gary Guo
  2026-06-16 13:25 ` [PATCH v2 2/2] rust: doctest: trim function name for reproducbility Gary Guo
  0 siblings, 1 reply; 2+ messages in thread
From: Gary Guo @ 2026-06-16 13:25 UTC (permalink / raw)
  To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, Brendan Higgins, David Gow,
	Rae Moar, Igor Korotin, Greg Kroah-Hartman
  Cc: rust-for-linux, linux-kselftest, kunit-dev, linux-kernel

From: Gary Guo <gary@garyguo.net>

The `-> Result<(), impl core::fmt::Debug>` string is generated by rustdoc
and by adding "::" into the string it no longer finds anything, and making
the line useless.

Remove the "::" in the pattern. Omit it in the replacement too, for
consistency with upstream rustdoc.

Fixes: de7cd3e4d638 ("rust: use absolute paths in macros referencing core and kernel")
Signed-off-by: Gary Guo <gary@garyguo.net>
--
Changes in v2:
- Update comments too
- Stops using :: in the replacement too to be consistent with upstream
  rustdoc
---
 scripts/rustdoc_test_builder.rs | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/scripts/rustdoc_test_builder.rs b/scripts/rustdoc_test_builder.rs
index f7540bcf595a..5457679c12f9 100644
--- a/scripts/rustdoc_test_builder.rs
+++ b/scripts/rustdoc_test_builder.rs
@@ -28,7 +28,7 @@ fn main() {
     //
     // ```
     // fn main() { #[allow(non_snake_case)] fn _doctest_main_rust_kernel_file_rs_28_0() {
-    // fn main() { #[allow(non_snake_case)] fn _doctest_main_rust_kernel_file_rs_37_0() -> Result<(), impl ::core::fmt::Debug> {
+    // fn main() { #[allow(non_snake_case)] fn _doctest_main_rust_kernel_file_rs_37_0() -> Result<(), impl core::fmt::Debug> {
     // ```
     //
     // It should be unlikely that doctest code matches such lines (when code is formatted properly).
@@ -47,12 +47,14 @@ fn main() {
         })
         .expect("No test function found in `rustdoc`'s output.");
 
-    // Qualify `Result` to avoid the collision with our own `Result` coming from the prelude.
+    // Replicate rustdoc 1.87+ behaviour by fully qualify `Result` (to avoid the collision with our
+    // own `Result` coming from the prelude).
+    //
+    // TODO: Remove this when MSRV is bumped above 1.87.
     let body = body.replace(
-        &format!("{rustdoc_function_name}() -> Result<(), impl ::core::fmt::Debug> {{"),
-        &format!(
-            "{rustdoc_function_name}() -> ::core::result::Result<(), impl ::core::fmt::Debug> {{"
-        ),
+        &format!("{rustdoc_function_name}() -> Result<(), impl core::fmt::Debug> {{"),
+        // This intentionally does not use absolute paths to match rustdoc 1.87 behaviour.
+        &format!("{rustdoc_function_name}() -> core::result::Result<(), impl core::fmt::Debug> {{"),
     );
 
     // For tests that get generated with `Result`, like above, `rustdoc` generates an `unwrap()` on

base-commit: c425609d6ac4012c8bbf01ec2e10e801b1923a7b
prerequisite-patch-id: 0000000000000000000000000000000000000000
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-16 13:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-16 13:25 [PATCH v2 1/2] rust: doctest: fix incorrect pattern in replacement Gary Guo
2026-06-16 13:25 ` [PATCH v2 2/2] rust: doctest: trim function name for reproducbility Gary Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox