diff options
| author | Noah Lev <camelidcamel@gmail.com> | 2021-10-06 10:16:02 -0700 |
|---|---|---|
| committer | Noah Lev <camelidcamel@gmail.com> | 2021-10-12 13:08:32 -0700 |
| commit | 6792c6a8510640dcdf7b6e82dc9c35d39dbf4226 (patch) | |
| tree | 2099032b14d993e17eae6e98149e93eeac069dbd | |
| parent | 9475e609b8458fff9e444934a6017d2e590642cf (diff) | |
| download | rust-6792c6a8510640dcdf7b6e82dc9c35d39dbf4226.tar.gz rust-6792c6a8510640dcdf7b6e82dc9c35d39dbf4226.zip | |
Sort candidate libraries by source path in error
This makes the error output deterministic and thus testable.
| -rw-r--r-- | compiler/rustc_metadata/src/locator.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 9b1ea3b4c4c..f1ada3e1b75 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -910,9 +910,15 @@ impl CrateError { "multiple matching crates for `{}`", crate_name ); + let mut libraries: Vec<_> = libraries.into_values().collect(); + // Make ordering of candidates deterministic. + // This has to `clone()` to work around lifetime restrictions with `sort_by_key()`. + // `sort_by()` could be used instead, but this is in the error path, + // so the performance shouldn't matter. + libraries.sort_by_cached_key(|lib| lib.source.paths().next().unwrap().clone()); let candidates = libraries .iter() - .filter_map(|(_, lib)| { + .filter_map(|lib| { let crate_name = &lib.metadata.get_root().name().as_str(); match (&lib.source.dylib, &lib.source.rlib) { (Some((pd, _)), Some((pr, _))) => Some(format!( |
