From e602647d4d6c73cf0e25ab37f26e96dd1b5a7b9f Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Fri, 30 Jul 2021 08:11:47 +1200 Subject: [PATCH] Fix clippy lint and disable broken lint (#3865) --- .azure/azure-pipelines.yml | 2 +- crates/nu-cli/src/app.rs | 8 ++++---- crates/nu-cli/src/app/options_parser.rs | 2 +- .../src/commands/core_commands/let_.rs | 4 ++-- .../src/commands/core_commands/source.rs | 2 +- .../src/commands/dataframe/aggregate.rs | 2 +- .../src/commands/dataframe/filter.rs | 4 ++-- .../nu-command/src/commands/dataframe/join.rs | 4 ++-- .../nu-command/src/commands/dataframe/melt.rs | 4 ++-- .../commands/dataframe/series/concatenate.rs | 2 +- .../src/commands/dataframe/where_.rs | 2 +- crates/nu-command/src/commands/env/let_env.rs | 2 +- .../nu-command/src/commands/env/load_env.rs | 4 ++-- .../nu-command/src/commands/env/with_env.rs | 2 +- .../src/commands/filters/collect.rs | 2 +- .../nu-command/src/commands/filters/merge.rs | 2 +- .../src/commands/filters/reverse.rs | 1 - .../src/commands/formats/from/json.rs | 6 +++--- .../src/commands/platform/which_.rs | 2 +- crates/nu-command/src/examples/double_echo.rs | 1 + .../nu-command/tests/commands/pathvar/mod.rs | 20 +++++++++---------- crates/nu-completion/src/variable.rs | 10 +++++----- crates/nu-engine/src/evaluate/evaluator.rs | 2 +- crates/nu-engine/src/shell/value_shell.rs | 2 +- crates/nu-engine/src/whole_stream_command.rs | 4 ++-- .../src/dataframe/compute_between.rs | 4 ++-- .../nu-protocol/src/dataframe/nu_dataframe.rs | 2 +- crates/nu_plugin_start/src/start.rs | 2 +- 28 files changed, 52 insertions(+), 52 deletions(-) diff --git a/.azure/azure-pipelines.yml b/.azure/azure-pipelines.yml index ed177234a..51d694594 100644 --- a/.azure/azure-pipelines.yml +++ b/.azure/azure-pipelines.yml @@ -49,7 +49,7 @@ steps: - bash: RUSTFLAGS="-D warnings" cargo test --all condition: eq(variables['style'], 'unflagged') displayName: Run tests - - bash: RUSTFLAGS="-D warnings" cargo clippy --all -- -D clippy::unwrap_used + - bash: RUSTFLAGS="-D warnings" cargo clippy --all -- -D clippy::unwrap_used -A clippy::needless_collect condition: eq(variables['style'], 'unflagged') displayName: Check clippy lints - bash: cd samples/wasm && npm install wasm-pack && node ./node_modules/wasm-pack/run.js build diff --git a/crates/nu-cli/src/app.rs b/crates/nu-cli/src/app.rs index fb8b85d77..747867919 100644 --- a/crates/nu-cli/src/app.rs +++ b/crates/nu-cli/src/app.rs @@ -121,9 +121,9 @@ impl App { use logger::{configure, debug_filters, logger, trace_filters}; logger(|builder| { - configure(&self, builder)?; - trace_filters(&self, builder)?; - debug_filters(&self, builder)?; + configure(self, builder)?; + trace_filters(self, builder)?; + debug_filters(self, builder)?; Ok(()) })?; @@ -298,7 +298,7 @@ impl App { } pub fn parse(&self, args: &str) -> Result<(), ShellError> { - self.parser.parse(&args).map(|options| { + self.parser.parse(args).map(|options| { self.options.swap(&options); }) } diff --git a/crates/nu-cli/src/app/options_parser.rs b/crates/nu-cli/src/app/options_parser.rs index 28512fe5b..938d17593 100644 --- a/crates/nu-cli/src/app/options_parser.rs +++ b/crates/nu-cli/src/app/options_parser.rs @@ -111,7 +111,7 @@ impl OptionsParser for NuParser { .flatten(); if let Some(value) = value { - options.put(&k, value); + options.put(k, value); } }); } diff --git a/crates/nu-command/src/commands/core_commands/let_.rs b/crates/nu-command/src/commands/core_commands/let_.rs index 77fbfd9c8..fb52df72b 100644 --- a/crates/nu-command/src/commands/core_commands/let_.rs +++ b/crates/nu-command/src/commands/core_commands/let_.rs @@ -63,7 +63,7 @@ pub fn letcmd(args: CommandArgs) -> Result { .expect("Internal error: type checker should require args"); let var_name = positional[0].var_name()?; - let rhs_raw = evaluate_baseline_expr(&positional[2], &ctx)?; + let rhs_raw = evaluate_baseline_expr(&positional[2], ctx)?; let tag: Tag = positional[2].span.into(); let rhs: CapturedBlock = FromValue::from_value(&rhs_raw)?; @@ -98,7 +98,7 @@ pub fn letcmd(args: CommandArgs) -> Result { }; ctx.scope.enter_scope(); - let value = evaluate_baseline_expr(expr, &ctx); + let value = evaluate_baseline_expr(expr, ctx); ctx.scope.exit_scope(); let value = value?; diff --git a/crates/nu-command/src/commands/core_commands/source.rs b/crates/nu-command/src/commands/core_commands/source.rs index ee8317713..aec3a52f2 100644 --- a/crates/nu-command/src/commands/core_commands/source.rs +++ b/crates/nu-command/src/commands/core_commands/source.rs @@ -51,7 +51,7 @@ pub fn source(args: CommandArgs) -> Result { let contents = std::fs::read_to_string(&expand_path(Cow::Borrowed(Path::new(&filename.item)))); match contents { Ok(contents) => { - let result = script::run_script_standalone(contents, true, &ctx, false); + let result = script::run_script_standalone(contents, true, ctx, false); if let Err(err) = result { ctx.error(err); diff --git a/crates/nu-command/src/commands/dataframe/aggregate.rs b/crates/nu-command/src/commands/dataframe/aggregate.rs index d5f1a922a..c6612d94d 100644 --- a/crates/nu-command/src/commands/dataframe/aggregate.rs +++ b/crates/nu-command/src/commands/dataframe/aggregate.rs @@ -175,7 +175,7 @@ fn command(mut args: CommandArgs) -> Result { UntaggedValue::DataFrame(df) => { let df = df.as_ref(); - let res = perform_dataframe_aggregation(&df, op, &operation.tag)?; + let res = perform_dataframe_aggregation(df, op, &operation.tag)?; Ok(OutputStream::one(NuDataFrame::dataframe_to_value(res, tag))) } diff --git a/crates/nu-command/src/commands/dataframe/filter.rs b/crates/nu-command/src/commands/dataframe/filter.rs index eb9ed1a4d..26a485028 100644 --- a/crates/nu-command/src/commands/dataframe/filter.rs +++ b/crates/nu-command/src/commands/dataframe/filter.rs @@ -73,7 +73,7 @@ fn command(mut args: CommandArgs) -> Result { let casted = series.bool().map_err(|e| { parse_polars_error( &e, - &&series_span, + &series_span, Some("Perhaps you want to use a series with booleans as mask"), ) })?; @@ -82,7 +82,7 @@ fn command(mut args: CommandArgs) -> Result { let res = df .as_ref() - .filter(&casted) + .filter(casted) .map_err(|e| parse_polars_error::<&str>(&e, &df_tag.span, None))?; Ok(OutputStream::one(NuDataFrame::dataframe_to_value(res, tag))) diff --git a/crates/nu-command/src/commands/dataframe/join.rs b/crates/nu-command/src/commands/dataframe/join.rs index 82c21e7ec..78bab021e 100644 --- a/crates/nu-command/src/commands/dataframe/join.rs +++ b/crates/nu-command/src/commands/dataframe/join.rs @@ -180,11 +180,11 @@ fn check_column_datatypes>( for (l, r) in l_cols.iter().zip(r_cols.iter()) { let l_series = df_l .column(l.as_ref()) - .map_err(|e| parse_polars_error::<&str>(&e, &l_col_span, None))?; + .map_err(|e| parse_polars_error::<&str>(&e, l_col_span, None))?; let r_series = df_r .column(r.as_ref()) - .map_err(|e| parse_polars_error::<&str>(&e, &r_col_span, None))?; + .map_err(|e| parse_polars_error::<&str>(&e, r_col_span, None))?; if l_series.dtype() != r_series.dtype() { return Err(ShellError::labeled_error_with_secondary( diff --git a/crates/nu-command/src/commands/dataframe/melt.rs b/crates/nu-command/src/commands/dataframe/melt.rs index 16df644f4..88f1f76fb 100644 --- a/crates/nu-command/src/commands/dataframe/melt.rs +++ b/crates/nu-command/src/commands/dataframe/melt.rs @@ -139,11 +139,11 @@ fn check_column_datatypes>( for w in cols.windows(2) { let l_series = df .column(w[0].as_ref()) - .map_err(|e| parse_polars_error::<&str>(&e, &col_span, None))?; + .map_err(|e| parse_polars_error::<&str>(&e, col_span, None))?; let r_series = df .column(w[1].as_ref()) - .map_err(|e| parse_polars_error::<&str>(&e, &col_span, None))?; + .map_err(|e| parse_polars_error::<&str>(&e, col_span, None))?; if l_series.dtype() != r_series.dtype() { return Err(ShellError::labeled_error_with_secondary( diff --git a/crates/nu-command/src/commands/dataframe/series/concatenate.rs b/crates/nu-command/src/commands/dataframe/series/concatenate.rs index bcad8aea4..e6dc0ef26 100644 --- a/crates/nu-command/src/commands/dataframe/series/concatenate.rs +++ b/crates/nu-command/src/commands/dataframe/series/concatenate.rs @@ -85,7 +85,7 @@ fn command(mut args: CommandArgs) -> Result { ) })?; - let mut res = chunked.concat(&other_chunked); + let mut res = chunked.concat(other_chunked); res.rename(series.name()); diff --git a/crates/nu-command/src/commands/dataframe/where_.rs b/crates/nu-command/src/commands/dataframe/where_.rs index ade8fcc39..aaf5d2b25 100644 --- a/crates/nu-command/src/commands/dataframe/where_.rs +++ b/crates/nu-command/src/commands/dataframe/where_.rs @@ -99,7 +99,7 @@ fn command(args: CommandArgs) -> Result { let rhs = evaluate_baseline_expr(&expression.right, &args.context)?; - filter_dataframe(args, &col_name, &col_name_span, &rhs, &expression.op) + filter_dataframe(args, col_name, col_name_span, &rhs, &expression.op) } macro_rules! comparison_arm { diff --git a/crates/nu-command/src/commands/env/let_env.rs b/crates/nu-command/src/commands/env/let_env.rs index e638a0d70..2cedb38e4 100644 --- a/crates/nu-command/src/commands/env/let_env.rs +++ b/crates/nu-command/src/commands/env/let_env.rs @@ -86,7 +86,7 @@ pub fn set_env(args: CommandArgs) -> Result { ctx.scope.enter_scope(); ctx.scope.add_vars(&captured.entries); - let value = evaluate_baseline_expr(&expr, &ctx); + let value = evaluate_baseline_expr(&expr, ctx); ctx.scope.exit_scope(); diff --git a/crates/nu-command/src/commands/env/load_env.rs b/crates/nu-command/src/commands/env/load_env.rs index c1eee26e4..57f276e6d 100644 --- a/crates/nu-command/src/commands/env/load_env.rs +++ b/crates/nu-command/src/commands/env/load_env.rs @@ -85,10 +85,10 @@ pub fn load_env(args: CommandArgs) -> Result { let ctx = &args.context; if let Some(values) = args.opt::>(0)? { - load_env_from_table(values, &ctx)?; + load_env_from_table(values, ctx)?; } - load_env_from_table(args.input, &ctx)?; + load_env_from_table(args.input, ctx)?; Ok(ActionStream::empty()) } diff --git a/crates/nu-command/src/commands/env/with_env.rs b/crates/nu-command/src/commands/env/with_env.rs index b325a4ac7..79893cbbd 100644 --- a/crates/nu-command/src/commands/env/with_env.rs +++ b/crates/nu-command/src/commands/env/with_env.rs @@ -109,7 +109,7 @@ fn with_env(args: CommandArgs) -> Result { context.scope.add_env(env); context.scope.add_vars(&block.captured.entries); - let result = run_block(&block.block, &context, args.input, external_redirection); + let result = run_block(&block.block, context, args.input, external_redirection); context.scope.exit_scope(); result.map(|x| x.into_action_stream()) diff --git a/crates/nu-command/src/commands/filters/collect.rs b/crates/nu-command/src/commands/filters/collect.rs index e1f56e6f4..10b4a3e15 100644 --- a/crates/nu-command/src/commands/filters/collect.rs +++ b/crates/nu-command/src/commands/filters/collect.rs @@ -67,7 +67,7 @@ fn collect(args: CommandArgs) -> Result { let result = run_block( &block.block, - &context, + context, InputStream::empty(), external_redirection, ); diff --git a/crates/nu-command/src/commands/filters/merge.rs b/crates/nu-command/src/commands/filters/merge.rs index 7e3fe0a96..7bc087fc2 100644 --- a/crates/nu-command/src/commands/filters/merge.rs +++ b/crates/nu-command/src/commands/filters/merge.rs @@ -52,7 +52,7 @@ fn merge(args: CommandArgs) -> Result { context.scope.add_vars(&block.captured.entries); let result = run_block( &block.block, - &context, + context, InputStream::empty(), ExternalRedirection::Stdout, ); diff --git a/crates/nu-command/src/commands/filters/reverse.rs b/crates/nu-command/src/commands/filters/reverse.rs index 2e95b99bd..ebcf15042 100644 --- a/crates/nu-command/src/commands/filters/reverse.rs +++ b/crates/nu-command/src/commands/filters/reverse.rs @@ -37,7 +37,6 @@ impl WholeStreamCommand for Reverse { } } -#[allow(clippy::needless_collect)] fn reverse(args: CommandArgs) -> Result { let input = args.input.collect::>(); Ok((input.into_iter().rev().map(ReturnSuccess::value)).into_action_stream()) diff --git a/crates/nu-command/src/commands/formats/from/json.rs b/crates/nu-command/src/commands/formats/from/json.rs index 38b67b5cb..2341965db 100644 --- a/crates/nu-command/src/commands/formats/from/json.rs +++ b/crates/nu-command/src/commands/formats/from/json.rs @@ -69,10 +69,10 @@ fn from_json(args: CommandArgs) -> Result { let concat_string = args.input.collect_string(name_tag.clone())?; - let string_clone: Vec<_> = concat_string.item.lines().map(|x| x.to_string()).collect(); - if objects { - Ok(string_clone + #[allow(clippy::needless_collect)] + let lines: Vec<_> = concat_string.item.lines().map(|x| x.to_string()).collect(); + Ok(lines .into_iter() .filter_map(move |json_str| { if json_str.is_empty() { diff --git a/crates/nu-command/src/commands/platform/which_.rs b/crates/nu-command/src/commands/platform/which_.rs index 2eb64c2a2..b71e84717 100644 --- a/crates/nu-command/src/commands/platform/which_.rs +++ b/crates/nu-command/src/commands/platform/which_.rs @@ -218,7 +218,7 @@ fn which(args: CommandArgs) -> Result { let mut output = vec![]; for app in which_args.applications { - let values = which_single(app, which_args.all, &args.scope()); + let values = which_single(app, which_args.all, args.scope()); output.extend(values); } diff --git a/crates/nu-command/src/examples/double_echo.rs b/crates/nu-command/src/examples/double_echo.rs index c993c3679..054e1827d 100644 --- a/crates/nu-command/src/examples/double_echo.rs +++ b/crates/nu-command/src/examples/double_echo.rs @@ -10,6 +10,7 @@ pub struct Command; #[derive(Deserialize)] struct Arguments { + #[allow(unused)] pub rest: Vec, } diff --git a/crates/nu-command/tests/commands/pathvar/mod.rs b/crates/nu-command/tests/commands/pathvar/mod.rs index 653be916a..2ac3fd138 100644 --- a/crates/nu-command/tests/commands/pathvar/mod.rs +++ b/crates/nu-command/tests/commands/pathvar/mod.rs @@ -66,7 +66,7 @@ fn pathvar_correctly_reads_path_from_config() { let expected = "/Users/andresrobalino/.volta/bin-/Users/mosqueteros/bin"; let actual = sandbox.pipeline(r#" pathvar | first 2 | str collect '-' "#); - assert_that!(actual, says().stdout(&expected)); + assert_that!(actual, says().stdout(expected)); }) } @@ -78,7 +78,7 @@ fn pathvar_correctly_reads_env_var_from_env() { let expected = "bacon-spam"; let actual = sandbox.pipeline(r#" pathvar -v BREAKFAST | str collect '-' "#); - assert_that!(actual, says().stdout(&expected)); + assert_that!(actual, says().stdout(expected)); }) } @@ -103,7 +103,7 @@ fn pathvar_adds_to_path() { let expected = "spam"; let actual = sandbox.pipeline(r#" pathvar add spam; pathvar | first "#); - assert_that!(actual, says().stdout(&expected)); + assert_that!(actual, says().stdout(expected)); }) } @@ -145,7 +145,7 @@ fn pathvar_appends_to_path() { let expected = "spam"; let actual = sandbox.pipeline(r#" pathvar append spam; pathvar | last "#); - assert_that!(actual, says().stdout(&expected)); + assert_that!(actual, says().stdout(expected)); }) } @@ -187,7 +187,7 @@ fn pathvar_removes_from_path() { let expected = "/Users/mosquito/proboscis"; let actual = sandbox.pipeline(r#" pathvar remove 1; pathvar | first "#); - assert_that!(actual, says().stdout(&expected)); + assert_that!(actual, says().stdout(expected)); }) } @@ -241,7 +241,7 @@ fn pathvar_resets_path_from_config() { "#, ); - assert_that!(actual, says().stdout(&expected)); + assert_that!(actual, says().stdout(expected)); }) } @@ -273,7 +273,7 @@ fn pathvar_resets_env_var_from_config() { "#, ); - assert_that!(actual, says().stdout(&expected)); + assert_that!(actual, says().stdout(expected)); }) } @@ -304,7 +304,7 @@ fn pathvar_saves_path_to_config() { "#, ); - assert_that!(actual, says().stdout(&expected)); + assert_that!(actual, says().stdout(expected)); }) } @@ -333,7 +333,7 @@ fn pathvar_saves_env_var_to_config() { "#, ); - assert_that!(actual, says().stdout(&expected)); + assert_that!(actual, says().stdout(expected)); }) } @@ -360,7 +360,7 @@ fn pathvar_saves_new_env_var_to_config() { "#, ); - assert_that!(actual, says().stdout(&expected)); + assert_that!(actual, says().stdout(expected)); }) } diff --git a/crates/nu-completion/src/variable.rs b/crates/nu-completion/src/variable.rs index 4bc56542a..e00d3c62a 100644 --- a/crates/nu-completion/src/variable.rs +++ b/crates/nu-completion/src/variable.rs @@ -20,12 +20,12 @@ fn build_path(head: &str, members: &Path, entry: &str) -> String { fn collect_entries(value_fs: &ValueShell, head: &str, path: &Path) -> Vec { value_fs - .members_under(&path) + .members_under(path) .iter() .flat_map(|entry| { entry .row_entries() - .map(|(entry_name, _)| build_path(&head, &path, entry_name)) + .map(|(entry_name, _)| build_path(head, path, entry_name)) }) .collect() } @@ -62,7 +62,7 @@ where .or_else(|| { path.parent().map(|parent| { fs.find(parent) - .map(|fs| collect_entries(fs, &head, &parent)) + .map(|fs| collect_entries(fs, &head, parent)) .unwrap_or_default() }) }) @@ -72,7 +72,7 @@ where }) .flatten() .filter_map(|candidate| { - if matcher.matches(&partial, &candidate) { + if matcher.matches(partial, &candidate) { Some(Suggestion::new(&candidate, &candidate)) } else { None @@ -107,7 +107,7 @@ mod tests { } fn source(&self) -> &nu_engine::EvaluationContext { - &self.0 + self.0 } fn scope(&self) -> &dyn nu_parser::ParserScope { diff --git a/crates/nu-engine/src/evaluate/evaluator.rs b/crates/nu-engine/src/evaluate/evaluator.rs index 13cae7ec5..68d99058f 100644 --- a/crates/nu-engine/src/evaluate/evaluator.rs +++ b/crates/nu-engine/src/evaluate/evaluator.rs @@ -266,7 +266,7 @@ impl<'a> From<&'a Expression> for Variable<'a> { "$true" => Self::True, "$false" => Self::False, "$nothing" => Self::Nothing, - _ => Self::Other(&name), + _ => Self::Other(name), }, _ => unreachable!(), } diff --git a/crates/nu-engine/src/shell/value_shell.rs b/crates/nu-engine/src/shell/value_shell.rs index bf83f64f1..186ec41f9 100644 --- a/crates/nu-engine/src/shell/value_shell.rs +++ b/crates/nu-engine/src/shell/value_shell.rs @@ -42,7 +42,7 @@ impl ValueShell { let mut value_system = ValueStructure::new(); if value_system.walk_decorate(&self.value).is_ok() { - value_system.exists(&path).then(|| self) + value_system.exists(path).then(|| self) } else { None } diff --git a/crates/nu-engine/src/whole_stream_command.rs b/crates/nu-engine/src/whole_stream_command.rs index fe936b6ce..e460da34a 100644 --- a/crates/nu-engine/src/whole_stream_command.rs +++ b/crates/nu-engine/src/whole_stream_command.rs @@ -104,7 +104,7 @@ impl WholeStreamCommand for Arc { let external_redirection = args.call_info.args.external_redirection; let ctx = &args.context; - let evaluated = call_info.evaluate(&ctx)?; + let evaluated = call_info.evaluate(ctx)?; let input = args.input; ctx.scope.enter_scope(); @@ -198,7 +198,7 @@ impl WholeStreamCommand for Arc { } } } - let result = run_block(&block, &ctx, input, external_redirection); + let result = run_block(&block, ctx, input, external_redirection); ctx.scope.exit_scope(); result } diff --git a/crates/nu-protocol/src/dataframe/compute_between.rs b/crates/nu-protocol/src/dataframe/compute_between.rs index ba1b1bff2..9ebfc4039 100644 --- a/crates/nu-protocol/src/dataframe/compute_between.rs +++ b/crates/nu-protocol/src/dataframe/compute_between.rs @@ -186,7 +186,7 @@ pub fn compute_between_series( let mut res = l.bitand(r).into_series(); let name = format!("and_{}_{}", lhs.name(), rhs.name()); res.rename(name.as_ref()); - Ok(NuDataFrame::series_to_untagged(res, &operation_span)) + Ok(NuDataFrame::series_to_untagged(res, operation_span)) } _ => Ok(UntaggedValue::Error(ShellError::labeled_error( "Casting error", @@ -211,7 +211,7 @@ pub fn compute_between_series( let mut res = l.bitor(r).into_series(); let name = format!("or_{}_{}", lhs.name(), rhs.name()); res.rename(name.as_ref()); - Ok(NuDataFrame::series_to_untagged(res, &operation_span)) + Ok(NuDataFrame::series_to_untagged(res, operation_span)) } _ => Ok(UntaggedValue::Error(ShellError::labeled_error( "Casting error", diff --git a/crates/nu-protocol/src/dataframe/nu_dataframe.rs b/crates/nu-protocol/src/dataframe/nu_dataframe.rs index 7b69fc1e6..68e39eb9d 100644 --- a/crates/nu-protocol/src/dataframe/nu_dataframe.rs +++ b/crates/nu-protocol/src/dataframe/nu_dataframe.rs @@ -136,7 +136,7 @@ impl PartialEq for NuDataFrame { _ => self_series.clone(), }; - if !self_series.series_equal(&other_series) { + if !self_series.series_equal(other_series) { return false; } } diff --git a/crates/nu_plugin_start/src/start.rs b/crates/nu_plugin_start/src/start.rs index fd9d8511a..4914035b7 100644 --- a/crates/nu_plugin_start/src/start.rs +++ b/crates/nu_plugin_start/src/start.rs @@ -206,7 +206,7 @@ impl Start { ); if let Some(app_name) = &self.application { - exec_cmd(&app_name, &args, self.tag.clone()) + exec_cmd(app_name, &args, self.tag.clone()) } else { for cmd in &["xdg-open", "gnome-open", "kde-open", "wslview"] { if exec_cmd(cmd, &args, self.tag.clone()).is_err() {