Skip to content

Commit 6792c6a

Browse files
committed
Sort candidate libraries by source path in error
This makes the error output deterministic and thus testable.
1 parent 9475e60 commit 6792c6a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

compiler/rustc_metadata/src/locator.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,9 +910,15 @@ impl CrateError {
910910
"multiple matching crates for `{}`",
911911
crate_name
912912
);
913+
let mut libraries: Vec<_> = libraries.into_values().collect();
914+
// Make ordering of candidates deterministic.
915+
// This has to `clone()` to work around lifetime restrictions with `sort_by_key()`.
916+
// `sort_by()` could be used instead, but this is in the error path,
917+
// so the performance shouldn't matter.
918+
libraries.sort_by_cached_key(|lib| lib.source.paths().next().unwrap().clone());
913919
let candidates = libraries
914920
.iter()
915-
.filter_map(|(_, lib)| {
921+
.filter_map(|lib| {
916922
let crate_name = &lib.metadata.get_root().name().as_str();
917923
match (&lib.source.dylib, &lib.source.rlib) {
918924
(Some((pd, _)), Some((pr, _))) => Some(format!(

0 commit comments

Comments
 (0)