From 05aca984456438dc05b1fe89221c4305cb5d6472 Mon Sep 17 00:00:00 2001 From: sholderbach Date: Sun, 23 Oct 2022 15:49:05 +0200 Subject: [PATCH] Deal with `needless_collect` with annotations --- crates/nu-command/src/filesystem/cp.rs | 2 ++ crates/nu-command/src/filters/lines.rs | 4 ---- crates/nu-command/src/filters/reverse.rs | 3 +++ 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/nu-command/src/filesystem/cp.rs b/crates/nu-command/src/filesystem/cp.rs index 70cbe2574d..6e73015068 100644 --- a/crates/nu-command/src/filesystem/cp.rs +++ b/crates/nu-command/src/filesystem/cp.rs @@ -235,6 +235,8 @@ impl Command for Cp { })? }; + // The lint does not properly take into account trait bounds + // `ExactSizedIterator` and `DoubleEndedIterator` are necessary to `.rev()` twice with `.take()` inbetween #[allow(clippy::needless_collect)] let comps: Vec<_> = path .components() diff --git a/crates/nu-command/src/filters/lines.rs b/crates/nu-command/src/filters/lines.rs index b4a00f3fbf..994432cc8c 100644 --- a/crates/nu-command/src/filters/lines.rs +++ b/crates/nu-command/src/filters/lines.rs @@ -34,10 +34,6 @@ impl Command for Lines { let ctrlc = engine_state.ctrlc.clone(); let skip_empty = call.has_flag("skip-empty"); match input { - #[allow(clippy::needless_collect)] - // Collect is needed because the string may not live long enough for - // the Rc structure to continue using it. If split could take ownership - // of the split values, then this wouldn't be needed PipelineData::Value(Value::String { val, span }, ..) => { let split_char = if val.contains("\r\n") { "\r\n" } else { "\n" }; diff --git a/crates/nu-command/src/filters/reverse.rs b/crates/nu-command/src/filters/reverse.rs index 566871ccd5..879f4b49e6 100644 --- a/crates/nu-command/src/filters/reverse.rs +++ b/crates/nu-command/src/filters/reverse.rs @@ -50,6 +50,9 @@ impl Command for Reverse { ) -> Result { let metadata = input.metadata(); + // Collecting has to be allowed as `PipelineData` does not implement `DoubleEndedIterator` + // The lint seems broken in those aspects: + // https://github.com/rust-lang/rust-clippy/issues?q=is%3Aissue+is%3Aopen+needless_collect #[allow(clippy::needless_collect)] let v: Vec<_> = input.into_iter().collect(); let iter = v.into_iter().rev();