From 517ca2604a8dfe8e2e4ff400ccdddc0b382996c6 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 21 Nov 2022 18:28:13 -0800 Subject: [PATCH] Fix clippy::needless_pass_by_value (pedantic) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit “this argument is passed by value, but not consumed in the function body” https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value Signed-off-by: Anders Kaseorg --- src/check_imports.rs | 2 +- src/flake8_annotations/settings.rs | 1 + src/flake8_builtins/types.rs | 1 + src/isort/plugins.rs | 8 ++++---- src/mccabe/settings.rs | 1 + src/rules/checks.rs | 1 + 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/check_imports.rs b/src/check_imports.rs index 4375d597d2..91ec788e97 100644 --- a/src/check_imports.rs +++ b/src/check_imports.rs @@ -20,7 +20,7 @@ fn check_import_blocks( let mut checks = vec![]; for block in tracker.into_iter() { if !block.is_empty() { - if let Some(check) = isort::plugins::check_imports(block, locator, settings, autofix) { + if let Some(check) = isort::plugins::check_imports(&block, locator, settings, autofix) { checks.push(check); } } diff --git a/src/flake8_annotations/settings.rs b/src/flake8_annotations/settings.rs index 69f8d5049f..573d2ebc01 100644 --- a/src/flake8_annotations/settings.rs +++ b/src/flake8_annotations/settings.rs @@ -29,6 +29,7 @@ pub struct Settings { } impl Settings { + #[allow(clippy::needless_pass_by_value)] pub fn from_options(options: Options) -> Self { Self { mypy_init_return: options.mypy_init_return.unwrap_or_default(), diff --git a/src/flake8_builtins/types.rs b/src/flake8_builtins/types.rs index 48b4c70b21..c32aa25993 100644 --- a/src/flake8_builtins/types.rs +++ b/src/flake8_builtins/types.rs @@ -1,3 +1,4 @@ +#[derive(Clone, Copy)] pub enum ShadowingType { Variable, Argument, diff --git a/src/isort/plugins.rs b/src/isort/plugins.rs index 4e1f48005d..3ff0d0b8d5 100644 --- a/src/isort/plugins.rs +++ b/src/isort/plugins.rs @@ -30,13 +30,13 @@ fn extract_indentation(body: &[&Stmt], locator: &SourceCodeLocator) -> String { /// I001 pub fn check_imports( - body: Vec<&Stmt>, + body: &[&Stmt], locator: &SourceCodeLocator, settings: &Settings, autofix: &fixer::Mode, ) -> Option { - let range = extract_range(&body); - let indentation = extract_indentation(&body, locator); + let range = extract_range(body); + let indentation = extract_indentation(body, locator); // Extract comments. Take care to grab any inline comments from the last line. let comments = comments::collect_comments( @@ -53,7 +53,7 @@ pub fn check_imports( // Generate the sorted import block. let expected = format_imports( - &body, + body, comments, settings.line_length - indentation.len(), &settings.src, diff --git a/src/mccabe/settings.rs b/src/mccabe/settings.rs index 2f1cde3a50..a76a48b787 100644 --- a/src/mccabe/settings.rs +++ b/src/mccabe/settings.rs @@ -14,6 +14,7 @@ pub struct Settings { } impl Settings { + #[allow(clippy::needless_pass_by_value)] pub fn from_options(options: Options) -> Self { Self { max_complexity: options.max_complexity.unwrap_or_default(), diff --git a/src/rules/checks.rs b/src/rules/checks.rs index 3ecbb99757..9a74d3aa7e 100644 --- a/src/rules/checks.rs +++ b/src/rules/checks.rs @@ -1596,6 +1596,7 @@ static CONFUSABLES: Lazy> = Lazy::new(|| { ]) }); +#[derive(Clone, Copy)] pub enum Context { String, Docstring,