Skip to content

Commit 66ed181

Browse files
committed
docs/test: add UI test and long-form error docs for E0462
1 parent d6da428 commit 66ed181

File tree

6 files changed

+63
-3
lines changed

6 files changed

+63
-3
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ E0457: include_str!("./error_codes/E0457.md"),
244244
E0458: include_str!("./error_codes/E0458.md"),
245245
E0459: include_str!("./error_codes/E0459.md"),
246246
E0460: include_str!("./error_codes/E0460.md"),
247+
E0462: include_str!("./error_codes/E0462.md"),
247248
E0463: include_str!("./error_codes/E0463.md"),
248249
E0464: include_str!("./error_codes/E0464.md"),
249250
E0466: include_str!("./error_codes/E0466.md"),
@@ -594,7 +595,6 @@ E0791: include_str!("./error_codes/E0791.md"),
594595
// E0427, // merged into 530
595596
// E0456, // plugin `..` is not available for triple `..`
596597
E0461, // couldn't find crate `..` with expected target triple ..
597-
E0462, // found staticlib `..` instead of rlib or dylib
598598
E0465, // multiple .. candidates for `..` found
599599
// E0467, // removed
600600
// E0470, // removed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Found `staticlib` `..` instead of `rlib` or `dylib`.
2+
3+
Consider the following two files:
4+
5+
`a.rs`
6+
```ignore (cannot-link-with-other-tests)
7+
#![crate_type = "staticlib"]
8+
9+
fn foo() {}
10+
```
11+
12+
`main.rs`
13+
```ignore (cannot-link-with-other-tests)
14+
extern crate a;
15+
16+
fn main() {
17+
a::foo();
18+
}
19+
```
20+
21+
Crate `a` is compiled as a `staticlib`. A `staticlib` is a system-dependant
22+
library only intended for linking with non-Rust applications (C programs). Note
23+
that `staticlib`s include all upstream dependencies (`core`, `std`, other user
24+
dependencies, etc) which makes them significantly larger than `dylib`s:
25+
prefer `staticlib` for linking with C programs. Learn more about different
26+
`crate_type`s in [this section of the Reference](../reference/linkage.html).
27+
28+
This error can be fixed by:
29+
* Using [Cargo](../cargo/index.html), the Rust package manager, automatically
30+
fixing this issue.
31+
* Recompiling the crate as a `rlib` or `dylib`; formats suitable for Rust
32+
linking.

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

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// aux-build:found-staticlib.rs
2+
3+
// normalize-stderr-test: "\.nll/" -> "/"
4+
// normalize-stderr-test: "\\\?\\" -> ""
5+
// normalize-stderr-test: "(lib)?found_staticlib\.[a-z]+" -> "libfound_staticlib.somelib"
6+
7+
extern crate found_staticlib; //~ ERROR E0462
8+
9+
fn main() {
10+
found_staticlib::foo();
11+
}

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

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0462]: found staticlib `found_staticlib` instead of rlib or dylib
2+
--> $DIR/E0462.rs:7:1
3+
|
4+
LL | extern crate found_staticlib;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: the following crate versions were found:
8+
crate `found_staticlib`: $TEST_BUILD_DIR/error-codes/E0462/auxiliary/libfound_staticlib.somelib
9+
= help: please recompile that crate using --crate-type lib
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0462`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// no-prefer-dynamic
2+
#![crate_type = "staticlib"]
3+
4+
pub fn foo() {}

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", "E0462", "E0465", "E0476", "E0490", "E0514", "E0519", "E0523", "E0554",
15-
"E0640", "E0717", "E0729", "E0789",
14+
"E0313", "E0461", "E0465", "E0476", "E0490", "E0514", "E0519", "E0523", "E0554", "E0640",
15+
"E0717", "E0729", "E0789",
1616
];
1717

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

0 commit comments

Comments
 (0)