Skip to content

Commit da7fcc7

Browse files
committed
docs/test: add UI test and long-form error docs for E0519
1 parent 270c94e commit da7fcc7

File tree

5 files changed

+60
-3
lines changed

5 files changed

+60
-3
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ E0515: include_str!("./error_codes/E0515.md"),
280280
E0516: include_str!("./error_codes/E0516.md"),
281281
E0517: include_str!("./error_codes/E0517.md"),
282282
E0518: include_str!("./error_codes/E0518.md"),
283+
E0519: include_str!("./error_codes/E0519.md"),
283284
E0520: include_str!("./error_codes/E0520.md"),
284285
E0521: include_str!("./error_codes/E0521.md"),
285286
E0522: include_str!("./error_codes/E0522.md"),
@@ -616,7 +617,6 @@ E0791: include_str!("./error_codes/E0791.md"),
616617
// E0489, // type/lifetime parameter not in scope here
617618
E0490, // a value of type `..` is borrowed for too long
618619
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,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)