Unnamed repository; edit this file 'description' to name the repository.
Simplify `check_command` while avoiding allocations
mo8it 2024-08-10
parent 56f63df · commit cb1c7b3
-rw-r--r--crates/rust-analyzer/src/flycheck.rs50
1 files changed, 24 insertions, 26 deletions
diff --git a/crates/rust-analyzer/src/flycheck.rs b/crates/rust-analyzer/src/flycheck.rs
index c2b943d1d6..da6e694e87 100644
--- a/crates/rust-analyzer/src/flycheck.rs
+++ b/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) {