diff --git a/crates/nu-command/src/filesystem/cp.rs b/crates/nu-command/src/filesystem/cp.rs index 6ebc305923..79751f2c93 100644 --- a/crates/nu-command/src/filesystem/cp.rs +++ b/crates/nu-command/src/filesystem/cp.rs @@ -124,18 +124,13 @@ impl Command for Cp { let sources = sources.paths_applying_with(|(source_file, depth_level)| { let mut dest = destination.clone(); let path = canonicalize_with(&source_file, &path)?; - - let comps: Vec<_> = path + let components = path .components() .map(|fragment| fragment.as_os_str()) .rev() - .take(1 + depth_level) - .collect(); - - for fragment in comps.into_iter().rev() { - dest.push(fragment); - } + .take(1 + depth_level); + components.for_each(|fragment| dest.push(fragment)); Ok((PathBuf::from(&source_file), dest)) })?;