From f7647584a3efa14797c37cbfc75cb802ec6bd323 Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Mon, 26 Sep 2022 19:29:25 +0200 Subject: [PATCH] Clippy with the current stable toolchain (#6615) Fix lints that are coming with rust 1.64 Passes with the earlier toolchain from `rust-toolchain.toml` as well. --- crates/nu-cli/src/completions/completer.rs | 2 +- crates/nu-cli/src/repl.rs | 4 +--- crates/nu-cli/tests/support/completions_helpers.rs | 4 +--- crates/nu-command/src/charting/histogram.rs | 4 ++-- crates/nu-command/src/env/with_env.rs | 2 +- crates/nu-command/src/filesystem/mv.rs | 5 +---- crates/nu-command/src/formats/to/md.rs | 2 +- crates/nu-command/src/network/fetch.rs | 2 +- crates/nu-command/src/network/post.rs | 2 +- crates/nu-command/src/viewers/table.rs | 7 ++----- crates/nu-glob/src/lib.rs | 4 +--- 11 files changed, 13 insertions(+), 25 deletions(-) diff --git a/crates/nu-cli/src/completions/completer.rs b/crates/nu-cli/src/completions/completer.rs index c1625c8c1..5aadca2ca 100644 --- a/crates/nu-cli/src/completions/completer.rs +++ b/crates/nu-cli/src/completions/completer.rs @@ -422,7 +422,7 @@ fn search_alias(input: &[u8], working_set: &StateWorkingSet) -> Option PipelineData::Value(input, None), diff --git a/crates/nu-cli/tests/support/completions_helpers.rs b/crates/nu-cli/tests/support/completions_helpers.rs index f774dd3f1..e1c8fd51e 100644 --- a/crates/nu-cli/tests/support/completions_helpers.rs +++ b/crates/nu-cli/tests/support/completions_helpers.rs @@ -104,9 +104,7 @@ pub fn merge_input( (block, working_set.render()) }; - if let Err(err) = engine_state.merge_delta(delta) { - return Err(err); - } + engine_state.merge_delta(delta)?; assert!(eval_block( engine_state, diff --git a/crates/nu-command/src/charting/histogram.rs b/crates/nu-command/src/charting/histogram.rs index b6161ec56..eba15dae1 100644 --- a/crates/nu-command/src/charting/histogram.rs +++ b/crates/nu-command/src/charting/histogram.rs @@ -215,8 +215,8 @@ fn histogram_impl( const MAX_FREQ_COUNT: f64 = 100.0; for (val, count) in counter.into_iter() { let quantile = match calc_method { - PercentageCalcMethod::Normalize => (count as f64 / total_cnt as f64), - PercentageCalcMethod::Relative => (count as f64 / max_cnt as f64), + PercentageCalcMethod::Normalize => count as f64 / total_cnt as f64, + PercentageCalcMethod::Relative => count as f64 / max_cnt as f64, }; let percentage = format!("{:.2}%", quantile * 100_f64); diff --git a/crates/nu-command/src/env/with_env.rs b/crates/nu-command/src/env/with_env.rs index a23adae9c..12f4494b4 100644 --- a/crates/nu-command/src/env/with_env.rs +++ b/crates/nu-command/src/env/with_env.rs @@ -110,7 +110,7 @@ fn with_env( // primitive values([X Y W Z]) for row in table.chunks(2) { if row.len() == 2 { - env.insert(row[0].as_string()?, (&row[1]).clone()); + env.insert(row[0].as_string()?, row[1].clone()); } // TODO: else error? } diff --git a/crates/nu-command/src/filesystem/mv.rs b/crates/nu-command/src/filesystem/mv.rs index 8cec348c6..5a7987622 100644 --- a/crates/nu-command/src/filesystem/mv.rs +++ b/crates/nu-command/src/filesystem/mv.rs @@ -154,10 +154,7 @@ impl Command for Mv { } if let Some(Ok(_filename)) = some_if_source_is_destination { - sources = sources - .into_iter() - .filter(|f| matches!(f, Ok(f) if !destination.starts_with(f))) - .collect(); + sources.retain(|f| matches!(f, Ok(f) if !destination.starts_with(f))); } let span = call.head; diff --git a/crates/nu-command/src/formats/to/md.rs b/crates/nu-command/src/formats/to/md.rs index 76ac54e79..537696fb0 100644 --- a/crates/nu-command/src/formats/to/md.rs +++ b/crates/nu-command/src/formats/to/md.rs @@ -110,7 +110,7 @@ fn fragment(input: Value, pretty: bool, config: &Config) -> String { let mut out = String::new(); if headers.len() == 1 { - let markup = match (&headers[0]).to_ascii_lowercase().as_ref() { + let markup = match headers[0].to_ascii_lowercase().as_ref() { "h1" => "# ".to_string(), "h2" => "## ".to_string(), "h3" => "### ".to_string(), diff --git a/crates/nu-command/src/network/fetch.rs b/crates/nu-command/src/network/fetch.rs index e07729634..b0420e172 100644 --- a/crates/nu-command/src/network/fetch.rs +++ b/crates/nu-command/src/network/fetch.rs @@ -427,7 +427,7 @@ fn helper( // primitive values ([key1 val1 key2 val2]) for row in table.chunks(2) { if row.len() == 2 { - custom_headers.insert(row[0].as_string()?, (&row[1]).clone()); + custom_headers.insert(row[0].as_string()?, row[1].clone()); } } } diff --git a/crates/nu-command/src/network/post.rs b/crates/nu-command/src/network/post.rs index fec460a95..fb96c981e 100644 --- a/crates/nu-command/src/network/post.rs +++ b/crates/nu-command/src/network/post.rs @@ -281,7 +281,7 @@ fn helper( // primitive values ([key1 val1 key2 val2]) for row in table.chunks(2) { if row.len() == 2 { - custom_headers.insert(row[0].as_string()?, (&row[1]).clone()); + custom_headers.insert(row[0].as_string()?, row[1].clone()); } } } diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index 656e9121f..eff479c19 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -357,10 +357,7 @@ fn convert_to_table( // The header with the INDEX is removed from the table headers since // it is added to the natural table index - headers = headers - .into_iter() - .filter(|header| header != INDEX_COLUMN_NAME) - .collect(); + headers.retain(|header| header != INDEX_COLUMN_NAME); // Vec of Vec of String1, String2 where String1 is datatype and String2 is value let mut data: Vec> = Vec::new(); @@ -408,7 +405,7 @@ fn convert_to_table( match result { Ok(value) => row.push(( - (&value.get_type()).to_string(), + value.get_type().to_string(), value.into_abbreviated_string(config), )), Err(_) => row.push(("empty".to_string(), "❎".into())), diff --git a/crates/nu-glob/src/lib.rs b/crates/nu-glob/src/lib.rs index bc5ccfbcd..c4d2cbc5b 100644 --- a/crates/nu-glob/src/lib.rs +++ b/crates/nu-glob/src/lib.rs @@ -199,9 +199,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Result