diff options
| author | Travis Finkenauer <tmfinken@gmail.com> | 2023-08-20 20:25:30 -0700 |
|---|---|---|
| committer | Travis Finkenauer <tmfinken@gmail.com> | 2024-03-15 01:41:37 -0700 |
| commit | 713043ef226332216ed75c1bd5ec1f6068a8439c (patch) | |
| tree | 7781e7ab00bd53d8b4890a45a119339507524353 | |
| parent | 3d53242e53bcf4f43f7d361cb7e2a4a28f30db9c (diff) | |
| download | rust-713043ef226332216ed75c1bd5ec1f6068a8439c.tar.gz rust-713043ef226332216ed75c1bd5ec1f6068a8439c.zip | |
rustdoc: create rustc command with an iterator
This avoids unnecessary allocation with a temporary Vec.
| -rw-r--r-- | src/librustdoc/doctest.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 96ad83e7867..c6eb7be08cd 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -307,12 +307,14 @@ fn add_exe_suffix(input: String, target: &TargetTriple) -> String { } fn wrapped_rustc_command(rustc_wrappers: &[PathBuf], rustc_binary: &Path) -> Command { - let args: Vec<&Path> = - rustc_wrappers.iter().map(PathBuf::as_path).chain([rustc_binary].into_iter()).collect(); - let (exe, args) = args.split_first().expect("unable to create rustc command"); + let mut args = rustc_wrappers.iter().map(PathBuf::as_path).chain([rustc_binary].into_iter()); + let exe = args.next().expect("unable to create rustc command"); let mut command = Command::new(exe); - command.args(args); + for arg in args { + command.arg(arg); + } + command } |
