From da7fcc7a09c213808134561ce99303b8d559d02b Mon Sep 17 00:00:00 2001 From: Ezra Shaw Date: Wed, 21 Dec 2022 13:48:12 +1300 Subject: [PATCH 1/2] docs/test: add UI test and long-form error docs for `E0519` --- compiler/rustc_error_codes/src/error_codes.rs | 2 +- .../src/error_codes/E0519.md | 40 +++++++++++++++++++ src/test/ui/error-codes/E0519.rs | 8 ++++ src/test/ui/error-codes/E0519.stderr | 9 +++++ src/tools/tidy/src/error_codes_check.rs | 4 +- 5 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0519.md create mode 100644 src/test/ui/error-codes/E0519.rs create mode 100644 src/test/ui/error-codes/E0519.stderr diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index e6d26240e242e..68eac479f9ef8 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -280,6 +280,7 @@ E0515: include_str!("./error_codes/E0515.md"), E0516: include_str!("./error_codes/E0516.md"), E0517: include_str!("./error_codes/E0517.md"), E0518: include_str!("./error_codes/E0518.md"), +E0519: include_str!("./error_codes/E0519.md"), E0520: include_str!("./error_codes/E0520.md"), E0521: include_str!("./error_codes/E0521.md"), E0522: include_str!("./error_codes/E0522.md"), @@ -616,7 +617,6 @@ E0791: include_str!("./error_codes/E0791.md"), // E0489, // type/lifetime parameter not in scope here E0490, // a value of type `..` is borrowed for too long E0514, // metadata version mismatch - E0519, // local crate and dependency have same (crate-name, disambiguator) E0523, // two dependencies have same (crate-name, disambiguator) but different SVH // E0526, // shuffle indices are not constant // E0540, // multiple rustc_deprecated attributes diff --git a/compiler/rustc_error_codes/src/error_codes/E0519.md b/compiler/rustc_error_codes/src/error_codes/E0519.md new file mode 100644 index 0000000000000..12876e2ad75fc --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0519.md @@ -0,0 +1,40 @@ +The current crate is indistinguishable from one of its dependencies, in terms +of metadata. + +Example of erroneous code: + +`a.rs` +```ignore (cannot-link-with-other-tests) +#![crate_name = "a"] +#![crate_type = "lib"] + +pub fn foo() {} +``` + +`b.rs` +```ignore (cannot-link-with-other-tests) +#![crate_name = "a"] +#![crate_type = "lib"] + +// error: the current crate is indistinguishable from one of its dependencies: +// it has the same crate-name `a` and was compiled with the same +// `-C metadata` arguments. This will result in symbol conflicts between +// the two. +extern crate a; + +pub fn foo() {} + +fn bar() { + a::foo(); // is this calling the local crate or the dependency? +} +``` + +The above example compiles two crates with exactly the same name and +`crate_type` (plus any other metadata). This causes an error because it becomes +impossible for the compiler to distinguish between symbols (`pub` item names). + +This error can be fixed by: + * Using [Cargo](../cargo/index.html), the Rust package manager, automatically + fixing this issue. + * Recompiling the crate with different metadata (different name/ + `crate_type`). diff --git a/src/test/ui/error-codes/E0519.rs b/src/test/ui/error-codes/E0519.rs new file mode 100644 index 0000000000000..269ffd6320d9e --- /dev/null +++ b/src/test/ui/error-codes/E0519.rs @@ -0,0 +1,8 @@ +// no need to create a new aux file, we can use an existing. +// aux-build: crateresolve1-1.rs + +// set same metadata as `crateresolve1` +#![crate_name = "crateresolve1"] +#![crate_type = "lib"] + +extern crate crateresolve1; //~ ERROR E0519 diff --git a/src/test/ui/error-codes/E0519.stderr b/src/test/ui/error-codes/E0519.stderr new file mode 100644 index 0000000000000..e24fc4aaa70fb --- /dev/null +++ b/src/test/ui/error-codes/E0519.stderr @@ -0,0 +1,9 @@ +error[E0519]: the current crate is indistinguishable from one of its dependencies: it has the same crate-name `crateresolve1` and was compiled with the same `-C metadata` arguments. This will result in symbol conflicts between the two. + --> $DIR/E0519.rs:8:1 + | +LL | extern crate crateresolve1; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0519`. diff --git a/src/tools/tidy/src/error_codes_check.rs b/src/tools/tidy/src/error_codes_check.rs index 49fc2ceb3a27f..fd870b0997ce0 100644 --- a/src/tools/tidy/src/error_codes_check.rs +++ b/src/tools/tidy/src/error_codes_check.rs @@ -11,8 +11,8 @@ use regex::Regex; // A few of those error codes can't be tested but all the others can and *should* be tested! const EXEMPTED_FROM_TEST: &[&str] = &[ - "E0313", "E0461", "E0465", "E0476", "E0490", "E0514", "E0519", "E0523", "E0554", "E0640", - "E0717", "E0729", "E0789", + "E0313", "E0461", "E0465", "E0476", "E0490", "E0514", "E0523", "E0554", "E0640", "E0717", + "E0729", "E0789", ]; // Some error codes don't have any tests apparently... From 726519d4f5dc8f12783ba873ccae75fce6654c89 Mon Sep 17 00:00:00 2001 From: Ezra Shaw Date: Fri, 23 Dec 2022 13:11:50 +1300 Subject: [PATCH 2/2] docs: add long-form error docs for `E0514` --- compiler/rustc_error_codes/src/error_codes.rs | 2 +- .../src/error_codes/E0514.md | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0514.md diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index 68eac479f9ef8..5a1670f06fc64 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -276,6 +276,7 @@ E0509: include_str!("./error_codes/E0509.md"), E0510: include_str!("./error_codes/E0510.md"), E0511: include_str!("./error_codes/E0511.md"), E0512: include_str!("./error_codes/E0512.md"), +E0514: include_str!("./error_codes/E0514.md"), E0515: include_str!("./error_codes/E0515.md"), E0516: include_str!("./error_codes/E0516.md"), E0517: include_str!("./error_codes/E0517.md"), @@ -616,7 +617,6 @@ E0791: include_str!("./error_codes/E0791.md"), // E0488, // lifetime of variable does not enclose its declaration // E0489, // type/lifetime parameter not in scope here E0490, // a value of type `..` is borrowed for too long - E0514, // metadata version mismatch E0523, // two dependencies have same (crate-name, disambiguator) but different SVH // E0526, // shuffle indices are not constant // E0540, // multiple rustc_deprecated attributes diff --git a/compiler/rustc_error_codes/src/error_codes/E0514.md b/compiler/rustc_error_codes/src/error_codes/E0514.md new file mode 100644 index 0000000000000..ce2bbc5c5056c --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0514.md @@ -0,0 +1,33 @@ +Dependency compiled with different version of `rustc`. + +Example of erroneous code: + +`a.rs` +```ignore (cannot-link-with-other-tests) +// compiled with stable `rustc` + +#[crate_type = "lib"] +``` + +`b.rs` +```ignore (cannot-link-with-other-tests) +// compiled with nightly `rustc` + +#[crate_type = "lib"] + +extern crate a; // error: found crate `a` compiled by an incompatible version + // of rustc +``` + +This error is caused when the version of `rustc` used to compile a crate, as +stored in the binary's metadata, differs from the version of one of its +dependencies. Many parts of Rust binaries are considered unstable. For +instance, the Rust ABI is not stable between compiler versions. This means that +the compiler cannot be sure about *how* to call a function between compiler +versions, and therefore this error occurs. + +This error can be fixed by: + * Using [Cargo](../cargo/index.html), the Rust package manager and + [Rustup](https://rust-lang.github.io/rustup/), the Rust toolchain installer, + automatically fixing this issue. + * Recompiling the crates with a uniform `rustc` version.