Skip to content

Commit f7ca8a6

Browse files
committed
Auto merge of rust-lang#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?)
2 parents bd9cc02 + afa8dfc commit f7ca8a6

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/tools/rust-analyzer/crates/ide/src/runnables.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl RunnableKind {
7979

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

src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1364,10 +1364,10 @@ pub(crate) fn runnable(
13641364
ide::RunnableKind::Bin { .. } => workspace_root.clone().map(|it| it.into()),
13651365
_ => spec.as_ref().map(|it| it.cargo_toml.parent().into()),
13661366
};
1367-
let target = spec.as_ref().map(|s| s.target.clone());
1367+
let target = spec.as_ref().map(|s| s.target.as_str());
1368+
let label = runnable.label(target);
13681369
let (cargo_args, executable_args) =
13691370
CargoTargetSpec::runnable_args(snap, spec, &runnable.kind, &runnable.cfg);
1370-
let label = runnable.label(target);
13711371
let location = location_link(snap, None, runnable.nav)?;
13721372

13731373
Ok(lsp_ext::Runnable {

0 commit comments

Comments
 (0)