* [PATCH v2 0/2] rust: minor idiomatic fixes to doctest generator
@ 2025-05-29 13:14 Tamir Duberstein
2025-05-29 13:14 ` [PATCH v2 1/2] rust: replace length checks with match Tamir Duberstein
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Tamir Duberstein @ 2025-05-29 13:14 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Brendan Higgins, David Gow,
Rae Moar
Cc: linux-kselftest, kunit-dev, rust-for-linux, linux-kernel,
Tamir Duberstein
Please see individual commit messages.
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
Changes in v2:
- rustfmt.
- Alice's RB.
- Add second patch to emit information in panic rather than separately
to stderr.
- Link to v1: https://lore.kernel.org/r/20250527-idiomatic-match-slice-v1-1-34b0b1d1d58c@gmail.com
---
Tamir Duberstein (2):
rust: replace length checks with match
rust: emit path candidates in panic message
scripts/rustdoc_test_gen.rs | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
---
base-commit: 1ce98bb2bb30713ec4374ef11ead0d7d3e856766
change-id: 20250527-idiomatic-match-slice-26a79d100e4d
Best regards,
--
Tamir Duberstein <tamird@gmail.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/2] rust: replace length checks with match
2025-05-29 13:14 [PATCH v2 0/2] rust: minor idiomatic fixes to doctest generator Tamir Duberstein
@ 2025-05-29 13:14 ` Tamir Duberstein
2025-05-29 13:14 ` [PATCH v2 2/2] rust: emit path candidates in panic message Tamir Duberstein
2025-07-20 22:57 ` [PATCH v2 0/2] rust: minor idiomatic fixes to doctest generator Miguel Ojeda
2 siblings, 0 replies; 9+ messages in thread
From: Tamir Duberstein @ 2025-05-29 13:14 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Brendan Higgins, David Gow,
Rae Moar
Cc: linux-kselftest, kunit-dev, rust-for-linux, linux-kernel,
Tamir Duberstein
Use a match expression with slice patterns instead of length checks and
indexing. The result is more idiomatic, which is a better example for
future Rust code authors.
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
scripts/rustdoc_test_gen.rs | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/scripts/rustdoc_test_gen.rs b/scripts/rustdoc_test_gen.rs
index 1ca253594d38..d796481f4359 100644
--- a/scripts/rustdoc_test_gen.rs
+++ b/scripts/rustdoc_test_gen.rs
@@ -85,24 +85,23 @@ fn find_candidates(
}
}
- assert!(
- valid_paths.len() > 0,
- "No path candidates found for `{file}`. This is likely a bug in the build system, or some \
- files went away while compiling."
- );
-
- if valid_paths.len() > 1 {
- eprintln!("Several path candidates found:");
- for path in valid_paths {
- eprintln!(" {path:?}");
+ match valid_paths.as_slice() {
+ [] => panic!(
+ "No path candidates found for `{file}`. This is likely a bug in the build system, or \
+ some files went away while compiling."
+ ),
+ [valid_path] => valid_path.to_str().unwrap(),
+ valid_paths => {
+ eprintln!("Several path candidates found:");
+ for path in valid_paths {
+ eprintln!(" {path:?}");
+ }
+ panic!(
+ "Several path candidates found for `{file}`, please resolve the ambiguity by \
+ renaming a file or folder."
+ );
}
- panic!(
- "Several path candidates found for `{file}`, please resolve the ambiguity by renaming \
- a file or folder."
- );
}
-
- valid_paths[0].to_str().unwrap()
}
fn main() {
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/2] rust: emit path candidates in panic message
2025-05-29 13:14 [PATCH v2 0/2] rust: minor idiomatic fixes to doctest generator Tamir Duberstein
2025-05-29 13:14 ` [PATCH v2 1/2] rust: replace length checks with match Tamir Duberstein
@ 2025-05-29 13:14 ` Tamir Duberstein
2025-05-29 13:21 ` Miguel Ojeda
2025-07-20 22:20 ` Miguel Ojeda
2025-07-20 22:57 ` [PATCH v2 0/2] rust: minor idiomatic fixes to doctest generator Miguel Ojeda
2 siblings, 2 replies; 9+ messages in thread
From: Tamir Duberstein @ 2025-05-29 13:14 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Brendan Higgins, David Gow,
Rae Moar
Cc: linux-kselftest, kunit-dev, rust-for-linux, linux-kernel,
Tamir Duberstein
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 --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}",
);
}
}
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/2] rust: emit path candidates in panic message
2025-05-29 13:14 ` [PATCH v2 2/2] rust: emit path candidates in panic message Tamir Duberstein
@ 2025-05-29 13:21 ` Miguel Ojeda
2025-05-29 14:38 ` Tamir Duberstein
2025-07-20 22:20 ` Miguel Ojeda
1 sibling, 1 reply; 9+ messages in thread
From: Miguel Ojeda @ 2025-05-29 13:21 UTC (permalink / raw)
To: Tamir Duberstein
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Brendan Higgins, David Gow,
Rae Moar, linux-kselftest, kunit-dev, rust-for-linux,
linux-kernel
On Thu, May 29, 2025 at 3:15 PM Tamir Duberstein <tamird@gmail.com> wrote:
>
> Include all information in the panic message rather than emit fragments
> to stderr.
Could we explain the "why" as well in the message? (i.e. not just the "what")
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/2] rust: emit path candidates in panic message
2025-05-29 13:21 ` Miguel Ojeda
@ 2025-05-29 14:38 ` Tamir Duberstein
2025-05-29 16:00 ` Miguel Ojeda
0 siblings, 1 reply; 9+ messages in thread
From: Tamir Duberstein @ 2025-05-29 14:38 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Brendan Higgins, David Gow,
Rae Moar, linux-kselftest, kunit-dev, rust-for-linux,
linux-kernel
On Thu, May 29, 2025 at 9:21 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Thu, May 29, 2025 at 3:15 PM Tamir Duberstein <tamird@gmail.com> wrote:
> >
> > Include all information in the panic message rather than emit fragments
> > to stderr.
>
> Could we explain the "why" as well in the message? (i.e. not just the "what")
Sure, that would be:
Include all information in the panic message rather than emit fragments
to stderr to avoid possible interleaving with other output.
Let me know if I should send another spin for this, or if this is ok
to do on apply.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/2] rust: emit path candidates in panic message
2025-05-29 14:38 ` Tamir Duberstein
@ 2025-05-29 16:00 ` Miguel Ojeda
0 siblings, 0 replies; 9+ messages in thread
From: Miguel Ojeda @ 2025-05-29 16:00 UTC (permalink / raw)
To: Tamir Duberstein
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Brendan Higgins, David Gow,
Rae Moar, linux-kselftest, kunit-dev, rust-for-linux,
linux-kernel
On Thu, May 29, 2025 at 4:38 PM Tamir Duberstein <tamird@gmail.com> wrote:
>
> Sure, that would be:
>
> Include all information in the panic message rather than emit fragments
> to stderr to avoid possible interleaving with other output.
>
> Let me know if I should send another spin for this, or if this is ok
> to do on apply.
Thanks! No worries, I can do that on apply.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/2] rust: emit path candidates in panic message
2025-05-29 13:14 ` [PATCH v2 2/2] rust: emit path candidates in panic message Tamir Duberstein
2025-05-29 13:21 ` Miguel Ojeda
@ 2025-07-20 22:20 ` Miguel Ojeda
2025-07-20 23:01 ` Tamir Duberstein
1 sibling, 1 reply; 9+ messages in thread
From: Miguel Ojeda @ 2025-07-20 22:20 UTC (permalink / raw)
To: Tamir Duberstein
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Brendan Higgins, David Gow,
Rae Moar, linux-kselftest, kunit-dev, rust-for-linux,
linux-kernel
On Thu, May 29, 2025 at 3:15 PM Tamir Duberstein <tamird@gmail.com> wrote:
>
> + write!(&mut candidates, " {path:?}").unwrap();
I assume this was supposed to be `writeln!`; otherwise, we lose the
newlines and the indent does not make much sense.
I will fix it when applying.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/2] rust: minor idiomatic fixes to doctest generator
2025-05-29 13:14 [PATCH v2 0/2] rust: minor idiomatic fixes to doctest generator Tamir Duberstein
2025-05-29 13:14 ` [PATCH v2 1/2] rust: replace length checks with match Tamir Duberstein
2025-05-29 13:14 ` [PATCH v2 2/2] rust: emit path candidates in panic message Tamir Duberstein
@ 2025-07-20 22:57 ` Miguel Ojeda
2 siblings, 0 replies; 9+ messages in thread
From: Miguel Ojeda @ 2025-07-20 22:57 UTC (permalink / raw)
To: Tamir Duberstein
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Brendan Higgins, David Gow,
Rae Moar, linux-kselftest, kunit-dev, rust-for-linux,
linux-kernel
On Thu, May 29, 2025 at 3:15 PM Tamir Duberstein <tamird@gmail.com> wrote:
>
> Please see individual commit messages.
>
> Signed-off-by: Tamir Duberstein <tamird@gmail.com>
Applied to `rust-next` -- thanks everyone!
[ Reworded title. - Miguel ]
[ Kept newlines using `writeln!`. Used new message from Tamir. Reworded
title. - Miguel ]
Cheers,
Miguel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/2] rust: emit path candidates in panic message
2025-07-20 22:20 ` Miguel Ojeda
@ 2025-07-20 23:01 ` Tamir Duberstein
0 siblings, 0 replies; 9+ messages in thread
From: Tamir Duberstein @ 2025-07-20 23:01 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Brendan Higgins, David Gow,
Rae Moar, linux-kselftest, kunit-dev, rust-for-linux,
linux-kernel
On Sun, Jul 20, 2025 at 6:20 PM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Thu, May 29, 2025 at 3:15 PM Tamir Duberstein <tamird@gmail.com> wrote:
> >
> > + write!(&mut candidates, " {path:?}").unwrap();
>
> I assume this was supposed to be `writeln!`; otherwise, we lose the
> newlines and the indent does not make much sense.
Duh, yes, that's right.
> I will fix it when applying.
Thank you!
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-07-20 23:02 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-29 13:14 [PATCH v2 0/2] rust: minor idiomatic fixes to doctest generator Tamir Duberstein
2025-05-29 13:14 ` [PATCH v2 1/2] rust: replace length checks with match Tamir Duberstein
2025-05-29 13:14 ` [PATCH v2 2/2] rust: emit path candidates in panic message Tamir Duberstein
2025-05-29 13:21 ` Miguel Ojeda
2025-05-29 14:38 ` Tamir Duberstein
2025-05-29 16:00 ` Miguel Ojeda
2025-07-20 22:20 ` Miguel Ojeda
2025-07-20 23:01 ` Tamir Duberstein
2025-07-20 22:57 ` [PATCH v2 0/2] rust: minor idiomatic fixes to doctest generator Miguel Ojeda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).