Skip to content

Commit ac4d1ca

Browse files
nbdd0121ojeda
authored andcommitted
rust: doctest: fix incorrect pattern in replacement
The `-> Result<(), impl core::fmt::Debug>` string is generated by rustdoc and by adding "::" into the string it no longer finds anything, making the line useless. Remove the "::" in the pattern. Omit it in the replacement too, for consistency with upstream rustdoc. Fixes: de7cd3e ("rust: use absolute paths in macros referencing core and kernel") Signed-off-by: Gary Guo <gary@garyguo.net> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260616132559.2245814-1-gary@kernel.org [ Added link in code comment to `rustdoc`'s 1.87 PR that fully qualified it for context. Improved comments for consistency. Reworded to drop changelog and to fix typo. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent f09d231 commit ac4d1ca

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

scripts/rustdoc_test_builder.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() {
2828
//
2929
// ```
3030
// fn main() { #[allow(non_snake_case)] fn _doctest_main_rust_kernel_file_rs_28_0() {
31-
// fn main() { #[allow(non_snake_case)] fn _doctest_main_rust_kernel_file_rs_37_0() -> Result<(), impl ::core::fmt::Debug> {
31+
// fn main() { #[allow(non_snake_case)] fn _doctest_main_rust_kernel_file_rs_37_0() -> Result<(), impl core::fmt::Debug> {
3232
// ```
3333
//
3434
// It should be unlikely that doctest code matches such lines (when code is formatted properly).
@@ -47,12 +47,16 @@ fn main() {
4747
})
4848
.expect("No test function found in `rustdoc`'s output.");
4949

50-
// Qualify `Result` to avoid the collision with our own `Result` coming from the prelude.
50+
// Replicate `rustdoc` 1.87+ behaviour [1] by fully qualifying `Result` to avoid the collision
51+
// with our own `Result` coming from the prelude.
52+
//
53+
// [1]: https://github.com/rust-lang/rust/pull/137807
54+
//
55+
// TODO: Remove this when MSRV is bumped above 1.87.
5156
let body = body.replace(
52-
&format!("{rustdoc_function_name}() -> Result<(), impl ::core::fmt::Debug> {{"),
53-
&format!(
54-
"{rustdoc_function_name}() -> ::core::result::Result<(), impl ::core::fmt::Debug> {{"
55-
),
57+
&format!("{rustdoc_function_name}() -> Result<(), impl core::fmt::Debug> {{"),
58+
// This intentionally does not use absolute paths to match `rustdoc` 1.87 behaviour.
59+
&format!("{rustdoc_function_name}() -> core::result::Result<(), impl core::fmt::Debug> {{"),
5660
);
5761

5862
// For tests that get generated with `Result`, like above, `rustdoc` generates an `unwrap()` on

0 commit comments

Comments
 (0)