From 0c38729735de7dabc2c776dadcfe1449a6d443ea Mon Sep 17 00:00:00 2001 From: nibon7 Date: Wed, 23 Nov 2022 11:57:27 +0800 Subject: [PATCH] Apply clippy fix (#7193) # Description rust 1.65.0 has been released for a while, this pr applies lint suggestions from rust 1.65.0. # User-Facing Changes N/A # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace --features=extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace --features=extra` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --- .../src/database/commands/into_sqlite.rs | 27 ++++++++----------- crates/nu-command/src/filters/split_by.rs | 6 ++--- .../src/strings/encode_decode/base64.rs | 2 +- crates/nu-command/src/system/run_external.rs | 4 +-- crates/nu-command/src/viewers/table.rs | 2 +- crates/nu-parser/src/parse_keywords.rs | 2 +- 6 files changed, 19 insertions(+), 24 deletions(-) diff --git a/crates/nu-command/src/database/commands/into_sqlite.rs b/crates/nu-command/src/database/commands/into_sqlite.rs index 59d63f7b3a..d687e2cec6 100644 --- a/crates/nu-command/src/database/commands/into_sqlite.rs +++ b/crates/nu-command/src/database/commands/into_sqlite.rs @@ -4,8 +4,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Category, Config, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, - Spanned, SyntaxShape, Type, Value, + Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned, + SyntaxShape, Type, Value, }; use std::iter; use std::path::Path; @@ -83,14 +83,13 @@ fn operate( input: PipelineData, ) -> Result { let span = call.head; - let config = engine_state.get_config(); let file_name: Spanned = call.req(engine_state, stack, 0)?; let table_name: Option> = call.get_flag(engine_state, stack, "table_name")?; // collect the input into a value let table_entries = input.into_value(span); - match action(&table_entries, table_name, file_name, config, span) { + match action(&table_entries, table_name, file_name, span) { Ok(val) => Ok(val.into_pipeline_data()), Err(e) => Err(e), } @@ -100,7 +99,6 @@ fn action( input: &Value, table: Option>, file: Spanned, - config: &Config, span: Span, ) -> Result { let table_name = if let Some(table_name) = table { @@ -133,10 +131,7 @@ fn action( } => { vals.iter() .map(|rec_val| { - format!( - "'{}'", - nu_value_to_string(rec_val.clone(), "", config) - ) + format!("'{}'", nu_value_to_string(rec_val.clone(), "")) }) .join(",") } @@ -145,10 +140,10 @@ fn action( | Value::Float { val: _, span: _ } | Value::Filesize { val: _, span: _ } | Value::Duration { val: _, span: _ } => - nu_value_to_string(list_value.clone(), "", config), + nu_value_to_string(list_value.clone(), ""), _ => // String formats so add quotes around them - format!("'{}'", nu_value_to_string(list_value.clone(), "", config)), + format!("'{}'", nu_value_to_string(list_value.clone(), "")), } ) }) @@ -231,7 +226,7 @@ fn action( } // This is taken from to text local_into_string but tweaks it a bit so that certain formatting does not happen -fn nu_value_to_string(value: Value, separator: &str, config: &Config) -> String { +fn nu_value_to_string(value: Value, separator: &str) -> String { match value { Value::Bool { val, .. } => val.to_string(), Value::Int { val, .. } => val.to_string(), @@ -242,8 +237,8 @@ fn nu_value_to_string(value: Value, separator: &str, config: &Config) -> String Value::Range { val, .. } => { format!( "{}..{}", - nu_value_to_string(val.from, ", ", config), - nu_value_to_string(val.to, ", ", config) + nu_value_to_string(val.from, ", "), + nu_value_to_string(val.to, ", ") ) } Value::String { val, .. } => { @@ -253,13 +248,13 @@ fn nu_value_to_string(value: Value, separator: &str, config: &Config) -> String } Value::List { vals: val, .. } => val .iter() - .map(|x| nu_value_to_string(x.clone(), ", ", config)) + .map(|x| nu_value_to_string(x.clone(), ", ")) .collect::>() .join(separator), Value::Record { cols, vals, .. } => cols .iter() .zip(vals.iter()) - .map(|(x, y)| format!("{}: {}", x, nu_value_to_string(y.clone(), ", ", config))) + .map(|(x, y)| format!("{}: {}", x, nu_value_to_string(y.clone(), ", "))) .collect::>() .join(separator), Value::Block { val, .. } => format!("", val), diff --git a/crates/nu-command/src/filters/split_by.rs b/crates/nu-command/src/filters/split_by.rs index d42f89fe6b..845352d7e5 100644 --- a/crates/nu-command/src/filters/split_by.rs +++ b/crates/nu-command/src/filters/split_by.rs @@ -1,3 +1,4 @@ +use indexmap::IndexMap; use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; @@ -213,9 +214,8 @@ pub fn data_split( } = grouped { for (inner_idx, subset) in li.iter().enumerate() { - let s = splits - .entry(sub_cols[inner_idx].clone()) - .or_insert(indexmap::IndexMap::new()); + let s: &mut IndexMap = + splits.entry(sub_cols[inner_idx].clone()).or_default(); s.insert(cols[idx].clone(), subset.clone()); } diff --git a/crates/nu-command/src/strings/encode_decode/base64.rs b/crates/nu-command/src/strings/encode_decode/base64.rs index 7aaf5207bb..95f93a3ea0 100644 --- a/crates/nu-command/src/strings/encode_decode/base64.rs +++ b/crates/nu-command/src/strings/encode_decode/base64.rs @@ -100,7 +100,7 @@ fn action( match input { Value::Binary { val, .. } => 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 => Value::Error { error: ShellError::UnsupportedInput( diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index a5c1493206..1618390ee9 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -593,8 +593,8 @@ impl ExternalCommand { for m in matches { if let Ok(arg) = m { let arg = if let Some(prefix) = &prefix { - if let Ok(remainder) = arg.strip_prefix(&prefix) { - let new_prefix = if let Some(pfx) = diff_paths(&prefix, &cwd) { + if let Ok(remainder) = arg.strip_prefix(prefix) { + let new_prefix = if let Some(pfx) = diff_paths(prefix, &cwd) { pfx } else { prefix.to_path_buf() diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index 9d4f841d8a..c33a865679 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -973,7 +973,7 @@ fn convert_to_table2<'a>( data[row].push(value); } - let count_columns = with_index.then(|| 2).unwrap_or(1); + let count_columns = if with_index { 2 } else { 1 }; let size = (data.len(), count_columns); let table = NuTable::new(data, size, usize::MAX, with_header, with_index); diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index 2e52326037..6d4a37b8f0 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -1424,7 +1424,7 @@ pub fn parse_module_block( } LiteElement::Or(_, command) | LiteElement::And(_, command) - | LiteElement::Redirection(_, _, command) => (garbage_pipeline(&command.parts)), + | LiteElement::Redirection(_, _, command) => garbage_pipeline(&command.parts), } } else { error = Some(ParseError::Expected("not a pipeline".into(), span));