Skip to content

Commit e4c7bd0

Browse files
authored
Merge pull request #7724 from nyurik/ref-option
chore: fix `ref_option` lint
2 parents 689aaf9 + ac5a913 commit e4c7bd0

File tree

11 files changed

+45
-44
lines changed

11 files changed

+45
-44
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,4 @@ unused_qualifications = "warn"
600600
[workspace.lints.clippy]
601601
all = { level = "deny", priority = -1 }
602602
#cargo = { level = "warn", priority = -1 }
603+
ref_option = "warn"

src/uu/chroot/src/chroot.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ fn handle_missing_groups(strategy: Strategy) -> Result<(), ChrootError> {
390390
/// Set supplemental groups for this process.
391391
fn set_supplemental_gids_with_strategy(
392392
strategy: Strategy,
393-
groups: &Option<Vec<String>>,
393+
groups: Option<&Vec<String>>,
394394
) -> Result<(), ChrootError> {
395395
match groups {
396396
None => handle_missing_groups(strategy),
@@ -410,27 +410,27 @@ fn set_context(options: &Options) -> UResult<()> {
410410
match &options.userspec {
411411
None | Some(UserSpec::NeitherGroupNorUser) => {
412412
let strategy = Strategy::Nothing;
413-
set_supplemental_gids_with_strategy(strategy, &options.groups)?;
413+
set_supplemental_gids_with_strategy(strategy, options.groups.as_ref())?;
414414
}
415415
Some(UserSpec::UserOnly(user)) => {
416416
let uid = name_to_uid(user)?;
417417
let gid = uid as libc::gid_t;
418418
let strategy = Strategy::FromUID(uid, false);
419-
set_supplemental_gids_with_strategy(strategy, &options.groups)?;
419+
set_supplemental_gids_with_strategy(strategy, options.groups.as_ref())?;
420420
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(user.to_string(), e))?;
421421
set_uid(uid).map_err(|e| ChrootError::SetUserFailed(user.to_string(), e))?;
422422
}
423423
Some(UserSpec::GroupOnly(group)) => {
424424
let gid = name_to_gid(group)?;
425425
let strategy = Strategy::Nothing;
426-
set_supplemental_gids_with_strategy(strategy, &options.groups)?;
426+
set_supplemental_gids_with_strategy(strategy, options.groups.as_ref())?;
427427
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(group.to_string(), e))?;
428428
}
429429
Some(UserSpec::UserAndGroup(user, group)) => {
430430
let uid = name_to_uid(user)?;
431431
let gid = name_to_gid(group)?;
432432
let strategy = Strategy::FromUID(uid, true);
433-
set_supplemental_gids_with_strategy(strategy, &options.groups)?;
433+
set_supplemental_gids_with_strategy(strategy, options.groups.as_ref())?;
434434
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(group.to_string(), e))?;
435435
set_uid(uid).map_err(|e| ChrootError::SetUserFailed(user.to_string(), e))?;
436436
}

src/uu/cp/src/copydir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ where
224224
#[allow(clippy::too_many_arguments)]
225225
/// Copy a single entry during a directory traversal.
226226
fn copy_direntry(
227-
progress_bar: &Option<ProgressBar>,
227+
progress_bar: Option<&ProgressBar>,
228228
entry: Entry,
229229
options: &Options,
230230
symlinked_files: &mut HashSet<FileInformation>,
@@ -314,7 +314,7 @@ fn copy_direntry(
314314
/// will not cause a short-circuit.
315315
#[allow(clippy::too_many_arguments)]
316316
pub(crate) fn copy_directory(
317-
progress_bar: &Option<ProgressBar>,
317+
progress_bar: Option<&ProgressBar>,
318318
root: &Path,
319319
target: &Path,
320320
options: &Options,

src/uu/cp/src/cp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ pub fn copy(sources: &[PathBuf], target: &Path, options: &Options) -> CopyResult
13661366
}
13671367

13681368
if let Err(error) = copy_source(
1369-
&progress_bar,
1369+
progress_bar.as_ref(),
13701370
source,
13711371
target,
13721372
target_type,
@@ -1433,7 +1433,7 @@ fn construct_dest_path(
14331433
}
14341434
#[allow(clippy::too_many_arguments)]
14351435
fn copy_source(
1436-
progress_bar: &Option<ProgressBar>,
1436+
progress_bar: Option<&ProgressBar>,
14371437
source: &Path,
14381438
target: &Path,
14391439
target_type: TargetType,
@@ -1979,7 +1979,7 @@ fn aligned_ancestors<'a>(source: &'a Path, dest: &'a Path) -> Vec<(&'a Path, &'a
19791979

19801980
fn print_verbose_output(
19811981
parents: bool,
1982-
progress_bar: &Option<ProgressBar>,
1982+
progress_bar: Option<&ProgressBar>,
19831983
source: &Path,
19841984
dest: &Path,
19851985
) {
@@ -2207,7 +2207,7 @@ fn calculate_dest_permissions(
22072207
/// after a successful copy.
22082208
#[allow(clippy::cognitive_complexity, clippy::too_many_arguments)]
22092209
fn copy_file(
2210-
progress_bar: &Option<ProgressBar>,
2210+
progress_bar: Option<&ProgressBar>,
22112211
source: &Path,
22122212
dest: &Path,
22132213
options: &Options,

src/uu/dd/src/dd.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,13 +1106,13 @@ fn dd_copy(mut i: Input, o: Output) -> io::Result<()> {
11061106
// blocks to this output. Read/write statistics are updated on
11071107
// each iteration and cumulative statistics are reported to
11081108
// the progress reporting thread.
1109-
while below_count_limit(&i.settings.count, &rstat) {
1109+
while below_count_limit(i.settings.count, &rstat) {
11101110
// Read a block from the input then write the block to the output.
11111111
//
11121112
// As an optimization, make an educated guess about the
11131113
// best buffer size for reading based on the number of
11141114
// blocks already read and the number of blocks remaining.
1115-
let loop_bsize = calc_loop_bsize(&i.settings.count, &rstat, &wstat, i.settings.ibs, bsize);
1115+
let loop_bsize = calc_loop_bsize(i.settings.count, &rstat, &wstat, i.settings.ibs, bsize);
11161116
let rstat_update = read_helper(&mut i, &mut buf, loop_bsize)?;
11171117
if rstat_update.is_empty() {
11181118
break;
@@ -1295,7 +1295,7 @@ fn calc_bsize(ibs: usize, obs: usize) -> usize {
12951295
// Calculate the buffer size appropriate for this loop iteration, respecting
12961296
// a count=N if present.
12971297
fn calc_loop_bsize(
1298-
count: &Option<Num>,
1298+
count: Option<Num>,
12991299
rstat: &ReadStat,
13001300
wstat: &WriteStat,
13011301
ibs: usize,
@@ -1308,7 +1308,7 @@ fn calc_loop_bsize(
13081308
cmp::min(ideal_bsize as u64, rremain * ibs as u64) as usize
13091309
}
13101310
Some(Num::Bytes(bmax)) => {
1311-
let bmax: u128 = (*bmax).into();
1311+
let bmax: u128 = bmax.into();
13121312
let bremain: u128 = bmax - wstat.bytes_total;
13131313
cmp::min(ideal_bsize as u128, bremain) as usize
13141314
}
@@ -1318,10 +1318,10 @@ fn calc_loop_bsize(
13181318

13191319
// Decide if the current progress is below a count=N limit or return
13201320
// true if no such limit is set.
1321-
fn below_count_limit(count: &Option<Num>, rstat: &ReadStat) -> bool {
1321+
fn below_count_limit(count: Option<Num>, rstat: &ReadStat) -> bool {
13221322
match count {
1323-
Some(Num::Blocks(n)) => rstat.reads_complete + rstat.reads_partial < *n,
1324-
Some(Num::Bytes(n)) => rstat.bytes_total < *n,
1323+
Some(Num::Blocks(n)) => rstat.reads_complete + rstat.reads_partial < n,
1324+
Some(Num::Bytes(n)) => rstat.bytes_total < n,
13251325
None => true,
13261326
}
13271327
}

src/uu/pr/src/pr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ fn write_columns(
10851085
for (i, cell) in row.iter().enumerate() {
10861086
if cell.is_none() && options.merge_files_print.is_some() {
10871087
out.write_all(
1088-
get_line_for_printing(options, &blank_line, columns, i, &line_width, indexes)
1088+
get_line_for_printing(options, &blank_line, columns, i, line_width, indexes)
10891089
.as_bytes(),
10901090
)?;
10911091
} else if cell.is_none() {
@@ -1095,7 +1095,7 @@ fn write_columns(
10951095
let file_line = cell.unwrap();
10961096

10971097
out.write_all(
1098-
get_line_for_printing(options, file_line, columns, i, &line_width, indexes)
1098+
get_line_for_printing(options, file_line, columns, i, line_width, indexes)
10991099
.as_bytes(),
11001100
)?;
11011101
lines_printed += 1;
@@ -1116,7 +1116,7 @@ fn get_line_for_printing(
11161116
file_line: &FileLine,
11171117
columns: usize,
11181118
index: usize,
1119-
line_width: &Option<usize>,
1119+
line_width: Option<usize>,
11201120
indexes: usize,
11211121
) -> String {
11221122
let blank_line = String::new();

src/uu/split/src/platform/unix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl Drop for FilterWriter {
121121

122122
/// Instantiate either a file writer or a "write to shell process's stdin" writer
123123
pub fn instantiate_current_writer(
124-
filter: &Option<String>,
124+
filter: Option<&str>,
125125
filename: &str,
126126
is_new: bool,
127127
) -> Result<BufWriter<Box<dyn Write>>> {

src/uu/split/src/platform/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use uucore::fs;
1212
/// Unlike the unix version of this function, this _always_ returns
1313
/// a file writer
1414
pub fn instantiate_current_writer(
15-
_filter: &Option<String>,
15+
_filter: Option<&str>,
1616
filename: &str,
1717
is_new: bool,
1818
) -> Result<BufWriter<Box<dyn Write>>> {

src/uu/split/src/split.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
5555
let (args, obs_lines) = handle_obsolete(args);
5656
let matches = uu_app().try_get_matches_from(args)?;
5757

58-
match Settings::from(&matches, &obs_lines) {
58+
match Settings::from(&matches, obs_lines.as_deref()) {
5959
Ok(settings) => split(&settings),
6060
Err(e) if e.requires_usage() => Err(UUsageError::new(1, format!("{e}"))),
6161
Err(e) => Err(USimpleError::new(1, format!("{e}"))),
@@ -460,7 +460,7 @@ impl SettingsError {
460460

461461
impl Settings {
462462
/// Parse a strategy from the command-line arguments.
463-
fn from(matches: &ArgMatches, obs_lines: &Option<String>) -> Result<Self, SettingsError> {
463+
fn from(matches: &ArgMatches, obs_lines: Option<&str>) -> Result<Self, SettingsError> {
464464
let strategy = Strategy::from(matches, obs_lines).map_err(SettingsError::Strategy)?;
465465
let suffix = Suffix::from(matches, &strategy).map_err(SettingsError::Suffix)?;
466466

@@ -541,7 +541,7 @@ impl Settings {
541541
));
542542
}
543543

544-
platform::instantiate_current_writer(&self.filter, filename, is_new)
544+
platform::instantiate_current_writer(self.filter.as_deref(), filename, is_new)
545545
}
546546
}
547547

@@ -607,14 +607,14 @@ fn get_input_size<R>(
607607
input: &String,
608608
reader: &mut R,
609609
buf: &mut Vec<u8>,
610-
io_blksize: &Option<u64>,
610+
io_blksize: Option<u64>,
611611
) -> io::Result<u64>
612612
where
613613
R: BufRead,
614614
{
615615
// Set read limit to io_blksize if specified
616616
let read_limit: u64 = if let Some(custom_blksize) = io_blksize {
617-
*custom_blksize
617+
custom_blksize
618618
} else {
619619
// otherwise try to get it from filesystem, or use default
620620
uucore::fs::sane_blksize::sane_blksize_from_path(Path::new(input))
@@ -1084,7 +1084,7 @@ where
10841084
{
10851085
// Get the size of the input in bytes
10861086
let initial_buf = &mut Vec::new();
1087-
let mut num_bytes = get_input_size(&settings.input, reader, initial_buf, &settings.io_blksize)?;
1087+
let mut num_bytes = get_input_size(&settings.input, reader, initial_buf, settings.io_blksize)?;
10881088
let mut reader = initial_buf.chain(reader);
10891089

10901090
// If input file is empty and we would not have determined the Kth chunk
@@ -1230,7 +1230,7 @@ where
12301230
// Get the size of the input in bytes and compute the number
12311231
// of bytes per chunk.
12321232
let initial_buf = &mut Vec::new();
1233-
let num_bytes = get_input_size(&settings.input, reader, initial_buf, &settings.io_blksize)?;
1233+
let num_bytes = get_input_size(&settings.input, reader, initial_buf, settings.io_blksize)?;
12341234
let reader = initial_buf.chain(reader);
12351235

12361236
// If input file is empty and we would not have determined the Kth chunk

src/uu/split/src/strategy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub enum StrategyError {
214214

215215
impl Strategy {
216216
/// Parse a strategy from the command-line arguments.
217-
pub fn from(matches: &ArgMatches, obs_lines: &Option<String>) -> Result<Self, StrategyError> {
217+
pub fn from(matches: &ArgMatches, obs_lines: Option<&str>) -> Result<Self, StrategyError> {
218218
fn get_and_parse(
219219
matches: &ArgMatches,
220220
option: &str,

0 commit comments

Comments
 (0)