diff mbox series

[v2,2/2] rust: emit path candidates in panic message

Message ID 20250529-idiomatic-match-slice-v2-2-4925ca2f1550@gmail.com
State New
Headers show
Series rust: minor idiomatic fixes to doctest generator | expand

Commit Message

Tamir Duberstein May 29, 2025, 1:14 p.m. UTC
Include all information in the panic message rather than emit fragments
to stderr.

Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
 scripts/rustdoc_test_gen.rs | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/scripts/rustdoc_test_gen.rs b/scripts/rustdoc_test_gen.rs
index d796481f4359..f95129b03cd8 100644
--- a/scripts/rustdoc_test_gen.rs
+++ b/scripts/rustdoc_test_gen.rs
@@ -92,13 +92,15 @@  fn find_candidates(
         ),
         [valid_path] => valid_path.to_str().unwrap(),
         valid_paths => {
-            eprintln!("Several path candidates found:");
+            use std::fmt::Write;
+
+            let mut candidates = String::new();
             for path in valid_paths {
-                eprintln!("    {path:?}");
+                write!(&mut candidates, "    {path:?}").unwrap();
             }
             panic!(
                 "Several path candidates found for `{file}`, please resolve the ambiguity by \
-                renaming a file or folder."
+                renaming a file or folder. Candidates:\n{candidates}",
             );
         }
     }