aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/rustdoc_test_gen.rs
diff options
context:
space:
mode:
authorTamir Duberstein <[email protected]>2025-05-29 13:14:58 +0000
committerMiguel Ojeda <[email protected]>2025-07-20 22:03:01 +0000
commit8b097b5ac68b0fd2a7a251e101a84175b2ed585d (patch)
tree6251d676fdbbd132f8b0030a1f0f72d4a576496a /scripts/rustdoc_test_gen.rs
parentrust: list: remove nonexistent generic parameter in link (diff)
downloadkernel-8b097b5ac68b0fd2a7a251e101a84175b2ed585d.tar.gz
kernel-8b097b5ac68b0fd2a7a251e101a84175b2ed585d.zip
scripts: rust: replace length checks with match
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 <[email protected]> Signed-off-by: Tamir Duberstein <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Reworded title. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
Diffstat (limited to 'scripts/rustdoc_test_gen.rs')
-rw-r--r--scripts/rustdoc_test_gen.rs31
1 files 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_real_path<'a>(srctree: &Path, valid_paths: &'a mut Vec<PathBuf>, file: &
}
}
- 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() {