Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy suggestions #5895

Merged
merged 5 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:
run: |
## `cargo clippy` lint testing
unset fault
CLIPPY_FLAGS="-W clippy::default_trait_access -W clippy::manual_string_new -W clippy::cognitive_complexity -W clippy::implicit_clone"
CLIPPY_FLAGS="-W clippy::default_trait_access -W clippy::manual_string_new -W clippy::cognitive_complexity -W clippy::implicit_clone -W clippy::range-plus-one -W clippy::redundant-clone"
fault_type="${{ steps.vars.outputs.FAULT_TYPE }}"
fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]')
# * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
Expand Down
2 changes: 1 addition & 1 deletion src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ fn aligned_ancestors<'a>(source: &'a Path, dest: &'a Path) -> Vec<(&'a Path, &'a
// Get the matching number of elements from the ancestors of the
// destination path (for example, get "d/a" and "d/a/b").
let k = source_ancestors.len();
let dest_ancestors = &dest_ancestors[1..1 + k];
let dest_ancestors = &dest_ancestors[1..=k];

// Now we have two slices of the same length, so we zip them.
let mut result = vec![];
Expand Down
6 changes: 3 additions & 3 deletions src/uu/nl/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn parse_options(settings: &mut crate::Settings, opts: &clap::ArgMatches) ->
{
None => {}
Some(Ok(style)) => settings.header_numbering = style,
Some(Err(message)) => errs.push(message.to_string()),
Some(Err(message)) => errs.push(message),
}
match opts
.get_one::<String>(options::BODY_NUMBERING)
Expand All @@ -45,7 +45,7 @@ pub fn parse_options(settings: &mut crate::Settings, opts: &clap::ArgMatches) ->
{
None => {}
Some(Ok(style)) => settings.body_numbering = style,
Some(Err(message)) => errs.push(message.to_string()),
Some(Err(message)) => errs.push(message),
}
match opts
.get_one::<String>(options::FOOTER_NUMBERING)
Expand All @@ -54,7 +54,7 @@ pub fn parse_options(settings: &mut crate::Settings, opts: &clap::ArgMatches) ->
{
None => {}
Some(Ok(style)) => settings.footer_numbering = style,
Some(Err(message)) => errs.push(message.to_string()),
Some(Err(message)) => errs.push(message),
}
match opts.get_one::<usize>(options::NUMBER_WIDTH) {
None => {}
Expand Down
8 changes: 2 additions & 6 deletions src/uu/numfmt/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ impl<'a> Iterator for WhitespaceSplitter<'a> {
.unwrap_or(haystack.len()),
);

let (field, rest) = field.split_at(
field
.find(|c: char| c.is_whitespace())
.unwrap_or(field.len()),
);
let (field, rest) = field.split_at(field.find(char::is_whitespace).unwrap_or(field.len()));

self.s = if rest.is_empty() { None } else { Some(rest) };

Expand Down Expand Up @@ -107,7 +103,7 @@ fn parse_implicit_precision(s: &str) -> usize {
match s.split_once('.') {
Some((_, decimal_part)) => decimal_part
.chars()
.take_while(|c| c.is_ascii_digit())
.take_while(char::is_ascii_digit)
.count(),
None => 0,
}
Expand Down
4 changes: 2 additions & 2 deletions src/uu/sort/src/numeric_str_cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ pub fn numeric_str_cmp((a, a_info): (&str, &NumInfo), (b, b_info): (&str, &NumIn
a_info.exponent.cmp(&b_info.exponent)
} else {
// walk the characters from the front until we find a difference
let mut a_chars = a.chars().filter(|c| c.is_ascii_digit());
let mut b_chars = b.chars().filter(|c| c.is_ascii_digit());
let mut a_chars = a.chars().filter(char::is_ascii_digit);
let mut b_chars = b.chars().filter(char::is_ascii_digit);
loop {
let a_next = a_chars.next();
let b_next = b_chars.next();
Expand Down
2 changes: 1 addition & 1 deletion src/uu/sort/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ impl FieldSelector {
let mut range = match to {
Some(Resolution::StartOfChar(mut to)) => {
// We need to include the character at `to`.
to += line[to..].chars().next().map_or(1, |c| c.len_utf8());
to += line[to..].chars().next().map_or(1, char::len_utf8);
from..to
}
Some(Resolution::EndOfChar(to)) => from..to,
Expand Down
5 changes: 2 additions & 3 deletions src/uu/split/src/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,7 @@ impl<'a> Write for LineChunkWriter<'a> {
// Write the line, starting from *after* the previous
// separator character and ending *after* the current
// separator character.
let num_bytes_written =
custom_write(&buf[prev..i + 1], &mut self.inner, self.settings)?;
let num_bytes_written = custom_write(&buf[prev..=i], &mut self.inner, self.settings)?;
total_bytes_written += num_bytes_written;
prev = i + 1;
self.num_lines_remaining_in_current_chunk -= 1;
Expand Down Expand Up @@ -1090,7 +1089,7 @@ impl<'a> Write for LineBytesChunkWriter<'a> {
// example comment above.)
Some(i) if i < self.num_bytes_remaining_in_current_chunk => {
let num_bytes_written =
custom_write(&buf[..i + 1], &mut self.inner, self.settings)?;
custom_write(&buf[..=i], &mut self.inner, self.settings)?;
self.num_bytes_remaining_in_current_chunk -= num_bytes_written;
total_bytes_written += num_bytes_written;
buf = &buf[num_bytes_written..];
Expand Down
4 changes: 2 additions & 2 deletions src/uu/uniq/src/uniq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl Uniq {

// fast path: avoid skipping
if self.ignore_case && slice_start == 0 && slice_stop == len {
return closure(&mut fields_to_check.chars().flat_map(|c| c.to_uppercase()));
return closure(&mut fields_to_check.chars().flat_map(char::to_uppercase));
}

// fast path: we can avoid mapping chars to upper-case, if we don't want to ignore the case
Expand All @@ -173,7 +173,7 @@ impl Uniq {
.chars()
.skip(slice_start)
.take(slice_stop)
.flat_map(|c| c.to_uppercase()),
.flat_map(char::to_uppercase),
)
} else {
closure(&mut fields_to_check.chars())
Expand Down
2 changes: 1 addition & 1 deletion src/uu/wc/src/wc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl<'a> Inputs<'a> {

// The 1-based index of each yielded item must be tracked for error reporting.
let mut with_idx = base.enumerate().map(|(i, v)| (i + 1, v));
let files0_from_path = settings.files0_from.as_ref().map(|p| p.as_borrowed());
let files0_from_path = settings.files0_from.as_ref().map(Input::as_borrowed);

let iter = iter::from_fn(move || {
let (idx, next) = with_idx.next()?;
Expand Down
6 changes: 3 additions & 3 deletions src/uucore/src/lib/parser/parse_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ impl<'parser> Parser<'parser> {
NumberSystem::Hexadecimal => size
.chars()
.take(2)
.chain(size.chars().skip(2).take_while(|c| c.is_ascii_hexdigit()))
.chain(size.chars().skip(2).take_while(char::is_ascii_hexdigit))
.collect(),
_ => size.chars().take_while(|c| c.is_ascii_digit()).collect(),
_ => size.chars().take_while(char::is_ascii_digit).collect(),
};
let mut unit: &str = &size[numeric_string.len()..];

Expand Down Expand Up @@ -243,7 +243,7 @@ impl<'parser> Parser<'parser> {

let num_digits: usize = size
.chars()
.take_while(|c| c.is_ascii_digit())
.take_while(char::is_ascii_digit)
.collect::<String>()
.len();
let all_zeros = size.chars().all(|c| c == '0');
Expand Down
Loading