Auto merge of #17296 - mathew-horner:no-clone-target, r=Veykril

Avoid clone when constructing runnable label.

I stumbled across this when reading this code. This seems like an unnecessary allocation (though likely small?)
This commit is contained in:
bors 2024-05-26 09:11:55 +00:00
commit 71a816a90f
2 changed files with 3 additions and 3 deletions

View file

@ -79,7 +79,7 @@ impl RunnableKind {
impl Runnable { impl Runnable {
// test package::module::testname // test package::module::testname
pub fn label(&self, target: Option<String>) -> String { pub fn label(&self, target: Option<&str>) -> String {
match &self.kind { match &self.kind {
RunnableKind::Test { test_id, .. } => format!("test {test_id}"), RunnableKind::Test { test_id, .. } => format!("test {test_id}"),
RunnableKind::TestMod { path } => format!("test-mod {path}"), RunnableKind::TestMod { path } => format!("test-mod {path}"),

View file

@ -1364,10 +1364,10 @@ pub(crate) fn runnable(
ide::RunnableKind::Bin { .. } => workspace_root.clone().map(|it| it.into()), ide::RunnableKind::Bin { .. } => workspace_root.clone().map(|it| it.into()),
_ => spec.as_ref().map(|it| it.cargo_toml.parent().into()), _ => spec.as_ref().map(|it| it.cargo_toml.parent().into()),
}; };
let target = spec.as_ref().map(|s| s.target.clone()); let target = spec.as_ref().map(|s| s.target.as_str());
let label = runnable.label(target);
let (cargo_args, executable_args) = let (cargo_args, executable_args) =
CargoTargetSpec::runnable_args(snap, spec, &runnable.kind, &runnable.cfg); CargoTargetSpec::runnable_args(snap, spec, &runnable.kind, &runnable.cfg);
let label = runnable.label(target);
let location = location_link(snap, None, runnable.nav)?; let location = location_link(snap, None, runnable.nav)?;
Ok(lsp_ext::Runnable { Ok(lsp_ext::Runnable {