From 6a7a60429f5c3090209b7bac90632189ffa2487c Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Mon, 24 Oct 2022 20:12:16 +0200 Subject: [PATCH] Remove unnecessary `#[allow(...)]` annotations (#6870) * Remove unnecessary `#[allow]` annots Reduce the number of lint exceptions that are not necessary with the current state of the code (or more recent toolchain) * Remove dead code from `FileStructure` in nu-command * Replace `allow(unused)` with relevant feature switch * Deal with `needless_collect` with annotations * Change hack for needless_collect in `from json` This change obviates the need for `allow(needless_collect)` Removes a pessimistic allocation for empty strings, but increases allocation size to `Value` Probably not really worth it. * Revert "Deal with `needless_collect` with annotations" This reverts commit 05aca984456438dc05b1fe89221c4305cb5d6472. The previous state seems to better from a performance perspective as a `Vec` is lighter weight than `Vec` --- crates/nu-command/src/dataframe/eager/columns.rs | 1 - crates/nu-command/src/dataframe/eager/dtypes.rs | 1 - crates/nu-command/src/filesystem/cp.rs | 1 - crates/nu-command/src/filesystem/mv.rs | 1 - crates/nu-command/src/filesystem/util.rs | 9 --------- crates/nu-command/src/filters/group_by.rs | 1 - crates/nu-command/src/filters/split_by.rs | 1 - crates/nu-command/src/formats/from/json.rs | 11 +++++------ crates/nu-command/src/formats/to/md.rs | 9 ++------- crates/nu-command/src/math/reducers.rs | 1 - crates/nu-command/src/viewers/table.rs | 1 - crates/nu-command/tests/commands/where_.rs | 2 +- crates/nu-glob/src/lib.rs | 1 - crates/nu-parser/src/parser.rs | 1 - src/main.rs | 1 - 15 files changed, 8 insertions(+), 34 deletions(-) diff --git a/crates/nu-command/src/dataframe/eager/columns.rs b/crates/nu-command/src/dataframe/eager/columns.rs index 0005d9311e..01cf03394f 100644 --- a/crates/nu-command/src/dataframe/eager/columns.rs +++ b/crates/nu-command/src/dataframe/eager/columns.rs @@ -55,7 +55,6 @@ impl Command for ColumnsDF { } } -#[allow(clippy::needless_collect)] fn command( _engine_state: &EngineState, _stack: &mut Stack, diff --git a/crates/nu-command/src/dataframe/eager/dtypes.rs b/crates/nu-command/src/dataframe/eager/dtypes.rs index b2b706d629..c8e0c54005 100644 --- a/crates/nu-command/src/dataframe/eager/dtypes.rs +++ b/crates/nu-command/src/dataframe/eager/dtypes.rs @@ -56,7 +56,6 @@ impl Command for DataTypes { } } -#[allow(clippy::needless_collect)] fn command( _engine_state: &EngineState, _stack: &mut Stack, diff --git a/crates/nu-command/src/filesystem/cp.rs b/crates/nu-command/src/filesystem/cp.rs index 9a554897f6..70cbe2574d 100644 --- a/crates/nu-command/src/filesystem/cp.rs +++ b/crates/nu-command/src/filesystem/cp.rs @@ -25,7 +25,6 @@ const GLOB_PARAMS: nu_glob::MatchOptions = nu_glob::MatchOptions { #[derive(Clone)] pub struct Cp; -#[allow(unused_must_use)] impl Command for Cp { fn name(&self) -> &str { "cp" diff --git a/crates/nu-command/src/filesystem/mv.rs b/crates/nu-command/src/filesystem/mv.rs index 5a79876221..c2daa6e823 100644 --- a/crates/nu-command/src/filesystem/mv.rs +++ b/crates/nu-command/src/filesystem/mv.rs @@ -20,7 +20,6 @@ const GLOB_PARAMS: nu_glob::MatchOptions = nu_glob::MatchOptions { #[derive(Clone)] pub struct Mv; -#[allow(unused_must_use)] impl Command for Mv { fn name(&self) -> &str { "mv" diff --git a/crates/nu-command/src/filesystem/util.rs b/crates/nu-command/src/filesystem/util.rs index c58a823b5a..db15c58d0a 100644 --- a/crates/nu-command/src/filesystem/util.rs +++ b/crates/nu-command/src/filesystem/util.rs @@ -14,20 +14,11 @@ pub struct FileStructure { pub resources: Vec, } -#[allow(dead_code)] impl FileStructure { pub fn new() -> FileStructure { FileStructure { resources: vec![] } } - pub fn contains_more_than_one_file(&self) -> bool { - self.resources.len() > 1 - } - - pub fn contains_files(&self) -> bool { - !self.resources.is_empty() - } - pub fn paths_applying_with( &mut self, to: F, diff --git a/crates/nu-command/src/filters/group_by.rs b/crates/nu-command/src/filters/group_by.rs index 0bc49fbdd1..ef69520d93 100644 --- a/crates/nu-command/src/filters/group_by.rs +++ b/crates/nu-command/src/filters/group_by.rs @@ -38,7 +38,6 @@ impl Command for GroupBy { group_by(engine_state, stack, call, input) } - #[allow(clippy::unwrap_used)] fn examples(&self) -> Vec { vec![ Example { diff --git a/crates/nu-command/src/filters/split_by.rs b/crates/nu-command/src/filters/split_by.rs index 61abc128d4..25c164079f 100644 --- a/crates/nu-command/src/filters/split_by.rs +++ b/crates/nu-command/src/filters/split_by.rs @@ -35,7 +35,6 @@ impl Command for SplitBy { split_by(engine_state, stack, call, input) } - #[allow(clippy::unwrap_used)] fn examples(&self) -> Vec { vec![Example { description: "split items by column named \"lang\"", diff --git a/crates/nu-command/src/formats/from/json.rs b/crates/nu-command/src/formats/from/json.rs index 5cf7143f5a..8383923702 100644 --- a/crates/nu-command/src/formats/from/json.rs +++ b/crates/nu-command/src/formats/from/json.rs @@ -84,21 +84,20 @@ impl Command for FromJson { // TODO: turn this into a structured underline of the nu_json error if call.has_flag("objects") { - #[allow(clippy::needless_collect)] - let lines: Vec = string_input.lines().map(|x| x.to_string()).collect(); - Ok(lines - .into_iter() + let converted_lines: Vec = string_input + .lines() .filter_map(move |x| { if x.trim() == "" { None } else { - match convert_string_to_value(x, span) { + match convert_string_to_value(x.to_string(), span) { Ok(v) => Some(v), Err(error) => Some(Value::Error { error }), } } }) - .into_pipeline_data(engine_state.ctrlc.clone())) + .collect(); + Ok(converted_lines.into_pipeline_data(engine_state.ctrlc.clone())) } else { Ok(convert_string_to_value(string_input, span)?.into_pipeline_data()) } diff --git a/crates/nu-command/src/formats/to/md.rs b/crates/nu-command/src/formats/to/md.rs index 537696fb03..44f5d155a4 100644 --- a/crates/nu-command/src/formats/to/md.rs +++ b/crates/nu-command/src/formats/to/md.rs @@ -270,15 +270,10 @@ fn get_output_string( output_string.push_str("\n|"); - #[allow(clippy::needless_range_loop)] - for i in 0..headers.len() { + for &col_width in column_widths.iter().take(headers.len()) { if pretty { output_string.push(' '); - output_string.push_str(&get_padded_string( - String::from("-"), - column_widths[i], - '-', - )); + output_string.push_str(&get_padded_string(String::from("-"), col_width, '-')); output_string.push(' '); } else { output_string.push('-'); diff --git a/crates/nu-command/src/math/reducers.rs b/crates/nu-command/src/math/reducers.rs index 5a8269868f..3b0e86b0f6 100644 --- a/crates/nu-command/src/math/reducers.rs +++ b/crates/nu-command/src/math/reducers.rs @@ -1,7 +1,6 @@ use nu_protocol::{ShellError, Span, Value}; use std::cmp::Ordering; -#[allow(dead_code)] pub enum Reduce { Summation, Product, diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index 2253b39e8a..0fe48bd8f1 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -774,7 +774,6 @@ fn convert_to_table( } #[allow(clippy::too_many_arguments)] -#[allow(clippy::into_iter_on_ref)] fn convert_to_table2<'a>( row_offset: usize, input: impl Iterator + ExactSizeIterator + Clone, diff --git a/crates/nu-command/tests/commands/where_.rs b/crates/nu-command/tests/commands/where_.rs index 102d0d5d4a..72bf3b2aa9 100644 --- a/crates/nu-command/tests/commands/where_.rs +++ b/crates/nu-command/tests/commands/where_.rs @@ -1,5 +1,5 @@ use nu_test_support::nu; -#[allow(unused)] +#[cfg(feature = "database")] use nu_test_support::pipeline; #[test] diff --git a/crates/nu-glob/src/lib.rs b/crates/nu-glob/src/lib.rs index c4d2cbc5b3..4138946fbd 100644 --- a/crates/nu-glob/src/lib.rs +++ b/crates/nu-glob/src/lib.rs @@ -863,7 +863,6 @@ fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool { } /// Configuration options to modify the behaviour of `Pattern::matches_with(..)`. -#[allow(missing_copy_implementations)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct MatchOptions { /// Whether or not patterns should be matched in a case-sensitive manner. diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 07e63d1ec2..9cd521cf47 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -1604,7 +1604,6 @@ pub fn parse_string_interpolation( let mut b = start; - #[allow(clippy::needless_range_loop)] while b != end { if contents[b - start] == b'(' && (if double_quote && (b - start) > 0 { diff --git a/src/main.rs b/src/main.rs index 1499edd8a4..b8c2dfae9d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -606,7 +606,6 @@ fn parse_commandline_args( struct NushellCliArgs { redirect_stdin: Option>, - #[allow(dead_code)] login_shell: Option>, interactive_shell: Option>, commands: Option>,