Include rmeta candidates in "multiple matching crates" error
Only dylib and rlib candidates were included in the error. I think the reason is that at the time this error was originally implemented, rmeta crate sources were represented different from dylib and rlib sources. I wrote up more detailed analysis in [this comment][1]. The new version of the code is also a bit easier to read and should be more robust to future changes since it uses `CrateSources::paths()`. [1]: https://github.com/rust-lang/rust/pull/88675#issuecomment-935282436
This commit is contained in:
parent
ad49cb6e0c
commit
2e56b6f98e
2 changed files with 18 additions and 13 deletions
|
@ -232,6 +232,7 @@ use rustc_span::Span;
|
||||||
use rustc_target::spec::{Target, TargetTriple};
|
use rustc_target::spec::{Target, TargetTriple};
|
||||||
|
|
||||||
use snap::read::FrameDecoder;
|
use snap::read::FrameDecoder;
|
||||||
|
use std::fmt::Write as _;
|
||||||
use std::io::{Read, Result as IoResult, Write};
|
use std::io::{Read, Result as IoResult, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::{cmp, fmt, fs};
|
use std::{cmp, fmt, fs};
|
||||||
|
@ -918,21 +919,22 @@ impl CrateError {
|
||||||
libraries.sort_by_cached_key(|lib| lib.source.paths().next().unwrap().clone());
|
libraries.sort_by_cached_key(|lib| lib.source.paths().next().unwrap().clone());
|
||||||
let candidates = libraries
|
let candidates = libraries
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|lib| {
|
.map(|lib| {
|
||||||
let crate_name = &lib.metadata.get_root().name().as_str();
|
let crate_name = &lib.metadata.get_root().name().as_str();
|
||||||
match (&lib.source.dylib, &lib.source.rlib) {
|
let mut paths = lib.source.paths();
|
||||||
(Some((pd, _)), Some((pr, _))) => Some(format!(
|
|
||||||
"\ncrate `{}`: {}\n{:>padding$}",
|
// This `unwrap()` should be okay because there has to be at least one
|
||||||
crate_name,
|
// source file. `CrateSource`'s docs confirm that too.
|
||||||
pd.display(),
|
let mut s = format!(
|
||||||
pr.display(),
|
"\ncrate `{}`: {}",
|
||||||
padding = 8 + crate_name.len()
|
crate_name,
|
||||||
)),
|
paths.next().unwrap().display()
|
||||||
(Some((p, _)), None) | (None, Some((p, _))) => {
|
);
|
||||||
Some(format!("\ncrate `{}`: {}", crate_name, p.display()))
|
let padding = 8 + crate_name.len();
|
||||||
}
|
for path in paths {
|
||||||
(None, None) => None,
|
write!(s, "\n{:>padding$}", path.display(), padding = padding).unwrap();
|
||||||
}
|
}
|
||||||
|
s
|
||||||
})
|
})
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
err.note(&format!("candidates:{}", candidates));
|
err.note(&format!("candidates:{}", candidates));
|
||||||
|
|
|
@ -5,6 +5,9 @@ LL | extern crate crateresolve2;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: candidates:
|
= note: candidates:
|
||||||
|
crate `crateresolve2`: $TEST_BUILD_DIR/crate-loading/crateresolve2/auxiliary/libcrateresolve2-1.rmeta
|
||||||
|
crate `crateresolve2`: $TEST_BUILD_DIR/crate-loading/crateresolve2/auxiliary/libcrateresolve2-2.rmeta
|
||||||
|
crate `crateresolve2`: $TEST_BUILD_DIR/crate-loading/crateresolve2/auxiliary/libcrateresolve2-3.rmeta
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue