about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorJoshua Nelson <jyn514@gmail.com>2021-08-26 18:37:44 +0000
committerJoshua Nelson <jyn514@gmail.com>2021-11-07 15:03:40 +0000
commit257ac1b4984f261dfe4572907955a24f43eee209 (patch)
tree1d34fc788831e9b5b63a2a5020d29a06935a1094 /src/test/ui
parent90a273b785b3bc482b82c4896ba1bdea68745e46 (diff)
downloadrust-257ac1b4984f261dfe4572907955a24f43eee209.tar.gz
rust-257ac1b4984f261dfe4572907955a24f43eee209.zip
Improve error when an .rlib can't be parsed
This usually describes either an error in the compiler itself or some
sort of IO error. Either way, we should report it to the user rather
than just saying "crate not found".

This only gives an error if the crate couldn't be loaded at all - if the
compiler finds another .rlib or .rmeta file which was valid, it will
continue to compile the crate.

Example output:
```
error[E0785]: found invalid metadata files for crate `foo`
 --> bar.rs:3:24
  |
3 |         println!("{}", foo::FOO_11_49[0]);
  |                        ^^^
  |
  = warning: failed to parse rlib '/home/joshua/test-rustdoc/libfoo.rlib': Invalid archive extended name offset
```
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/crate-loading/auxiliary/libfoo.rlib0
-rw-r--r--src/test/ui/crate-loading/invalid-rlib.rs8
-rw-r--r--src/test/ui/crate-loading/invalid-rlib.stderr11
3 files changed, 19 insertions, 0 deletions
diff --git a/src/test/ui/crate-loading/auxiliary/libfoo.rlib b/src/test/ui/crate-loading/auxiliary/libfoo.rlib
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/src/test/ui/crate-loading/auxiliary/libfoo.rlib
diff --git a/src/test/ui/crate-loading/invalid-rlib.rs b/src/test/ui/crate-loading/invalid-rlib.rs
new file mode 100644
index 00000000000..77c29090a3e
--- /dev/null
+++ b/src/test/ui/crate-loading/invalid-rlib.rs
@@ -0,0 +1,8 @@
+// compile-flags: --crate-type lib --extern foo={{src-base}}/crate-loading/auxiliary/libfoo.rlib
+// normalize-stderr-test: "failed to mmap file '.*auxiliary/libfoo.rlib':.*" -> "failed to mmap file 'auxiliary/libfoo.rlib'"
+// don't emit warn logging, it's basically the same as the errors and it's annoying to normalize
+// rustc-env:RUSTC_LOG=error
+// edition:2018
+#![no_std]
+use ::foo; //~ ERROR invalid metadata files for crate `foo`
+//~| NOTE failed to mmap file
diff --git a/src/test/ui/crate-loading/invalid-rlib.stderr b/src/test/ui/crate-loading/invalid-rlib.stderr
new file mode 100644
index 00000000000..b2c79f742fb
--- /dev/null
+++ b/src/test/ui/crate-loading/invalid-rlib.stderr
@@ -0,0 +1,11 @@
+error[E0786]: found invalid metadata files for crate `foo`
+  --> $DIR/invalid-rlib.rs:7:7
+   |
+LL | use ::foo;
+   |       ^^^
+   |
+   = note: failed to mmap file 'auxiliary/libfoo.rlib'
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0786`.