From f562a4526c17cba87186fcbfc03b72b28aa2f42e Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Tue, 18 Jan 2022 07:33:28 -0500 Subject: [PATCH] Fix clippy lints (#4262) * Fix clippy lints * Fix clippy lints * Fix clippy lints --- crates/nu-ansi-term/src/lib.rs | 1 - crates/nu-cli/src/cli.rs | 4 ++-- crates/nu-command/src/commands/core_commands/source.rs | 4 ++-- crates/nu-command/src/commands/filters/empty.rs | 2 +- crates/nu-command/src/commands/platform/kill.rs | 2 +- crates/nu-command/src/commands/system/ps.rs | 6 +++--- crates/nu-engine/src/filesystem/filesystem_shell.rs | 2 +- crates/nu-engine/src/script.rs | 2 +- crates/nu-parser/src/parse/source.rs | 4 ++-- crates/nu-test-support/src/playground/director.rs | 2 +- tests/shell/environment/mod.rs | 4 ++-- 11 files changed, 16 insertions(+), 17 deletions(-) diff --git a/crates/nu-ansi-term/src/lib.rs b/crates/nu-ansi-term/src/lib.rs index aa3648da9..d33b9bb52 100644 --- a/crates/nu-ansi-term/src/lib.rs +++ b/crates/nu-ansi-term/src/lib.rs @@ -231,7 +231,6 @@ #![crate_name = "nu_ansi_term"] #![crate_type = "rlib"] -#![crate_type = "dylib"] #![warn(missing_copy_implementations)] // #![warn(missing_docs)] #![warn(trivial_casts, trivial_numeric_casts)] diff --git a/crates/nu-cli/src/cli.rs b/crates/nu-cli/src/cli.rs index 698152227..72f2f4c97 100644 --- a/crates/nu-cli/src/cli.rs +++ b/crates/nu-cli/src/cli.rs @@ -91,10 +91,10 @@ pub fn run_script_file( fn default_prompt_string(cwd: &str) -> String { format!( "{}{}{}{}{}{}> ", - Color::Green.bold().prefix().to_string(), + Color::Green.bold().prefix(), cwd, nu_ansi_term::ansi::RESET, - Color::Cyan.bold().prefix().to_string(), + Color::Cyan.bold().prefix(), current_branch(), nu_ansi_term::ansi::RESET ) diff --git a/crates/nu-command/src/commands/core_commands/source.rs b/crates/nu-command/src/commands/core_commands/source.rs index f77901572..862ef6286 100644 --- a/crates/nu-command/src/commands/core_commands/source.rs +++ b/crates/nu-command/src/commands/core_commands/source.rs @@ -93,7 +93,7 @@ pub fn source(args: CommandArgs) -> Result { let path = canonicalize(source_file).map_err(|e| { ShellError::labeled_error( - format!("Can't load source file. Reason: {}", e.to_string()), + format!("Can't load source file. Reason: {}", e), "Can't load this file", filename.span(), ) @@ -112,7 +112,7 @@ pub fn source(args: CommandArgs) -> Result { } Err(e) => { ctx.error(ShellError::labeled_error( - format!("Can't load source file. Reason: {}", e.to_string()), + format!("Can't load source file. Reason: {}", e), "Can't load this file", filename.span(), )); diff --git a/crates/nu-command/src/commands/filters/empty.rs b/crates/nu-command/src/commands/filters/empty.rs index cad66fc10..c84fdbad6 100644 --- a/crates/nu-command/src/commands/filters/empty.rs +++ b/crates/nu-command/src/commands/filters/empty.rs @@ -197,7 +197,7 @@ fn process_row( } else { let mut obj = input.clone(); - for column in column_paths.clone() { + for column in column_paths { let path = UntaggedValue::Primitive(Primitive::ColumnPath(column.clone())) .into_value(tag); let data = r.get_data(&as_string(&path)?).borrow().clone(); diff --git a/crates/nu-command/src/commands/platform/kill.rs b/crates/nu-command/src/commands/platform/kill.rs index 961abe38e..2f508a1a2 100644 --- a/crates/nu-command/src/commands/platform/kill.rs +++ b/crates/nu-command/src/commands/platform/kill.rs @@ -104,7 +104,7 @@ fn kill(args: CommandArgs) -> Result { } cmd.arg("-9"); } else if let Some(signal_value) = signal { - cmd.arg(format!("-{}", signal_value.item().to_string())); + cmd.arg(format!("-{}", signal_value.item())); } cmd.arg(pid.item().to_string()); diff --git a/crates/nu-command/src/commands/system/ps.rs b/crates/nu-command/src/commands/system/ps.rs index 85dc6400c..aca2c62c5 100644 --- a/crates/nu-command/src/commands/system/ps.rs +++ b/crates/nu-command/src/commands/system/ps.rs @@ -1,7 +1,7 @@ use crate::prelude::*; use nu_errors::ShellError; use nu_protocol::{Signature, TaggedDictBuilder, UntaggedValue}; -use sysinfo::{ProcessExt, System, SystemExt}; +use sysinfo::{PidExt, ProcessExt, System, SystemExt}; pub struct Command; @@ -50,7 +50,7 @@ fn run_ps(args: CommandArgs) -> Result { for pid in result { if let Some(result) = sys.process(pid) { let mut dict = TaggedDictBuilder::new(args.name_tag()); - dict.insert_untagged("pid", UntaggedValue::int(pid as i64)); + dict.insert_untagged("pid", UntaggedValue::int(pid.as_u32() as i64)); dict.insert_untagged("name", UntaggedValue::string(result.name())); dict.insert_untagged( "status", @@ -68,7 +68,7 @@ fn run_ps(args: CommandArgs) -> Result { if long { if let Some(parent) = result.parent() { - dict.insert_untagged("parent", UntaggedValue::int(parent as i64)); + dict.insert_untagged("parent", UntaggedValue::int(parent.as_u32() as i64)); } else { dict.insert_untagged("parent", UntaggedValue::nothing()); } diff --git a/crates/nu-engine/src/filesystem/filesystem_shell.rs b/crates/nu-engine/src/filesystem/filesystem_shell.rs index 1967d99c9..f221553ae 100644 --- a/crates/nu-engine/src/filesystem/filesystem_shell.rs +++ b/crates/nu-engine/src/filesystem/filesystem_shell.rs @@ -970,7 +970,7 @@ fn move_item(from: &Path, from_tag: &Tag, to: &Path) -> Result<(), ShellError> { } { Ok(_) => Ok(()), Err(e) => Err(ShellError::labeled_error( - format!("Could not move {:?} to {:?}. {:}", from, to, e.to_string()), + format!("Could not move {:?} to {:?}. {:}", from, to, e), "could not move", from_tag, )), diff --git a/crates/nu-engine/src/script.rs b/crates/nu-engine/src/script.rs index 796b4e491..fd9c41f0c 100644 --- a/crates/nu-engine/src/script.rs +++ b/crates/nu-engine/src/script.rs @@ -147,7 +147,7 @@ pub fn process_script( { val.to_string() } else { - format!("{}\\", name.to_string()) + format!("{}\\", name) } } else { name.to_string() diff --git a/crates/nu-parser/src/parse/source.rs b/crates/nu-parser/src/parse/source.rs index 0871bf8ab..c39960a0c 100644 --- a/crates/nu-parser/src/parse/source.rs +++ b/crates/nu-parser/src/parse/source.rs @@ -75,7 +75,7 @@ fn find_source_file( let path = canonicalize(&file).map_err(|e| { ParseError::general_error( - format!("Can't load source file. Reason: {}", e.to_string()), + format!("Can't load source file. Reason: {}", e), "Can't load this file".spanned(file_span), ) })?; @@ -85,7 +85,7 @@ fn find_source_file( match contents { Ok(contents) => parse(&contents, 0, scope), Err(e) => Err(ParseError::general_error( - format!("Can't load source file. Reason: {}", e.to_string()), + format!("Can't load source file. Reason: {}", e), "Can't load this file".spanned(file_span), )), } diff --git a/crates/nu-test-support/src/playground/director.rs b/crates/nu-test-support/src/playground/director.rs index 9074338b7..ba8b9922f 100644 --- a/crates/nu-test-support/src/playground/director.rs +++ b/crates/nu-test-support/src/playground/director.rs @@ -97,7 +97,7 @@ impl Executable for Director { .spawn() { Ok(child) => child, - Err(why) => panic!("Can't run test {}", why.to_string()), + Err(why) => panic!("Can't run test {}", why), }; if let Some(pipelines) = &self.pipeline { diff --git a/tests/shell/environment/mod.rs b/tests/shell/environment/mod.rs index 01a0a3657..f505dcbf3 100644 --- a/tests/shell/environment/mod.rs +++ b/tests/shell/environment/mod.rs @@ -12,9 +12,9 @@ pub mod support { pub fn in_path(dirs: &Dirs, block: impl FnOnce() -> Outcome) -> Outcome { let for_env_manifest = dirs.test().to_string_lossy(); - nu!(cwd: dirs.root(), format!("autoenv trust \"{}\"", for_env_manifest.to_string())); + nu!(cwd: dirs.root(), format!("autoenv trust \"{}\"", for_env_manifest)); let out = block(); - nu!(cwd: dirs.root(), format!("autoenv untrust \"{}\"", for_env_manifest.to_string())); + nu!(cwd: dirs.root(), format!("autoenv untrust \"{}\"", for_env_manifest)); out }