Skip to content

Commit 3a77bf4

Browse files
committed
chore: huge clippy pass ahead of 1.92.0 release
1 parent 8d59e08 commit 3a77bf4

File tree

25 files changed

+62
-79
lines changed

25 files changed

+62
-79
lines changed

src/uu/chmod/src/chmod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
133133
let cmode = if let Some(parsed_cmode) = parsed_cmode {
134134
parsed_cmode
135135
} else {
136-
modes.unwrap().to_string() // modes is required
136+
modes.unwrap().to_owned() // modes is required
137137
};
138138
let mut files: Vec<OsString> = matches
139139
.get_many::<OsString>(options::FILE)

src/uu/chroot/src/chroot.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,22 +411,22 @@ fn set_context(options: &Options) -> UResult<()> {
411411
let gid = uid as libc::gid_t;
412412
let strategy = Strategy::FromUID(uid, false);
413413
set_supplemental_gids_with_strategy(strategy, options.groups.as_ref())?;
414-
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(user.to_string(), e))?;
415-
set_uid(uid).map_err(|e| ChrootError::SetUserFailed(user.to_string(), e))?;
414+
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(user.to_owned(), e))?;
415+
set_uid(uid).map_err(|e| ChrootError::SetUserFailed(user.to_owned(), e))?;
416416
}
417417
Some(UserSpec::GroupOnly(group)) => {
418418
let gid = name_to_gid(group)?;
419419
let strategy = Strategy::Nothing;
420420
set_supplemental_gids_with_strategy(strategy, options.groups.as_ref())?;
421-
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(group.to_string(), e))?;
421+
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(group.to_owned(), e))?;
422422
}
423423
Some(UserSpec::UserAndGroup(user, group)) => {
424424
let uid = name_to_uid(user)?;
425425
let gid = name_to_gid(group)?;
426426
let strategy = Strategy::FromUID(uid, true);
427427
set_supplemental_gids_with_strategy(strategy, options.groups.as_ref())?;
428-
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(group.to_string(), e))?;
429-
set_uid(uid).map_err(|e| ChrootError::SetUserFailed(user.to_string(), e))?;
428+
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(group.to_owned(), e))?;
429+
set_uid(uid).map_err(|e| ChrootError::SetUserFailed(user.to_owned(), e))?;
430430
}
431431
}
432432
Ok(())

src/uu/cp/src/copydir.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,12 +613,10 @@ fn build_dir(
613613
0
614614
} as u32;
615615

616-
let umask = if copy_attributes_from.is_some()
617-
&& matches!(options.attributes.mode, Preserve::Yes { .. })
616+
let umask = if let (Some(from), Preserve::Yes { .. }) =
617+
(copy_attributes_from, options.attributes.mode)
618618
{
619-
!fs::symlink_metadata(copy_attributes_from.unwrap())?
620-
.permissions()
621-
.mode()
619+
!fs::symlink_metadata(from)?.permissions().mode()
622620
} else {
623621
uucore::mode::get_umask()
624622
};

