Skip to content

Commit 713043e

Browse files
committed
rustdoc: create rustc command with an iterator
This avoids unnecessary allocation with a temporary Vec.
1 parent 3d53242 commit 713043e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/librustdoc/doctest.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,14 @@ fn add_exe_suffix(input: String, target: &TargetTriple) -> String {
307307
}
308308

309309
fn wrapped_rustc_command(rustc_wrappers: &[PathBuf], rustc_binary: &Path) -> Command {
310-
let args: Vec<&Path> =
311-
rustc_wrappers.iter().map(PathBuf::as_path).chain([rustc_binary].into_iter()).collect();
312-
let (exe, args) = args.split_first().expect("unable to create rustc command");
310+
let mut args = rustc_wrappers.iter().map(PathBuf::as_path).chain([rustc_binary].into_iter());
313311

312+
let exe = args.next().expect("unable to create rustc command");
314313
let mut command = Command::new(exe);
315-
command.args(args);
314+
for arg in args {
315+
command.arg(arg);
316+
}
317+
316318
command
317319
}
318320

0 commit comments

Comments
 (0)