Skip to content

Commit 51534b8

Browse files
authored
Rollup merge of #106236 - Ezrashaw:add-test+docs-e0519-e0514, r=GuillaumeGomez
docs/test: add docs and a UI test for `E0514` and `E0519` No UI test on `E0514`, it would need to compile with a different `rustc` version. r? `@GuillaumeGomez`
2 parents 0e953ed + 726519d commit 51534b8

File tree

6 files changed

+94
-4
lines changed

6 files changed

+94
-4
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,12 @@ E0509: include_str!("./error_codes/E0509.md"),
276276
E0510: include_str!("./error_codes/E0510.md"),
277277
E0511: include_str!("./error_codes/E0511.md"),
278278
E0512: include_str!("./error_codes/E0512.md"),
279+
E0514: include_str!("./error_codes/E0514.md"),
279280
E0515: include_str!("./error_codes/E0515.md"),
280281
E0516: include_str!("./error_codes/E0516.md"),
281282
E0517: include_str!("./error_codes/E0517.md"),
282283
E0518: include_str!("./error_codes/E0518.md"),
284+
E0519: include_str!("./error_codes/E0519.md"),
283285
E0520: include_str!("./error_codes/E0520.md"),
284286
E0521: include_str!("./error_codes/E0521.md"),
285287
E0522: include_str!("./error_codes/E0522.md"),
@@ -615,8 +617,6 @@ E0791: include_str!("./error_codes/E0791.md"),
615617
// E0488, // lifetime of variable does not enclose its declaration
616618
// E0489, // type/lifetime parameter not in scope here
617619
E0490, // a value of type `..` is borrowed for too long
618-
E0514, // metadata version mismatch
619-
E0519, // local crate and dependency have same (crate-name, disambiguator)
620620
E0523, // two dependencies have same (crate-name, disambiguator) but different SVH
621621
// E0526, // shuffle indices are not constant
622622
// E0540, // multiple rustc_deprecated attributes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Dependency compiled with different version of `rustc`.
2+
3+
Example of erroneous code:
4+
5+
`a.rs`
6+
```ignore (cannot-link-with-other-tests)
7+
// compiled with stable `rustc`
8+
9+
#[crate_type = "lib"]
10+
```
11+
12+
`b.rs`
13+
```ignore (cannot-link-with-other-tests)
14+
// compiled with nightly `rustc`
15+
16+
#[crate_type = "lib"]
17+
18+
extern crate a; // error: found crate `a` compiled by an incompatible version
19+
// of rustc
20+
```
21+
22+
This error is caused when the version of `rustc` used to compile a crate, as
23+
stored in the binary's metadata, differs from the version of one of its
24+
dependencies. Many parts of Rust binaries are considered unstable. For
25+
instance, the Rust ABI is not stable between compiler versions. This means that
26+
the compiler cannot be sure about *how* to call a function between compiler
27+
versions, and therefore this error occurs.
28+
29+
This error can be fixed by:
30+
* Using [Cargo](../cargo/index.html), the Rust package manager and
31+
[Rustup](https://rust-lang.github.io/rustup/), the Rust toolchain installer,
32+
automatically fixing this issue.
33+
* Recompiling the crates with a uniform `rustc` version.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
The current crate is indistinguishable from one of its dependencies, in terms
2+
of metadata.
3+
4+
Example of erroneous code:
5+
6+
`a.rs`
7+
```ignore (cannot-link-with-other-tests)
8+
#![crate_name = "a"]
9+
#![crate_type = "lib"]
10+
11+
pub fn foo() {}
12+
```
13+
14+
`b.rs`
15+
```ignore (cannot-link-with-other-tests)
16+
#![crate_name = "a"]
17+
#![crate_type = "lib"]
18+
19+
// error: the current crate is indistinguishable from one of its dependencies:
20+
// it has the same crate-name `a` and was compiled with the same
21+
// `-C metadata` arguments. This will result in symbol conflicts between
22+
// the two.
23+
extern crate a;
24+
25+
pub fn foo() {}
26+
27+
fn bar() {
28+
a::foo(); // is this calling the local crate or the dependency?
29+
}
30+
```
31+
32+
The above example compiles two crates with exactly the same name and
33+
`crate_type` (plus any other metadata). This causes an error because it becomes
34+
impossible for the compiler to distinguish between symbols (`pub` item names).
35+
36+
This error can be fixed by:
37+
* Using [Cargo](../cargo/index.html), the Rust package manager, automatically
38+
fixing this issue.
39+
* Recompiling the crate with different metadata (different name/
40+
`crate_type`).

src/test/ui/error-codes/E0519.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// no need to create a new aux file, we can use an existing.
2+
// aux-build: crateresolve1-1.rs
3+
4+
// set same metadata as `crateresolve1`
5+
#![crate_name = "crateresolve1"]
6+
#![crate_type = "lib"]
7+
8+
extern crate crateresolve1; //~ ERROR E0519

src/test/ui/error-codes/E0519.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
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.
2+
--> $DIR/E0519.rs:8:1
3+
|
4+
LL | extern crate crateresolve1;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0519`.

src/tools/tidy/src/error_codes_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use regex::Regex;
1111

1212
// A few of those error codes can't be tested but all the others can and *should* be tested!
1313
const EXEMPTED_FROM_TEST: &[&str] = &[
14-
"E0313", "E0461", "E0465", "E0476", "E0490", "E0514", "E0519", "E0523", "E0554", "E0640",
15-
"E0717", "E0729", "E0789",
14+
"E0313", "E0461", "E0465", "E0476", "E0490", "E0514", "E0523", "E0554", "E0640", "E0717",
15+
"E0729", "E0789",
1616
];
1717

1818
// Some error codes don't have any tests apparently...

0 commit comments

Comments
 (0)