about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-11-07 23:03:55 +0000
committerbors <bors@rust-lang.org>2021-11-07 23:03:55 +0000
commit5fa94f3c57e27a339bc73336cd260cd875026bd1 (patch)
tree954a45648f2857e5756b415597887efae27d7593 /src
parent46b8e7488eae116722196e8390c1bd2ea2e396cf (diff)
parent257ac1b4984f261dfe4572907955a24f43eee209 (diff)
downloadrust-5fa94f3c57e27a339bc73336cd260cd875026bd1.tar.gz
rust-5fa94f3c57e27a339bc73336cd260cd875026bd1.zip
Auto merge of #88368 - jyn514:metadata-error, r=petrochenkov
 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
```

cc `@ehuss`
Diffstat (limited to 'src')
-rw-r--r--src/test/run-make-fulldeps/invalid-library/Makefile2
-rw-r--r--src/test/run-make/invalid-so/Makefile7
-rw-r--r--src/test/run-make/invalid-so/bar.rs1
-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
6 files changed, 28 insertions, 1 deletions
diff --git a/src/test/run-make-fulldeps/invalid-library/Makefile b/src/test/run-make-fulldeps/invalid-library/Makefile
index c75713c3ee5..de463a33014 100644
--- a/src/test/run-make-fulldeps/invalid-library/Makefile
+++ b/src/test/run-make-fulldeps/invalid-library/Makefile
@@ -3,4 +3,4 @@
 all:
 	touch $(TMPDIR)/lib.rmeta
 	$(AR) crus $(TMPDIR)/libfoo-ffffffff-1.0.rlib $(TMPDIR)/lib.rmeta
-	$(RUSTC) foo.rs 2>&1 | $(CGREP) "can't find crate for"
+	$(RUSTC) foo.rs 2>&1 | $(CGREP) "found invalid metadata"
diff --git a/src/test/run-make/invalid-so/Makefile b/src/test/run-make/invalid-so/Makefile
new file mode 100644
index 00000000000..5b82ecd207d
--- /dev/null
+++ b/src/test/run-make/invalid-so/Makefile
@@ -0,0 +1,7 @@
+include ../../run-make-fulldeps/tools.mk
+
+DYLIB_NAME := $(shell echo | $(RUSTC) --crate-name foo --crate-type dylib --print file-names -)
+
+all:
+	echo >> $(TMPDIR)/$(DYLIB_NAME)
+	$(RUSTC) --crate-type lib --extern foo=$(TMPDIR)/$(DYLIB_NAME) bar.rs 2>&1 | $(CGREP) 'invalid metadata files for crate `foo`'
diff --git a/src/test/run-make/invalid-so/bar.rs b/src/test/run-make/invalid-so/bar.rs
new file mode 100644
index 00000000000..49af74e1b74
--- /dev/null
+++ b/src/test/run-make/invalid-so/bar.rs
@@ -0,0 +1 @@
+extern crate foo;
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`.