Skip to content

Commit

Permalink
Rollup merge of #105970 - Ezrashaw:add-docs+test-e0462, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
docs/test: add UI test and long-form error docs for E0462

Another UI test/ docs combo.

r? ``@GuillaumeGomez``
  • Loading branch information
matthiaskrgr committed Dec 23, 2022
2 parents af3e06f + 66ed181 commit e08dd9d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ E0457: include_str!("./error_codes/E0457.md"),
E0458: include_str!("./error_codes/E0458.md"),
E0459: include_str!("./error_codes/E0459.md"),
E0460: include_str!("./error_codes/E0460.md"),
E0462: include_str!("./error_codes/E0462.md"),
E0463: include_str!("./error_codes/E0463.md"),
E0464: include_str!("./error_codes/E0464.md"),
E0466: include_str!("./error_codes/E0466.md"),
Expand Down Expand Up @@ -595,7 +596,6 @@ E0791: include_str!("./error_codes/E0791.md"),
// E0427, // merged into 530
// E0456, // plugin `..` is not available for triple `..`
E0461, // couldn't find crate `..` with expected target triple ..
E0462, // found staticlib `..` instead of rlib or dylib
E0465, // multiple .. candidates for `..` found
// E0467, // removed
// E0470, // removed
Expand Down
32 changes: 32 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0462.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Found `staticlib` `..` instead of `rlib` or `dylib`.

Consider the following two files:

`a.rs`
```ignore (cannot-link-with-other-tests)
#![crate_type = "staticlib"]
fn foo() {}
```

`main.rs`
```ignore (cannot-link-with-other-tests)
extern crate a;
fn main() {
a::foo();
}
```

Crate `a` is compiled as a `staticlib`. A `staticlib` is a system-dependant
library only intended for linking with non-Rust applications (C programs). Note
that `staticlib`s include all upstream dependencies (`core`, `std`, other user
dependencies, etc) which makes them significantly larger than `dylib`s:
prefer `staticlib` for linking with C programs. Learn more about different
`crate_type`s in [this section of the Reference](../reference/linkage.html).

This error can be fixed by:
* Using [Cargo](../cargo/index.html), the Rust package manager, automatically
fixing this issue.
* Recompiling the crate as a `rlib` or `dylib`; formats suitable for Rust
linking.
11 changes: 11 additions & 0 deletions src/test/ui/error-codes/E0462.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// aux-build:found-staticlib.rs

// normalize-stderr-test: "\.nll/" -> "/"
// normalize-stderr-test: "\\\?\\" -> ""
// normalize-stderr-test: "(lib)?found_staticlib\.[a-z]+" -> "libfound_staticlib.somelib"

extern crate found_staticlib; //~ ERROR E0462

fn main() {
found_staticlib::foo();
}
13 changes: 13 additions & 0 deletions src/test/ui/error-codes/E0462.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0462]: found staticlib `found_staticlib` instead of rlib or dylib
--> $DIR/E0462.rs:7:1
|
LL | extern crate found_staticlib;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the following crate versions were found:
crate `found_staticlib`: $TEST_BUILD_DIR/error-codes/E0462/auxiliary/libfound_staticlib.somelib
= help: please recompile that crate using --crate-type lib

error: aborting due to previous error

For more information about this error, try `rustc --explain E0462`.
4 changes: 4 additions & 0 deletions src/test/ui/error-codes/auxiliary/found-staticlib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// no-prefer-dynamic
#![crate_type = "staticlib"]

pub fn foo() {}
4 changes: 2 additions & 2 deletions src/tools/tidy/src/error_codes_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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", "E0462", "E0465", "E0476", "E0490", "E0514", "E0519", "E0523", "E0554",
"E0640", "E0717", "E0729", "E0789",
"E0313", "E0461", "E0465", "E0476", "E0490", "E0514", "E0519", "E0523", "E0554", "E0640",
"E0717", "E0729", "E0789",
];

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

0 comments on commit e08dd9d

Please sign in to comment.