diff options
| author | mo8it <mo8it@proton.me> | 2024-08-10 00:24:55 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-08-10 00:24:55 +0200 |
| commit | dd90d4e122fd1bc40f948809c524cf86d90dc81f (patch) | |
| tree | 8717485819f08785f4e1ae841172de5ab0ecd88c /src | |
| parent | bee4926ae76aa5bba1ab892bfa5db0f75107b1da (diff) | |
| download | rust-dd90d4e122fd1bc40f948809c524cf86d90dc81f.tar.gz rust-dd90d4e122fd1bc40f948809c524cf86d90dc81f.zip | |
Simplify `check_command` while avoiding allocations
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs index c2b943d1d6f..da6e694e879 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs @@ -388,7 +388,7 @@ impl FlycheckActor { package: Option<&str>, saved_file: Option<&AbsPath>, ) -> Option<Command> { - let (mut cmd, args) = match &self.config { + match &self.config { FlycheckConfig::CargoCommand { command, options, ansi_color_output } => { let mut cmd = Command::new(Tool::Cargo.path()); if let Some(sysroot_root) = &self.sysroot_root { @@ -419,7 +419,8 @@ impl FlycheckActor { cmd.arg("--keep-going"); options.apply_on_command(&mut cmd); - (cmd, options.extra_args.clone()) + cmd.args(&options.extra_args); + Some(cmd) } FlycheckConfig::CustomCommand { command, @@ -448,34 +449,31 @@ impl FlycheckActor { } } - if args.contains(&SAVED_FILE_PLACEHOLDER.to_owned()) { - // If the custom command has a $saved_file placeholder, and - // we're saving a file, replace the placeholder in the arguments. - if let Some(saved_file) = saved_file { - let args = args - .iter() - .map(|arg| { - if arg == SAVED_FILE_PLACEHOLDER { - saved_file.to_string() - } else { - arg.clone() - } - }) - .collect(); - (cmd, args) - } else { - // The custom command has a $saved_file placeholder, - // but we had an IDE event that wasn't a file save. Do nothing. - return None; + // If the custom command has a $saved_file placeholder, and + // we're saving a file, replace the placeholder in the arguments. + if let Some(saved_file) = saved_file { + for arg in args { + if arg == SAVED_FILE_PLACEHOLDER { + cmd.arg(saved_file); + } else { + cmd.arg(arg); + } } } else { - (cmd, args.clone()) + for arg in args { + if arg == SAVED_FILE_PLACEHOLDER { + // The custom command has a $saved_file placeholder, + // but we had an IDE event that wasn't a file save. Do nothing. + return None; + } + + cmd.arg(arg); + } } - } - }; - cmd.args(args); - Some(cmd) + Some(cmd) + } + } } fn send(&self, check_task: FlycheckMessage) { |
