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
15 changed files with 8 additions and 34 deletions

View File

@ -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> = string_input.lines().map(|x| x.to_string()).collect();
Ok(lines
.into_iter()
let converted_lines: Vec<Value> = 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())
}

View File

@ -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('-');