Skip to content

Commit f60a889

Browse files
committed
rustdoc: create rustc command with an iterator
This avoids unnecessary allocation with a temporary Vec.
1 parent 5e935ad commit f60a889

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
@@ -304,12 +304,14 @@ fn add_exe_suffix(input: String, target: &TargetTriple) -> String {
304304
}
305305

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

309+
let exe = args.next().expect("unable to create rustc command");
311310
let mut command = Command::new(exe);
312-
command.args(args);
311+
for arg in args {
312+
command.arg(arg);
313+
}
314+
313315
command
314316
}
315317

0 commit comments

Comments
 (0)