diff --git a/.azure/azure-pipelines.yml b/.azure/azure-pipelines.yml index ed177234a8..51d6945944 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 fb8b85d773..747867919a 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 28512fe5bb..938d17593f 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 77fbfd9c82..fb52df72b9 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 ee8317713f..aec3a52f28 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 d5f1a922a2..c6612d94dc 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 eb9ed1a4de..26a485028d 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 82c21e7ec4..78bab021e1 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 16df644f48..88f1f76fbc 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 bcad8aea44..e6dc0ef267 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 ade8fcc392..aaf5d2b257 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 e638a0d707..2cedb38e42 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 c1eee26e46..57f276e6d4 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 b325a4ac7a..79893cbbd4 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 e1f56e6f4f..10b4a3e154 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 7e3fe0a963..7bc087fc20 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 2e95b99bd8..ebcf15042e 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 38b67b5cb8..2341965db4 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 2eb64c2a27..b71e847175 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 c993c36797..054e1827d6 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 653be916a6..2ac3fd1384 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 4bc56542a3..e00d3c62ac 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 13cae7ec54..68d99058f6 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 bf83f64f1e..186ec41f9f 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 fe936b6ce3..e460da34ae 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 ba1b1bff22..9ebfc4039e 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 7b69fc1e6c..68e39eb9df 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 fd9d8511af..4914035b7d 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() {