src/uu/cp/src/cp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,7 @@ fn copy_source(
15191519
// This fix adds yet another metadata read.
15201520
// Should this metadata be read once and then reused throughout the execution?
15211521
// https://github.com/uutils/coreutils/issues/6658
1522+
#[allow(clippy::if_not_else)]
15221523
fn file_mode_for_interactive_overwrite(
15231524
#[cfg_attr(not(unix), allow(unused_variables))] path: &Path,
15241525
) -> Option<(String, String)> {

src/uu/csplit/src/csplit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ where
172172
// the error happened when applying the pattern more than once
173173
Err(CsplitError::LineOutOfRange(_)) if ith != 1 => {
174174
return Err(CsplitError::LineOutOfRangeOnRepetition(
175-
pattern_as_str.to_string(),
175+
pattern_as_str,
176176
ith - 1,
177177
));
178178
}
@@ -204,7 +204,7 @@ where
204204
// the error happened when applying the pattern more than once
205205
(Err(CsplitError::MatchNotFound(_)), Some(m)) if m != 1 && ith != 1 => {
206206
return Err(CsplitError::MatchNotFoundOnRepetition(
207-
pattern_as_str.to_string(),
207+
pattern_as_str,
208208
ith - 1,
209209
));
210210
}
@@ -623,7 +623,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
623623
let patterns: Vec<String> = matches
624624
.get_many::<String>(options::PATTERN)
625625
.unwrap()
626-
.map(|s| s.to_string())
626+
.map(ToOwned::to_owned)
627627
.collect();
628628
let options = CsplitOptions::new(&matches)?;
629629
if file_name == "-" {

src/uu/csplit/src/patterns.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,17 @@ fn extract_patterns(args: &[String]) -> Result<Vec<Pattern>, CsplitError> {
140140
};
141141
if let Some(up_to_match) = captures.name("UPTO") {
142142
let pattern = Regex::new(up_to_match.as_str())
143-
.map_err(|_| CsplitError::InvalidPattern(arg.to_string()))?;
143+
.map_err(|_| CsplitError::InvalidPattern(arg.to_owned()))?;
144144
patterns.push(Pattern::UpToMatch(pattern, offset, execute_ntimes));
145145
} else if let Some(skip_to_match) = captures.name("SKIPTO") {
146146
let pattern = Regex::new(skip_to_match.as_str())
147-
.map_err(|_| CsplitError::InvalidPattern(arg.to_string()))?;
147+
.map_err(|_| CsplitError::InvalidPattern(arg.to_owned()))?;
148148
patterns.push(Pattern::SkipToMatch(pattern, offset, execute_ntimes));
149149
}
150150
} else if let Ok(line_number) = arg.parse::<usize>() {
151151
patterns.push(Pattern::UpToLine(line_number, execute_ntimes));
152152
} else {
153-
return Err(CsplitError::InvalidPattern(arg.to_string()));
153+
return Err(CsplitError::InvalidPattern(arg.to_owned()));
154154
}
155155
}
156156
Ok(patterns)

src/uu/df/src/df.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,7 @@ impl Options {
163163
block_size: read_block_size(matches).map_err(|e| match e {
164164
ParseSizeError::InvalidSuffix(s) => OptionsError::InvalidSuffix(s),
165165
ParseSizeError::SizeTooBig(_) => OptionsError::BlockSizeTooLarge(
166-
matches
167-
.get_one::<String>(OPT_BLOCKSIZE)
168-
.unwrap()
169-
.to_string(),
166+
matches.get_one::<String>(OPT_BLOCKSIZE).unwrap().to_owned(),
170167
),
171168
ParseSizeError::ParseFailure(s) => OptionsError::InvalidBlockSize(s),
172169
ParseSizeError::PhysicalMem(s) => OptionsError::InvalidBlockSize(s),

src/uu/df/src/filesystem.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ pub(crate) enum FsError {
5151
/// `mounts` after mount that has the same `mount_dir`.
5252
#[cfg(not(windows))]
5353
fn is_over_mounted(mounts: &[MountInfo], mount: &MountInfo) -> bool {
54-
let last_mount_for_dir = mounts
55-
.iter()
56-
.filter(|m| m.mount_dir == mount.mount_dir)
57-
.next_back();
54+
let last_mount_for_dir = mounts.iter().rfind(|m| m.mount_dir == mount.mount_dir);
5855

5956
if let Some(lmi) = last_mount_for_dir {
6057
lmi.dev_name != mount.dev_name

src/uu/df/src/table.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ impl<'a> RowFormatter<'a> {
343343
}
344344

345345
/// A `HeaderMode` defines what header labels should be shown.
346+
#[derive(Default)]
346347
pub(crate) enum HeaderMode {
348+
#[default]
347349
Default,
348350
// the user used -h or -H
349351
HumanReadable,
@@ -353,12 +355,6 @@ pub(crate) enum HeaderMode {
353355
Output,
354356
}
355357

356-
impl Default for HeaderMode {
357-
fn default() -> Self {
358-
Self::Default
359-
}
360-
}
361-
362358
/// The data of the header row.
363359
struct Header {}
364360

src/uu/head/src/head.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,17 +530,13 @@ fn uu_head(options: &HeadOptions) -> UResult<()> {
530530
head_file(&mut file_handle, options)?;
531531
Ok(())
532532
};
533-
if let Err(e) = res {
533+
if let Err(err) = res {
534534
let name = if file == "-" {
535535
"standard input".to_string()
536536
} else {
537537
file.to_string_lossy().into_owned()
538538
};
539-
return Err(HeadError::Io {
540-
name: name.to_string(),
541-
err: e,
542-
}
543-
.into());
539+
return Err(HeadError::Io { name, err }.into());
544540
}
545541
first = false;
546542
}

0 commit comments

Comments
 (0)