Skip to content

Commit

Permalink
Tests for bad --extern library path and file
Browse files Browse the repository at this point in the history
  • Loading branch information
YC committed Nov 22, 2022
1 parent 395f2b8 commit 7169c7d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
1 change: 0 additions & 1 deletion compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,6 @@ impl CrateError {
None => String::new(),
Some(r) => format!(" which `{}` depends on", r.name),
};
// FIXME: There are no tests for CrateLocationUnknownType or LibFilenameForm
if !locator.crate_rejections.via_filename.is_empty() {
let mismatches = locator.crate_rejections.via_filename.iter();
for CrateMismatch { path, .. } in mismatches {
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/errors/issue-104621-extern-bad-file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// compile-flags: --extern foo={{src-base}}/errors/issue-104621-extern-bad-file.rs
// only-linux

extern crate foo;
//~^ ERROR extern location for foo is of an unknown type
//~| ERROR file name should be lib*.rlib or lib*.so
//~| ERROR can't find crate for `foo` [E0463]
fn main() {}
21 changes: 21 additions & 0 deletions src/test/ui/errors/issue-104621-extern-bad-file.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error: extern location for foo is of an unknown type: $DIR/issue-104621-extern-bad-file.rs
--> $DIR/issue-104621-extern-bad-file.rs:4:1
|
LL | extern crate foo;
| ^^^^^^^^^^^^^^^^^

error: file name should be lib*.rlib or lib*.so
--> $DIR/issue-104621-extern-bad-file.rs:4:1
|
LL | extern crate foo;
| ^^^^^^^^^^^^^^^^^

error[E0463]: can't find crate for `foo`
--> $DIR/issue-104621-extern-bad-file.rs:4:1
|
LL | extern crate foo;
| ^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0463`.
4 changes: 4 additions & 0 deletions src/test/ui/errors/issue-104621-extern-not-file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// compile-flags: --extern foo=.

extern crate foo; //~ ERROR extern location for foo is not a file: .
fn main() {}
8 changes: 8 additions & 0 deletions src/test/ui/errors/issue-104621-extern-not-file.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: extern location for foo is not a file: .
--> $DIR/issue-104621-extern-not-file.rs:3:1
|
LL | extern crate foo;
| ^^^^^^^^^^^^^^^^^

error: aborting due to previous error

0 comments on commit 7169c7d

Please sign in to comment.