mirror of
https://github.com/uutils/coreutils
synced 2024-10-15 12:24:09 +00:00
clippy: fix warnings introduced with Rust 1.78
This commit is contained in:
parent
1c0984911f
commit
19901055a2
|
@ -1120,6 +1120,7 @@ fn parse_path_args(
|
||||||
};
|
};
|
||||||
|
|
||||||
if options.strip_trailing_slashes {
|
if options.strip_trailing_slashes {
|
||||||
|
#[allow(clippy::assigning_clones)]
|
||||||
for source in &mut paths {
|
for source in &mut paths {
|
||||||
*source = source.components().as_path().to_owned();
|
*source = source.components().as_path().to_owned();
|
||||||
}
|
}
|
||||||
|
@ -1617,8 +1618,8 @@ fn handle_existing_dest(
|
||||||
// linking.
|
// linking.
|
||||||
|
|
||||||
if options.preserve_hard_links()
|
if options.preserve_hard_links()
|
||||||
// only try to remove dest file only if the current source
|
// only try to remove dest file only if the current source
|
||||||
// is hardlink to a file that is already copied
|
// is hardlink to a file that is already copied
|
||||||
&& copied_files.contains_key(
|
&& copied_files.contains_key(
|
||||||
&FileInformation::from_path(
|
&FileInformation::from_path(
|
||||||
source,
|
source,
|
||||||
|
@ -1734,7 +1735,7 @@ fn handle_copy_mode(
|
||||||
dest: &Path,
|
dest: &Path,
|
||||||
options: &Options,
|
options: &Options,
|
||||||
context: &str,
|
context: &str,
|
||||||
source_metadata: Metadata,
|
source_metadata: &Metadata,
|
||||||
symlinked_files: &mut HashSet<FileInformation>,
|
symlinked_files: &mut HashSet<FileInformation>,
|
||||||
source_in_command_line: bool,
|
source_in_command_line: bool,
|
||||||
) -> CopyResult<()> {
|
) -> CopyResult<()> {
|
||||||
|
@ -2053,7 +2054,7 @@ fn copy_file(
|
||||||
dest,
|
dest,
|
||||||
options,
|
options,
|
||||||
context,
|
context,
|
||||||
source_metadata,
|
&source_metadata,
|
||||||
symlinked_files,
|
symlinked_files,
|
||||||
source_in_command_line,
|
source_in_command_line,
|
||||||
)?;
|
)?;
|
||||||
|
|
|
@ -86,17 +86,13 @@ impl CsplitOptions {
|
||||||
/// - [`CsplitError::MatchNotFound`] if no line matched a regular expression.
|
/// - [`CsplitError::MatchNotFound`] if no line matched a regular expression.
|
||||||
/// - [`CsplitError::MatchNotFoundOnRepetition`], like previous but after applying the pattern
|
/// - [`CsplitError::MatchNotFoundOnRepetition`], like previous but after applying the pattern
|
||||||
/// more than once.
|
/// more than once.
|
||||||
pub fn csplit<T>(
|
pub fn csplit<T>(options: &CsplitOptions, patterns: &[String], input: T) -> Result<(), CsplitError>
|
||||||
options: &CsplitOptions,
|
|
||||||
patterns: Vec<String>,
|
|
||||||
input: T,
|
|
||||||
) -> Result<(), CsplitError>
|
|
||||||
where
|
where
|
||||||
T: BufRead,
|
T: BufRead,
|
||||||
{
|
{
|
||||||
let mut input_iter = InputSplitter::new(input.lines().enumerate());
|
let mut input_iter = InputSplitter::new(input.lines().enumerate());
|
||||||
let mut split_writer = SplitWriter::new(options);
|
let mut split_writer = SplitWriter::new(options);
|
||||||
let patterns: Vec<patterns::Pattern> = patterns::get_patterns(&patterns[..])?;
|
let patterns: Vec<patterns::Pattern> = patterns::get_patterns(patterns)?;
|
||||||
let ret = do_csplit(&mut split_writer, patterns, &mut input_iter);
|
let ret = do_csplit(&mut split_writer, patterns, &mut input_iter);
|
||||||
|
|
||||||
// consume the rest, unless there was an error
|
// consume the rest, unless there was an error
|
||||||
|
@ -568,7 +564,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let options = CsplitOptions::new(&matches);
|
let options = CsplitOptions::new(&matches);
|
||||||
if file_name == "-" {
|
if file_name == "-" {
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
Ok(csplit(&options, patterns, stdin.lock())?)
|
Ok(csplit(&options, &patterns, stdin.lock())?)
|
||||||
} else {
|
} else {
|
||||||
let file = File::open(file_name)
|
let file = File::open(file_name)
|
||||||
.map_err_context(|| format!("cannot access {}", file_name.quote()))?;
|
.map_err_context(|| format!("cannot access {}", file_name.quote()))?;
|
||||||
|
@ -578,7 +574,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
if !file_metadata.is_file() {
|
if !file_metadata.is_file() {
|
||||||
return Err(CsplitError::NotRegularFile(file_name.to_string()).into());
|
return Err(CsplitError::NotRegularFile(file_name.to_string()).into());
|
||||||
}
|
}
|
||||||
Ok(csplit(&options, patterns, BufReader::new(file))?)
|
Ok(csplit(&options, &patterns, BufReader::new(file))?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,14 +25,14 @@ pub enum Pattern {
|
||||||
SkipToMatch(Regex, i32, ExecutePattern),
|
SkipToMatch(Regex, i32, ExecutePattern),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for Pattern {
|
impl std::fmt::Display for Pattern {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::UpToLine(n, _) => n.to_string(),
|
Self::UpToLine(n, _) => write!(f, "{n}"),
|
||||||
Self::UpToMatch(regex, 0, _) => format!("/{}/", regex.as_str()),
|
Self::UpToMatch(regex, 0, _) => write!(f, "/{}/", regex.as_str()),
|
||||||
Self::UpToMatch(regex, offset, _) => format!("/{}/{:+}", regex.as_str(), offset),
|
Self::UpToMatch(regex, offset, _) => write!(f, "/{}/{:+}", regex.as_str(), offset),
|
||||||
Self::SkipToMatch(regex, 0, _) => format!("%{}%", regex.as_str()),
|
Self::SkipToMatch(regex, 0, _) => write!(f, "%{}%", regex.as_str()),
|
||||||
Self::SkipToMatch(regex, offset, _) => format!("%{}%{:+}", regex.as_str(), offset),
|
Self::SkipToMatch(regex, offset, _) => write!(f, "%{}%{:+}", regex.as_str(), offset),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,6 +220,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::assigning_clones)]
|
||||||
fn test_dev_name_match() {
|
fn test_dev_name_match() {
|
||||||
let tmp = tempfile::TempDir::new().expect("Failed to create temp dir");
|
let tmp = tempfile::TempDir::new().expect("Failed to create temp dir");
|
||||||
let dev_name = std::fs::canonicalize(tmp.path())
|
let dev_name = std::fs::canonicalize(tmp.path())
|
||||||
|
|
6
src/uu/env/src/env.rs
vendored
6
src/uu/env/src/env.rs
vendored
|
@ -104,7 +104,7 @@ fn load_config_file(opts: &mut Options) -> UResult<()> {
|
||||||
|
|
||||||
for (_, prop) in &conf {
|
for (_, prop) in &conf {
|
||||||
// ignore all INI section lines (treat them as comments)
|
// ignore all INI section lines (treat them as comments)
|
||||||
for (key, value) in prop.iter() {
|
for (key, value) in prop {
|
||||||
env::set_var(key, value);
|
env::set_var(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -371,7 +371,7 @@ impl EnvAppData {
|
||||||
// no program provided, so just dump all env vars to stdout
|
// no program provided, so just dump all env vars to stdout
|
||||||
print_env(opts.line_ending);
|
print_env(opts.line_ending);
|
||||||
} else {
|
} else {
|
||||||
return self.run_program(opts, self.do_debug_printing);
|
return self.run_program(&opts, self.do_debug_printing);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -379,7 +379,7 @@ impl EnvAppData {
|
||||||
|
|
||||||
fn run_program(
|
fn run_program(
|
||||||
&mut self,
|
&mut self,
|
||||||
opts: Options<'_>,
|
opts: &Options<'_>,
|
||||||
do_debug_printing: bool,
|
do_debug_printing: bool,
|
||||||
) -> Result<(), Box<dyn UError>> {
|
) -> Result<(), Box<dyn UError>> {
|
||||||
let prog = Cow::from(opts.program[0]);
|
let prog = Cow::from(opts.program[0]);
|
||||||
|
|
|
@ -51,14 +51,14 @@ fn print_factors_str(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
write_result(w, x, factorization, print_exponents).map_err_context(|| "write error".into())?;
|
write_result(w, &x, factorization, print_exponents).map_err_context(|| "write error".into())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_result(
|
fn write_result(
|
||||||
w: &mut io::BufWriter<impl Write>,
|
w: &mut io::BufWriter<impl Write>,
|
||||||
x: BigUint,
|
x: &BigUint,
|
||||||
factorization: BTreeMap<BigUint, usize>,
|
factorization: BTreeMap<BigUint, usize>,
|
||||||
print_exponents: bool,
|
print_exponents: bool,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
|
|
|
@ -831,27 +831,27 @@ where
|
||||||
if !options.status && !skip_summary {
|
if !options.status && !skip_summary {
|
||||||
match bad_format.cmp(&1) {
|
match bad_format.cmp(&1) {
|
||||||
Ordering::Equal => {
|
Ordering::Equal => {
|
||||||
show_warning_caps!("{} line is improperly formatted", bad_format)
|
show_warning_caps!("{} line is improperly formatted", bad_format);
|
||||||
}
|
}
|
||||||
Ordering::Greater => {
|
Ordering::Greater => {
|
||||||
show_warning_caps!("{} lines are improperly formatted", bad_format)
|
show_warning_caps!("{} lines are improperly formatted", bad_format);
|
||||||
}
|
}
|
||||||
Ordering::Less => {}
|
Ordering::Less => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
match failed_cksum.cmp(&1) {
|
match failed_cksum.cmp(&1) {
|
||||||
Ordering::Equal => {
|
Ordering::Equal => {
|
||||||
show_warning_caps!("{} computed checksum did NOT match", failed_cksum)
|
show_warning_caps!("{} computed checksum did NOT match", failed_cksum);
|
||||||
}
|
}
|
||||||
Ordering::Greater => {
|
Ordering::Greater => {
|
||||||
show_warning_caps!("{} computed checksums did NOT match", failed_cksum)
|
show_warning_caps!("{} computed checksums did NOT match", failed_cksum);
|
||||||
}
|
}
|
||||||
Ordering::Less => {}
|
Ordering::Less => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
match failed_open_file.cmp(&1) {
|
match failed_open_file.cmp(&1) {
|
||||||
Ordering::Equal => {
|
Ordering::Equal => {
|
||||||
show_warning_caps!("{} listed file could not be read", failed_open_file)
|
show_warning_caps!("{} listed file could not be read", failed_open_file);
|
||||||
}
|
}
|
||||||
Ordering::Greater => {
|
Ordering::Greater => {
|
||||||
show_warning_caps!("{} listed files could not be read", failed_open_file);
|
show_warning_caps!("{} listed files could not be read", failed_open_file);
|
||||||
|
|
|
@ -193,7 +193,7 @@ fn list(signals: &Vec<String>) {
|
||||||
} else {
|
} else {
|
||||||
for signal in signals {
|
for signal in signals {
|
||||||
if let Err(e) = print_signal(signal) {
|
if let Err(e) = print_signal(signal) {
|
||||||
uucore::show!(e)
|
uucore::show!(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub fn parse_options(settings: &mut crate::Settings, opts: &clap::ArgMatches) ->
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if let Some(val) = opts.get_one::<String>(options::NUMBER_SEPARATOR) {
|
if let Some(val) = opts.get_one::<String>(options::NUMBER_SEPARATOR) {
|
||||||
settings.number_separator = val.clone();
|
settings.number_separator.clone_from(val);
|
||||||
}
|
}
|
||||||
settings.number_format = opts
|
settings.number_format = opts
|
||||||
.get_one::<String>(options::NUMBER_FORMAT)
|
.get_one::<String>(options::NUMBER_FORMAT)
|
||||||
|
|
|
@ -223,7 +223,7 @@ fn get_config(matches: &clap::ArgMatches) -> UResult<Config> {
|
||||||
if matches.get_flag(options::TRADITIONAL) {
|
if matches.get_flag(options::TRADITIONAL) {
|
||||||
config.gnu_ext = false;
|
config.gnu_ext = false;
|
||||||
config.format = OutFormat::Roff;
|
config.format = OutFormat::Roff;
|
||||||
config.context_regex = "[^ \t\n]+".to_owned();
|
"[^ \t\n]+".clone_into(&mut config.context_regex);
|
||||||
} else {
|
} else {
|
||||||
return Err(PtxError::NotImplemented("GNU extensions").into());
|
return Err(PtxError::NotImplemented("GNU extensions").into());
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ impl WatcherRx {
|
||||||
Tested for notify::InotifyWatcher and for notify::PollWatcher.
|
Tested for notify::InotifyWatcher and for notify::PollWatcher.
|
||||||
*/
|
*/
|
||||||
if let Some(parent) = path.parent() {
|
if let Some(parent) = path.parent() {
|
||||||
|
#[allow(clippy::assigning_clones)]
|
||||||
if parent.is_dir() {
|
if parent.is_dir() {
|
||||||
path = parent.to_owned();
|
path = parent.to_owned();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue