Deal with needless_collect with annotations

This commit is contained in:
sholderbach 2022-10-23 15:49:05 +02:00
parent 07c21a58fb
commit 05aca98445
3 changed files with 5 additions and 4 deletions

View File

@ -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)] #[allow(clippy::needless_collect)]
let comps: Vec<_> = path let comps: Vec<_> = path
.components() .components()

View File

@ -34,10 +34,6 @@ impl Command for Lines {
let ctrlc = engine_state.ctrlc.clone(); let ctrlc = engine_state.ctrlc.clone();
let skip_empty = call.has_flag("skip-empty"); let skip_empty = call.has_flag("skip-empty");
match input { 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 }, ..) => { PipelineData::Value(Value::String { val, span }, ..) => {
let split_char = if val.contains("\r\n") { "\r\n" } else { "\n" }; let split_char = if val.contains("\r\n") { "\r\n" } else { "\n" };

View File

@ -50,6 +50,9 @@ impl Command for Reverse {
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
let metadata = input.metadata(); 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)] #[allow(clippy::needless_collect)]
let v: Vec<_> = input.into_iter().collect(); let v: Vec<_> = input.into_iter().collect();
let iter = v.into_iter().rev(); let iter = v.into_iter().rev();