Skip to content

Commit ca91401

Browse files
narpfellcnr
authored andcommitted
Fix "local crate" detection
`PackageId` is an opaque identifier whose internal format is subject to change, so looking up the names of local crates by ID is more robust than parsing the ID. Resolves rust-lang#3643.
1 parent 1ec6779 commit ca91401

File tree

1 file changed

+9
-11
lines changed
  • src/tools/miri/cargo-miri/src

1 file changed

+9
-11
lines changed

src/tools/miri/cargo-miri/src/util.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::HashMap;
12
use std::env;
23
use std::ffi::OsString;
34
use std::fs::File;
@@ -233,21 +234,18 @@ pub fn get_cargo_metadata() -> Metadata {
233234
}
234235

235236
/// Pulls all the crates in this workspace from the cargo metadata.
236-
/// Workspace members are emitted like "miri 0.1.0 (path+file:///path/to/miri)"
237237
/// Additionally, somewhere between cargo metadata and TyCtxt, '-' gets replaced with '_' so we
238238
/// make that same transformation here.
239239
pub fn local_crates(metadata: &Metadata) -> String {
240240
assert!(!metadata.workspace_members.is_empty());
241-
let mut local_crates = String::new();
242-
for member in &metadata.workspace_members {
243-
let name = member.repr.split(' ').next().unwrap();
244-
let name = name.replace('-', "_");
245-
local_crates.push_str(&name);
246-
local_crates.push(',');
247-
}
248-
local_crates.pop(); // Remove the trailing ','
249-
250-
local_crates
241+
let package_name_by_id: HashMap<_, _> =
242+
metadata.packages.iter().map(|package| (&package.id, package.name.as_str())).collect();
243+
metadata
244+
.workspace_members
245+
.iter()
246+
.map(|id| package_name_by_id[id].replace('-', "_"))
247+
.collect::<Vec<_>>()
248+
.join(",")
251249
}
252250

253251
/// Debug-print a command that is going to be run.

0 commit comments

Comments
 (0)