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 <aliceryhl@google.com> Signed-off-by: Tamir Duberstein <tamird@gmail.com> Link: https://lore.kernel.org/r/20250529-idiomatic-match-slice-v2-1-4925ca2f1550@gmail.com [ Reworded title. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>pull/1320/head
parent
275ad5e793
commit
8b097b5ac6
|
|
@ -85,24 +85,23 @@ fn find_real_path<'a>(srctree: &Path, valid_paths: &'a mut Vec<PathBuf>, file: &
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert!(
|
match valid_paths.as_slice() {
|
||||||
valid_paths.len() > 0,
|
[] => panic!(
|
||||||
"No path candidates found for `{file}`. This is likely a bug in the build system, or some \
|
"No path candidates found for `{file}`. This is likely a bug in the build system, or \
|
||||||
files went away while compiling."
|
some files went away while compiling."
|
||||||
);
|
),
|
||||||
|
[valid_path] => valid_path.to_str().unwrap(),
|
||||||
if valid_paths.len() > 1 {
|
valid_paths => {
|
||||||
eprintln!("Several path candidates found:");
|
eprintln!("Several path candidates found:");
|
||||||
for path in valid_paths {
|
for path in valid_paths {
|
||||||
eprintln!(" {path:?}");
|
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() {
|
fn main() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue