mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
Remove some indexing (#6728)
**Summary** A common pattern in the code used to be ```rust if statements.len() != 1 { return; } use_single_entry(statements[0])?; ``` which can be better expressed as ```rust let [statement] = statements else { return; }; use_single_entry(statements)?; ``` Direct indexing can cause panics if you don't manually take care of checking the length, while matching (such as if-let or let-else) can never panic. This isn't a complete refactor, i've just removed some of the obvious cases. I've specifically looked for `.len() != 1` and fixed those. **Test Plan** No functional changes
This commit is contained in:
parent
2405536d03
commit
aafde6db28
9 changed files with 50 additions and 67 deletions
|
@ -90,12 +90,11 @@ fn is_stdin(files: &[PathBuf], stdin_filename: Option<&Path>) -> bool {
|
|||
return true;
|
||||
}
|
||||
|
||||
let [file] = files else {
|
||||
return false;
|
||||
};
|
||||
// If the user provided exactly `-`, read from standard input.
|
||||
if files.len() == 1 && files[0] == Path::new("-") {
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
file == Path::new("-")
|
||||
}
|
||||
|
||||
pub fn run(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue