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 05aca98445.

The previous state seems to better from a performance perspective as a
`Vec<String>` is lighter weight than `Vec<Value>`
This commit is contained in:
Stefan Holderbach 2022-10-24 20:12:16 +02:00 committed by GitHub
parent 79fd7d54b2
commit 6a7a60429f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 8 additions and 34 deletions

View file

@ -55,7 +55,6 @@ impl Command for ColumnsDF {
} }
} }
#[allow(clippy::needless_collect)]
fn command( fn command(
_engine_state: &EngineState, _engine_state: &EngineState,
_stack: &mut Stack, _stack: &mut Stack,

View file

@ -56,7 +56,6 @@ impl Command for DataTypes {
} }
} }
#[allow(clippy::needless_collect)]
fn command( fn command(
_engine_state: &EngineState, _engine_state: &EngineState,
_stack: &mut Stack, _stack: &mut Stack,

View file

@ -25,7 +25,6 @@ const GLOB_PARAMS: nu_glob::MatchOptions = nu_glob::MatchOptions {
#[derive(Clone)] #[derive(Clone)]
pub struct Cp; pub struct Cp;
#[allow(unused_must_use)]
impl Command for Cp { impl Command for Cp {
fn name(&self) -> &str { fn name(&self) -> &str {
"cp" "cp"

View file

@ -20,7 +20,6 @@ const GLOB_PARAMS: nu_glob::MatchOptions = nu_glob::MatchOptions {
#[derive(Clone)] #[derive(Clone)]
pub struct Mv; pub struct Mv;
#[allow(unused_must_use)]
impl Command for Mv { impl Command for Mv {
fn name(&self) -> &str { fn name(&self) -> &str {
"mv" "mv"

View file

@ -14,20 +14,11 @@ pub struct FileStructure {
pub resources: Vec<Resource>, pub resources: Vec<Resource>,
} }
#[allow(dead_code)]
impl FileStructure { impl FileStructure {
pub fn new() -> FileStructure { pub fn new() -> FileStructure {
FileStructure { resources: vec![] } 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<F>( pub fn paths_applying_with<F>(
&mut self, &mut self,
to: F, to: F,

View file

@ -38,7 +38,6 @@ impl Command for GroupBy {
group_by(engine_state, stack, call, input) group_by(engine_state, stack, call, input)
} }
#[allow(clippy::unwrap_used)]
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![ vec![
Example { Example {

View file

@ -35,7 +35,6 @@ impl Command for SplitBy {
split_by(engine_state, stack, call, input) split_by(engine_state, stack, call, input)
} }
#[allow(clippy::unwrap_used)]
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "split items by column named \"lang\"", description: "split items by column named \"lang\"",

View file

@ -84,21 +84,20 @@ impl Command for FromJson {
// TODO: turn this into a structured underline of the nu_json error // TODO: turn this into a structured underline of the nu_json error
if call.has_flag("objects") { if call.has_flag("objects") {
#[allow(clippy::needless_collect)] let converted_lines: Vec<Value> = string_input
let lines: Vec<String> = string_input.lines().map(|x| x.to_string()).collect(); .lines()
Ok(lines
.into_iter()
.filter_map(move |x| { .filter_map(move |x| {
if x.trim() == "" { if x.trim() == "" {
None None
} else { } else {
match convert_string_to_value(x, span) { match convert_string_to_value(x.to_string(), span) {
Ok(v) => Some(v), Ok(v) => Some(v),
Err(error) => Some(Value::Error { error }), 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 { } else {
Ok(convert_string_to_value(string_input, span)?.into_pipeline_data()) Ok(convert_string_to_value(string_input, span)?.into_pipeline_data())
} }

View file

@ -270,15 +270,10 @@ fn get_output_string(
output_string.push_str("\n|"); output_string.push_str("\n|");
#[allow(clippy::needless_range_loop)] for &col_width in column_widths.iter().take(headers.len()) {
for i in 0..headers.len() {
if pretty { if pretty {
output_string.push(' '); output_string.push(' ');
output_string.push_str(&get_padded_string( output_string.push_str(&get_padded_string(String::from("-"), col_width, '-'));
String::from("-"),
column_widths[i],
'-',
));
output_string.push(' '); output_string.push(' ');
} else { } else {
output_string.push('-'); output_string.push('-');

View file

@ -1,7 +1,6 @@
use nu_protocol::{ShellError, Span, Value}; use nu_protocol::{ShellError, Span, Value};
use std::cmp::Ordering; use std::cmp::Ordering;
#[allow(dead_code)]
pub enum Reduce { pub enum Reduce {
Summation, Summation,
Product, Product,

View file

@ -774,7 +774,6 @@ fn convert_to_table(
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
#[allow(clippy::into_iter_on_ref)]
fn convert_to_table2<'a>( fn convert_to_table2<'a>(
row_offset: usize, row_offset: usize,
input: impl Iterator<Item = &'a Value> + ExactSizeIterator + Clone, input: impl Iterator<Item = &'a Value> + ExactSizeIterator + Clone,

View file

@ -1,5 +1,5 @@
use nu_test_support::nu; use nu_test_support::nu;
#[allow(unused)] #[cfg(feature = "database")]
use nu_test_support::pipeline; use nu_test_support::pipeline;
#[test] #[test]

View file

@ -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(..)`. /// Configuration options to modify the behaviour of `Pattern::matches_with(..)`.
#[allow(missing_copy_implementations)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct MatchOptions { pub struct MatchOptions {
/// Whether or not patterns should be matched in a case-sensitive manner. /// Whether or not patterns should be matched in a case-sensitive manner.

View file

@ -1604,7 +1604,6 @@ pub fn parse_string_interpolation(
let mut b = start; let mut b = start;
#[allow(clippy::needless_range_loop)]
while b != end { while b != end {
if contents[b - start] == b'(' if contents[b - start] == b'('
&& (if double_quote && (b - start) > 0 { && (if double_quote && (b - start) > 0 {

View file

@ -606,7 +606,6 @@ fn parse_commandline_args(
struct NushellCliArgs { struct NushellCliArgs {
redirect_stdin: Option<Spanned<String>>, redirect_stdin: Option<Spanned<String>>,
#[allow(dead_code)]
login_shell: Option<Spanned<String>>, login_shell: Option<Spanned<String>>,
interactive_shell: Option<Spanned<String>>, interactive_shell: Option<Spanned<String>>,
commands: Option<Spanned<String>>, commands: Option<Spanned<String>>,