Skip to content

Commit 2140961

Browse files
authored
Merge pull request #8282 from sylvestre/clipp
clippy: replace vector indexing with safe .get() method
2 parents 3214c4d + e446ed9 commit 2140961

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/uu/df/src/table.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,16 +447,19 @@ impl fmt::Display for Table {
447447
while let Some((i, elem)) = col_iter.next() {
448448
let is_last_col = col_iter.peek().is_none();
449449

450-
match self.alignments[i] {
451-
Alignment::Left => {
450+
match self.alignments.get(i) {
451+
Some(Alignment::Left) => {
452452
if is_last_col {
453453
// no trailing spaces in last column
454454
write!(f, "{elem}")?;
455455
} else {
456456
write!(f, "{:<width$}", elem, width = self.widths[i])?;
457457
}
458458
}
459-
Alignment::Right => write!(f, "{:>width$}", elem, width = self.widths[i])?,
459+
Some(Alignment::Right) => {
460+
write!(f, "{:>width$}", elem, width = self.widths[i])?;
461+
}
462+
None => break,
460463
}
461464

462465
if !is_last_col {

src/uu/expand/src/expand.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,10 @@ fn expand_line(
381381
}
382382
} else {
383383
(
384-
match buf[byte] {
384+
match buf.get(byte) {
385385
// always take exactly 1 byte in strict ASCII mode
386-
0x09 => Tab,
387-
0x08 => Backspace,
386+
Some(0x09) => Tab,
387+
Some(0x08) => Backspace,
388388
_ => Other,
389389
},
390390
1,

src/uu/stat/src/stat.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -755,11 +755,11 @@ impl Stater {
755755
let chars = format_str.chars().collect::<Vec<char>>();
756756
let mut i = 0;
757757
while i < bound {
758-
match chars[i] {
759-
'%' => tokens.push(Self::handle_percent_case(
758+
match chars.get(i) {
759+
Some('%') => tokens.push(Self::handle_percent_case(
760760
&chars, &mut i, bound, format_str,
761761
)?),
762-
'\\' => {
762+
Some('\\') => {
763763
if use_printf {
764764
tokens.push(Self::handle_escape_sequences(
765765
&chars, &mut i, bound, format_str,
@@ -768,7 +768,8 @@ impl Stater {
768768
tokens.push(Token::Char('\\'));
769769
}
770770
}
771-
c => tokens.push(Token::Char(c)),
771+
Some(c) => tokens.push(Token::Char(*c)),
772+
None => break,
772773
}
773774
i += 1;
774775
}

0 commit comments

Comments
 (0)