diff --git a/crates/nu-cli/src/completions/command_completions.rs b/crates/nu-cli/src/completions/command_completions.rs index 468708ad50..1f49718db4 100644 --- a/crates/nu-cli/src/completions/command_completions.rs +++ b/crates/nu-cli/src/completions/command_completions.rs @@ -60,7 +60,7 @@ impl CommandCompletion { .matches_str(&x.to_string_lossy(), prefix)), Some(true) ) - && is_executable::is_executable(&item.path()) + && is_executable::is_executable(item.path()) { if let Ok(name) = item.file_name().into_string() { executables.push(name); diff --git a/crates/nu-cli/src/config_files.rs b/crates/nu-cli/src/config_files.rs index 3767228428..9e72d2232d 100644 --- a/crates/nu-cli/src/config_files.rs +++ b/crates/nu-cli/src/config_files.rs @@ -30,7 +30,7 @@ pub fn read_plugin_file( let plugin_path = engine_state.plugin_signatures.clone(); if let Some(plugin_path) = plugin_path { - let plugin_filename = plugin_path.to_string_lossy().to_owned(); + let plugin_filename = plugin_path.to_string_lossy(); if let Ok(contents) = std::fs::read(&plugin_path) { eval_source( @@ -77,7 +77,7 @@ pub fn eval_config_contents( stack: &mut Stack, ) { if config_path.exists() & config_path.is_file() { - let config_filename = config_path.to_string_lossy().to_owned(); + let config_filename = config_path.to_string_lossy(); if let Ok(contents) = std::fs::read(&config_path) { eval_source( diff --git a/crates/nu-cli/src/menus/description_menu.rs b/crates/nu-cli/src/menus/description_menu.rs index ceec536a69..e841735919 100644 --- a/crates/nu-cli/src/menus/description_menu.rs +++ b/crates/nu-cli/src/menus/description_menu.rs @@ -372,7 +372,7 @@ impl DescriptionMenu { let description = self .get_value() .and_then(|suggestion| suggestion.description) - .unwrap_or_else(|| "".to_string()) + .unwrap_or_default() .lines() .skip(self.skipped_rows) .take(self.working_details.description_rows) @@ -610,7 +610,7 @@ impl Menu for DescriptionMenu { let description_rows = self .get_value() .and_then(|suggestion| suggestion.description) - .unwrap_or_else(|| "".to_string()) + .unwrap_or_default() .lines() .count(); diff --git a/crates/nu-cli/src/reedline_config.rs b/crates/nu-cli/src/reedline_config.rs index 89949e3bf2..44d292770d 100644 --- a/crates/nu-cli/src/reedline_config.rs +++ b/crates/nu-cli/src/reedline_config.rs @@ -114,7 +114,7 @@ pub(crate) fn add_menus( let res = eval_block(&engine_state, &mut temp_stack, &block, input, false, false)?; if let PipelineData::Value(value, None) = res { - for menu in create_menus(&value, config)? { + for menu in create_menus(&value)? { line_editor = add_menu(line_editor, &menu, engine_state.clone(), stack, config)?; } diff --git a/crates/nu-command/src/conversions/into/binary.rs b/crates/nu-command/src/conversions/into/binary.rs index 06401c1122..0b23968cf8 100644 --- a/crates/nu-command/src/conversions/into/binary.rs +++ b/crates/nu-command/src/conversions/into/binary.rs @@ -164,7 +164,7 @@ pub fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value { span, }, Value::Bool { val, .. } => Value::Binary { - val: int_to_endian(if *val { 1i64 } else { 0 }), + val: int_to_endian(i64::from(*val)), span, }, Value::Date { val, .. } => Value::Binary { diff --git a/crates/nu-command/src/filesystem/ls.rs b/crates/nu-command/src/filesystem/ls.rs index 0714a03ef0..c29a4b9a69 100644 --- a/crates/nu-command/src/filesystem/ls.rs +++ b/crates/nu-command/src/filesystem/ls.rs @@ -198,7 +198,7 @@ impl Command for Ls { } else if full_paths || absolute_path { Some(path.to_string_lossy().to_string()) } else if let Some(prefix) = &prefix { - if let Ok(remainder) = path.strip_prefix(&prefix) { + if let Ok(remainder) = path.strip_prefix(prefix) { if directory { // When the path is the same as the cwd, path_diff should be "." let path_diff = @@ -215,7 +215,7 @@ impl Command for Ls { Some(path_diff) } else { - let new_prefix = if let Some(pfx) = diff_paths(&prefix, &cwd) { + let new_prefix = if let Some(pfx) = diff_paths(prefix, &cwd) { pfx } else { prefix.to_path_buf() diff --git a/crates/nu-command/src/filesystem/mv.rs b/crates/nu-command/src/filesystem/mv.rs index b64c887068..cc0f74ba12 100644 --- a/crates/nu-command/src/filesystem/mv.rs +++ b/crates/nu-command/src/filesystem/mv.rs @@ -295,7 +295,7 @@ fn move_file( fn move_item(from: &Path, from_span: Span, to: &Path) -> Result<(), ShellError> { // We first try a rename, which is a quick operation. If that doesn't work, we'll try a copy // and remove the old file/folder. This is necessary if we're moving across filesystems or devices. - std::fs::rename(&from, &to).or_else(|_| { + std::fs::rename(from, to).or_else(|_| { match if from.is_file() { let mut options = fs_extra::file::CopyOptions::new(); options.overwrite = true; diff --git a/crates/nu-command/src/filesystem/open.rs b/crates/nu-command/src/filesystem/open.rs index f1f9b036b7..2bfb289164 100644 --- a/crates/nu-command/src/filesystem/open.rs +++ b/crates/nu-command/src/filesystem/open.rs @@ -97,7 +97,7 @@ impl Command for Open { let path_no_whitespace = &path.item.trim_end_matches(|x| matches!(x, '\x09'..='\x0d')); let path = Path::new(path_no_whitespace); - if permission_denied(&path) { + if permission_denied(path) { #[cfg(unix)] let error_msg = match path.metadata() { Ok(md) => format!( diff --git a/crates/nu-command/src/filesystem/rm.rs b/crates/nu-command/src/filesystem/rm.rs index 9e6be3587c..b0b422b92d 100644 --- a/crates/nu-command/src/filesystem/rm.rs +++ b/crates/nu-command/src/filesystem/rm.rs @@ -284,8 +284,8 @@ fn rm( } Ok(all_targets - .into_iter() - .map(move |(f, _)| { + .into_keys() + .map(move |f| { let is_empty = || match f.read_dir() { Ok(mut p) => p.next().is_none(), Err(_) => false, diff --git a/crates/nu-command/src/filesystem/watch.rs b/crates/nu-command/src/filesystem/watch.rs index 46b654375c..e6162ee373 100644 --- a/crates/nu-command/src/filesystem/watch.rs +++ b/crates/nu-command/src/filesystem/watch.rs @@ -72,7 +72,7 @@ impl Command for Watch { .item .trim_end_matches(|x| matches!(x, '\x09'..='\x0d')); - let path = match nu_path::canonicalize_with(path_no_whitespace, &cwd) { + let path = match nu_path::canonicalize_with(path_no_whitespace, cwd) { Ok(p) => p, Err(e) => { return Err(ShellError::DirectoryNotFound( diff --git a/crates/nu-command/src/filters/group_by.rs b/crates/nu-command/src/filters/group_by.rs index ef69520d93..7e938329e6 100644 --- a/crates/nu-command/src/filters/group_by.rs +++ b/crates/nu-command/src/filters/group_by.rs @@ -210,7 +210,7 @@ pub fn data_group( value.as_string() }; - let group = groups.entry(group_key?).or_insert(vec![]); + let group = groups.entry(group_key?).or_default(); group.push(value); } diff --git a/crates/nu-command/src/formats/from/ssv.rs b/crates/nu-command/src/formats/from/ssv.rs index e6a917371a..3efa0873f0 100644 --- a/crates/nu-command/src/formats/from/ssv.rs +++ b/crates/nu-command/src/formats/from/ssv.rs @@ -141,7 +141,7 @@ fn parse_aligned_columns<'a>( let parse_without_headers = |ls: Vec<&str>| { let mut indices = ls .iter() - .flat_map(|s| find_indices(*s)) + .flat_map(|s| find_indices(s)) .collect::>(); indices.sort_unstable(); diff --git a/crates/nu-command/src/generators/seq.rs b/crates/nu-command/src/generators/seq.rs index ff0c309ea8..3ec9c15f57 100644 --- a/crates/nu-command/src/generators/seq.rs +++ b/crates/nu-command/src/generators/seq.rs @@ -284,9 +284,7 @@ pub fn run_seq( } } }; - if largest_dec > 0 { - largest_dec -= 1; - } + largest_dec = largest_dec.saturating_sub(1); let separator = escape_sequences(&sep[..]); let terminator = match termy { Some(term) => escape_sequences(&term[..]), diff --git a/crates/nu-command/src/math/median.rs b/crates/nu-command/src/math/median.rs index 034449bb81..a9dfebe4ab 100644 --- a/crates/nu-command/src/math/median.rs +++ b/crates/nu-command/src/math/median.rs @@ -96,7 +96,7 @@ pub fn median(values: &[Value], head: &Span) -> Result { Ok(out.clone()) } Pick::MedianAverage => { - let idx_end = (values.len() / 2) as usize; + let idx_end = values.len() / 2; let idx_start = idx_end - 1; let left = sorted diff --git a/crates/nu-command/src/network/fetch.rs b/crates/nu-command/src/network/fetch.rs index b0420e1724..994f094ab4 100644 --- a/crates/nu-command/src/network/fetch.rs +++ b/crates/nu-command/src/network/fetch.rs @@ -376,8 +376,8 @@ fn helper( let headers = args.headers; let raw = args.raw; let login = match (user, password) { - (Some(user), Some(password)) => Some(encode(&format!("{}:{}", user, password))), - (Some(user), _) => Some(encode(&format!("{}:", user))), + (Some(user), Some(password)) => Some(encode(format!("{}:{}", user, password))), + (Some(user), _) => Some(encode(format!("{}:", user))), _ => None, }; diff --git a/crates/nu-command/src/strings/encode_decode/base64.rs b/crates/nu-command/src/strings/encode_decode/base64.rs index c288cbf631..7aaf5207bb 100644 --- a/crates/nu-command/src/strings/encode_decode/base64.rs +++ b/crates/nu-command/src/strings/encode_decode/base64.rs @@ -115,7 +115,7 @@ fn action( } => { match base64_config.action_type { ActionType::Encode => { - Value::string(encode_config(&val, base64_config_enum), command_span) + Value::string(encode_config(val, base64_config_enum), command_span) } ActionType::Decode => { diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index f704e6e7d5..f91c139be2 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -548,7 +548,7 @@ impl ExternalCommand { .to_string_lossy() .to_string(); - let mut process = std::process::Command::new(&head); + let mut process = std::process::Command::new(head); for (arg, arg_keep_raw) in self.args.iter().zip(self.arg_keep_raw.iter()) { // if arg is quoted, like "aa", 'aa', `aa`, or: diff --git a/crates/nu-command/tests/commands/ls.rs b/crates/nu-command/tests/commands/ls.rs index c57a2d899a..4a8c3f8784 100644 --- a/crates/nu-command/tests/commands/ls.rs +++ b/crates/nu-command/tests/commands/ls.rs @@ -529,7 +529,7 @@ fn list_directory_contains_invalid_utf8() { let cwd = dirs.test(); let path = cwd.join(s); - std::fs::create_dir_all(&path).expect("failed to create directory"); + std::fs::create_dir_all(path).expect("failed to create directory"); let actual = nu!(cwd: cwd, "ls"); diff --git a/crates/nu-engine/src/env.rs b/crates/nu-engine/src/env.rs index 336828593c..d1e319cb60 100644 --- a/crates/nu-engine/src/env.rs +++ b/crates/nu-engine/src/env.rs @@ -279,7 +279,7 @@ pub fn find_in_dirs_env( for lib_dir in dirs { if let Ok(dir) = lib_dir.as_path() { // make sure the dir is absolute path - if let Ok(dir_abs) = canonicalize_with(&dir, &cwd) { + if let Ok(dir_abs) = canonicalize_with(dir, &cwd) { if let Ok(path) = canonicalize_with(filename, dir_abs) { return Ok(Some(path)); } diff --git a/crates/nu-engine/src/glob_from.rs b/crates/nu-engine/src/glob_from.rs index 4cd744f99d..6aaf5b17bf 100644 --- a/crates/nu-engine/src/glob_from.rs +++ b/crates/nu-engine/src/glob_from.rs @@ -41,7 +41,7 @@ pub fn glob_from( } (Some(p), path) } else { - let path = if let Ok(p) = canonicalize_with(path, &cwd) { + let path = if let Ok(p) = canonicalize_with(path, cwd) { p } else { return Err(ShellError::DirectoryNotFound(pattern.span, None)); diff --git a/crates/nu-glob/src/lib.rs b/crates/nu-glob/src/lib.rs index 4138946fbd..1da5879d98 100644 --- a/crates/nu-glob/src/lib.rs +++ b/crates/nu-glob/src/lib.rs @@ -335,7 +335,7 @@ impl Iterator for Paths { if let Some(scope) = self.scope.take() { if !self.dir_patterns.is_empty() { // Shouldn't happen, but we're using -1 as a special index. - assert!(self.dir_patterns.len() < !0 as usize); + assert!(self.dir_patterns.len() < !0); fill_todo(&mut self.todo, &self.dir_patterns, 0, &scope, self.options); } @@ -357,7 +357,7 @@ impl Iterator for Paths { // idx -1: was already checked by fill_todo, maybe path was '.' or // '..' that we can't match here because of normalization. - if idx == !0 as usize { + if idx == !0 { if self.require_dir && !is_dir(&path) { continue; } @@ -771,7 +771,7 @@ fn fill_todo( // We know it's good, so don't make the iterator match this path // against the pattern again. In particular, it can't match // . or .. globs since these never show up as path components. - todo.push(Ok((next_path, !0 as usize))); + todo.push(Ok((next_path, !0))); } else { fill_todo(todo, patterns, idx + 1, &next_path, options); } @@ -1222,7 +1222,7 @@ mod test { #[test] fn test_path_join() { - let pattern = Path::new("one").join(&Path::new("**/*.rs")); + let pattern = Path::new("one").join(Path::new("**/*.rs")); assert!(Pattern::new(pattern.to_str().unwrap()).is_ok()); } } diff --git a/crates/nu-json/src/de.rs b/crates/nu-json/src/de.rs index a462a408fb..198ccd7635 100644 --- a/crates/nu-json/src/de.rs +++ b/crates/nu-json/src/de.rs @@ -469,7 +469,7 @@ where let n = (((n1 - 0xD800) as u32) << 10 | (n2 - 0xDC00) as u32) + 0x1_0000; - match char::from_u32(n as u32) { + match char::from_u32(n) { Some(c) => c, None => { return Err(self diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index 27829d1380..57d31ebf19 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -3252,7 +3252,7 @@ pub fn find_in_dirs( for lib_dir in dirs { if let Ok(dir) = lib_dir.as_path() { // make sure the dir is absolute path - if let Ok(dir_abs) = canonicalize_with(&dir, actual_cwd) { + if let Ok(dir_abs) = canonicalize_with(dir, actual_cwd) { if let Ok(path) = canonicalize_with(filename, dir_abs) { return Some(path); } diff --git a/crates/nu-path/src/tilde.rs b/crates/nu-path/src/tilde.rs index 35201e9c58..f2379ae5ac 100644 --- a/crates/nu-path/src/tilde.rs +++ b/crates/nu-path/src/tilde.rs @@ -157,7 +157,7 @@ mod tests { fn check_expanded(s: &str) { let home = Path::new("/home"); let buf = Some(PathBuf::from(home)); - assert!(expand_tilde_with_home(Path::new(s), buf).starts_with(&home)); + assert!(expand_tilde_with_home(Path::new(s), buf).starts_with(home)); // Tests the special case in expand_tilde for "/" as home let home = Path::new("/"); diff --git a/crates/nu-pretty-hex/src/pretty_hex.rs b/crates/nu-pretty-hex/src/pretty_hex.rs index b3066c0b92..b3fac48cc2 100644 --- a/crates/nu-pretty-hex/src/pretty_hex.rs +++ b/crates/nu-pretty-hex/src/pretty_hex.rs @@ -174,7 +174,7 @@ where .iter() .skip(skip) .take(amount) - .map(|&x| x as u8) + .copied() .collect(); if cfg.title { diff --git a/crates/nu-protocol/src/config.rs b/crates/nu-protocol/src/config.rs index 45a2456597..fc7d927d66 100644 --- a/crates/nu-protocol/src/config.rs +++ b/crates/nu-protocol/src/config.rs @@ -347,14 +347,14 @@ impl Value { eprintln!("$config.log_level is not a string") } } - "menus" => match create_menus(value, &config) { + "menus" => match create_menus(value) { Ok(map) => config.menus = map, Err(e) => { eprintln!("$config.menus is not a valid list of menus"); eprintln!("{:?}", e); } }, - "keybindings" => match create_keybindings(value, &config) { + "keybindings" => match create_keybindings(value) { Ok(keybindings) => config.keybindings = keybindings, Err(e) => { eprintln!("$config.keybindings is not a valid keybindings list"); @@ -599,7 +599,7 @@ fn create_hooks(value: &Value) -> Result { } // Parses the config object to extract the strings that will compose a keybinding for reedline -fn create_keybindings(value: &Value, config: &Config) -> Result, ShellError> { +fn create_keybindings(value: &Value) -> Result, ShellError> { match value { Value::Record { cols, vals, span } => { // Finding the modifier value in the record @@ -621,7 +621,7 @@ fn create_keybindings(value: &Value, config: &Config) -> Result { let res = vals .iter() - .map(|inner_value| create_keybindings(inner_value, config)) + .map(create_keybindings) .collect::>, ShellError>>(); let res = res? @@ -636,7 +636,7 @@ fn create_keybindings(value: &Value, config: &Config) -> Result Result, ShellError> { +pub fn create_menus(value: &Value) -> Result, ShellError> { match value { Value::Record { cols, vals, span } => { // Finding the modifier value in the record @@ -667,7 +667,7 @@ pub fn create_menus(value: &Value, config: &Config) -> Result, S Value::List { vals, .. } => { let res = vals .iter() - .map(|inner_value| create_menus(inner_value, config)) + .map(create_menus) .collect::>, ShellError>>(); let res = res?.into_iter().flatten().collect::>(); diff --git a/crates/nu-protocol/src/value/from_value.rs b/crates/nu-protocol/src/value/from_value.rs index 69ebe46af4..f5a792da9b 100644 --- a/crates/nu-protocol/src/value/from_value.rs +++ b/crates/nu-protocol/src/value/from_value.rs @@ -25,11 +25,11 @@ impl FromValue for Spanned { span: *span, }), Value::Filesize { val, span } => Ok(Spanned { - item: *val as i64, + item: *val, span: *span, }), Value::Duration { val, span } => Ok(Spanned { - item: *val as i64, + item: *val, span: *span, }), @@ -47,8 +47,8 @@ impl FromValue for i64 { fn from_value(v: &Value) -> Result { match v { Value::Int { val, .. } => Ok(*val), - Value::Filesize { val, .. } => Ok(*val as i64), - Value::Duration { val, .. } => Ok(*val as i64), + Value::Filesize { val, .. } => Ok(*val), + Value::Duration { val, .. } => Ok(*val), v => Err(ShellError::CantConvert( "integer".into(), diff --git a/crates/nu-system/src/linux.rs b/crates/nu-system/src/linux.rs index b04b1c006b..28f010dd17 100644 --- a/crates/nu-system/src/linux.rs +++ b/crates/nu-system/src/linux.rs @@ -157,7 +157,7 @@ impl ProcessInfo { pub fn command(&self) -> String { if let Ok(cmd) = &self.curr_proc.cmdline() { if !cmd.is_empty() { - cmd.join(" ").replace('\n', " ").replace('\t', " ") + cmd.join(" ").replace(['\n', '\t'], " ") } else { match self.curr_proc.stat() { Ok(p) => p.comm, @@ -200,8 +200,8 @@ impl ProcessInfo { let curr_time = cs.utime + cs.stime; let prev_time = ps.utime + ps.stime; - let usage_ms = (curr_time - prev_time) * 1000 - / procfs::ticks_per_second().unwrap_or(100) as u64; + let usage_ms = + (curr_time - prev_time) * 1000 / procfs::ticks_per_second().unwrap_or(100); let interval_ms = self.interval.as_secs() * 1000 + u64::from(self.interval.subsec_millis()); usage_ms as f64 * 100.0 / interval_ms as f64 diff --git a/crates/nu-table/src/table.rs b/crates/nu-table/src/table.rs index cb21713d31..566e1ef4c7 100644 --- a/crates/nu-table/src/table.rs +++ b/crates/nu-table/src/table.rs @@ -230,7 +230,7 @@ fn override_alignments( index_present: bool, alignments: Alignments, ) { - let offset = if header_present { 1 } else { 0 }; + let offset = usize::from(header_present); let (count_rows, count_columns) = table.shape(); for row in offset..count_rows { for col in 0..count_columns { diff --git a/crates/nu-term-grid/src/grid.rs b/crates/nu-term-grid/src/grid.rs index f4a624bc9c..064a00bfa7 100644 --- a/crates/nu-term-grid/src/grid.rs +++ b/crates/nu-term-grid/src/grid.rs @@ -131,7 +131,7 @@ pub struct Cell { impl From for Cell { fn from(string: String) -> Self { Self { - width: unicode_width_strip_ansi(&*string), + width: unicode_width_strip_ansi(&string), contents: string, alignment: Alignment::Left, } diff --git a/crates/nu-test-support/src/playground/nu_process.rs b/crates/nu-test-support/src/playground/nu_process.rs index ffb3271ac4..401dbd4498 100644 --- a/crates/nu-test-support/src/playground/nu_process.rs +++ b/crates/nu-test-support/src/playground/nu_process.rs @@ -74,7 +74,7 @@ impl NuProcess { } pub fn construct(&self) -> Command { - let mut command = Command::new(&executable_path()); + let mut command = Command::new(executable_path()); if let Some(cwd) = self.get_cwd() { command.current_dir(cwd); @@ -84,7 +84,7 @@ impl NuProcess { let paths = vec![test_bins_path()]; - let paths_joined = match std::env::join_paths(&paths) { + let paths_joined = match std::env::join_paths(paths) { Ok(all) => all, Err(_) => panic!("Couldn't join paths for PATH var."), }; diff --git a/tests/path/expand_path.rs b/tests/path/expand_path.rs index 24f4eeea9d..799c7769ab 100644 --- a/tests/path/expand_path.rs +++ b/tests/path/expand_path.rs @@ -32,7 +32,7 @@ fn expand_path_no_change() { let path = "/foo/bar"; let cwd = std::env::current_dir().expect("Could not get current directory"); - let actual = expand_path_with(&path, cwd); + let actual = expand_path_with(path, cwd); assert_eq!(actual, PathBuf::from(path)); }