-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Include rmeta candidates in "multiple matching crates" error #89587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6792c6a
642a43a
ad49cb6
2e56b6f
cc6a090
bf2d2e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
The compiler found multiple library files with the requested crate name. | ||
|
||
This error can occur in several different cases -- for example, when using | ||
`extern crate` or passing `--extern` options without crate paths. It can also be | ||
caused by caching issues with the build directory, in which case `cargo clean` | ||
may help. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,6 +232,7 @@ use rustc_span::Span; | |
use rustc_target::spec::{Target, TargetTriple}; | ||
|
||
use snap::read::FrameDecoder; | ||
use std::fmt::Write as _; | ||
use std::io::{Read, Result as IoResult, Write}; | ||
use std::path::{Path, PathBuf}; | ||
use std::{cmp, fmt, fs}; | ||
|
@@ -910,23 +911,30 @@ 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)| { | ||
.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!( | ||
"\ncrate `{}`: {}\n{:>padding$}", | ||
crate_name, | ||
pd.display(), | ||
pr.display(), | ||
padding = 8 + crate_name.len() | ||
)), | ||
(Some((p, _)), None) | (None, Some((p, _))) => { | ||
Some(format!("\ncrate `{}`: {}", crate_name, p.display())) | ||
} | ||
(None, None) => None, | ||
let mut paths = lib.source.paths(); | ||
|
||
// This `unwrap()` should be okay because there has to be at least one | ||
// source file. `CrateSource`'s docs confirm that too. | ||
let mut s = format!( | ||
"\ncrate `{}`: {}", | ||
crate_name, | ||
paths.next().unwrap().display() | ||
); | ||
let padding = 8 + crate_name.len(); | ||
|
||
for path in paths { | ||
write!(s, "\n{:>padding$}", path.display(), padding = padding).unwrap(); | ||
} | ||
s | ||
}) | ||
.collect::<String>(); | ||
err.note(&format!("candidates:{}", candidates)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// compile-flags:-C extra-filename=-1 --emit=metadata | ||
#![crate_name = "crateresolve2"] | ||
#![crate_type = "lib"] | ||
|
||
pub fn f() -> isize { 10 } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// compile-flags:-C extra-filename=-2 --emit=metadata | ||
#![crate_name = "crateresolve2"] | ||
#![crate_type = "lib"] | ||
|
||
pub fn f() -> isize { 20 } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// compile-flags:-C extra-filename=-3 --emit=metadata | ||
#![crate_name = "crateresolve2"] | ||
#![crate_type = "lib"] | ||
|
||
pub fn f() -> isize { 30 } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
// dont-check-compiler-stderr | ||
// aux-build:crateresolve1-1.rs | ||
// aux-build:crateresolve1-2.rs | ||
// aux-build:crateresolve1-3.rs | ||
// error-pattern:multiple matching crates for `crateresolve1` | ||
|
||
// normalize-stderr-test: "\.nll/" -> "/" | ||
// normalize-stderr-test: "\\\?\\" -> "" | ||
|
||
// normalize-stderr-test: "(lib)?crateresolve1-([123])\.[a-z]+" -> "libcrateresolve1-$2.somelib" | ||
|
||
// NOTE: This test is duplicated at `src/test/ui/error-codes/E0464.rs`. | ||
|
||
extern crate crateresolve1; | ||
//~^ ERROR multiple matching crates for `crateresolve1` | ||
|
||
fn main() { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0464]: multiple matching crates for `crateresolve1` | ||
--> $DIR/crateresolve1.rs:11:1 | ||
| | ||
LL | extern crate crateresolve1; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: candidates: | ||
crate `crateresolve1`: $TEST_BUILD_DIR/crate-loading/crateresolve1/auxiliary/libcrateresolve1-1.somelib | ||
crate `crateresolve1`: $TEST_BUILD_DIR/crate-loading/crateresolve1/auxiliary/libcrateresolve1-2.somelib | ||
crate `crateresolve1`: $TEST_BUILD_DIR/crate-loading/crateresolve1/auxiliary/libcrateresolve1-3.somelib | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0464`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// check-fail | ||
|
||
// aux-build:crateresolve2-1.rs | ||
// aux-build:crateresolve2-2.rs | ||
// aux-build:crateresolve2-3.rs | ||
|
||
// normalize-stderr-test: "\.nll/" -> "/" | ||
// normalize-stderr-test: "\\\?\\" -> "" | ||
|
||
extern crate crateresolve2; | ||
//~^ ERROR multiple matching crates for `crateresolve2` | ||
|
||
fn main() { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0464]: multiple matching crates for `crateresolve2` | ||
--> $DIR/crateresolve2.rs:10:1 | ||
| | ||
LL | extern crate crateresolve2; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= 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 | ||
|
||
For more information about this error, try `rustc --explain E0464`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// aux-build:crateresolve1-1.rs | ||
// aux-build:crateresolve1-2.rs | ||
// aux-build:crateresolve1-3.rs | ||
|
||
// normalize-stderr-test: "\.nll/" -> "/" | ||
// normalize-stderr-test: "\\\?\\" -> "" | ||
// normalize-stderr-test: "(lib)?crateresolve1-([123])\.[a-z]+" -> "libcrateresolve1-$2.somelib" | ||
|
||
// NOTE: This test is duplicated from `src/test/ui/crate-loading/crateresolve1.rs`. | ||
|
||
extern crate crateresolve1; | ||
//~^ ERROR multiple matching crates for `crateresolve1` | ||
|
||
fn main() { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0464]: multiple matching crates for `crateresolve1` | ||
--> $DIR/E0464.rs:11:1 | ||
| | ||
LL | extern crate crateresolve1; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: candidates: | ||
crate `crateresolve1`: $TEST_BUILD_DIR/error-codes/E0464/auxiliary/libcrateresolve1-1.somelib | ||
crate `crateresolve1`: $TEST_BUILD_DIR/error-codes/E0464/auxiliary/libcrateresolve1-2.somelib | ||
crate `crateresolve1`: $TEST_BUILD_DIR/error-codes/E0464/auxiliary/libcrateresolve1-3.somelib | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0464`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// compile-flags:-C extra-filename=-1 | ||
#![crate_name = "crateresolve1"] | ||
#![crate_type = "lib"] | ||
|
||
pub fn f() -> isize { 10 } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// compile-flags:-C extra-filename=-2 | ||
#![crate_name = "crateresolve1"] | ||
#![crate_type = "lib"] | ||
|
||
pub fn f() -> isize { 20 } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// compile-flags:-C extra-filename=-3 | ||
#![crate_name = "crateresolve1"] | ||
#![crate_type = "lib"] | ||
|
||
pub fn f() -> isize { 30 } | ||
petrochenkov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.