about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_error_messages/locales/en-US/metadata.ftl2
-rw-r--r--compiler/rustc_metadata/src/errors.rs1
-rw-r--r--compiler/rustc_metadata/src/locator.rs9
-rw-r--r--src/test/ui/errors/issue-104621-extern-bad-file.rs8
-rw-r--r--src/test/ui/errors/issue-104621-extern-bad-file.stderr21
-rw-r--r--src/test/ui/errors/issue-104621-extern-not-file.rs4
-rw-r--r--src/test/ui/errors/issue-104621-extern-not-file.stderr8
7 files changed, 50 insertions, 3 deletions
diff --git a/compiler/rustc_error_messages/locales/en-US/metadata.ftl b/compiler/rustc_error_messages/locales/en-US/metadata.ftl
index c292ae9b32a..d1e1fd54db9 100644
--- a/compiler/rustc_error_messages/locales/en-US/metadata.ftl
+++ b/compiler/rustc_error_messages/locales/en-US/metadata.ftl
@@ -275,7 +275,7 @@ metadata_crate_location_unknown_type =
     extern location for {$crate_name} is of an unknown type: {$path}
 
 metadata_lib_filename_form =
-    file name should be lib*.rlib or {dll_prefix}*.{dll_suffix}
+    file name should be lib*.rlib or {$dll_prefix}*{$dll_suffix}
 
 metadata_multiple_import_name_type =
     multiple `import_name_type` arguments in a single `#[link]` attribute
diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs
index e5b91d566e5..6f7e6e09ca5 100644
--- a/compiler/rustc_metadata/src/errors.rs
+++ b/compiler/rustc_metadata/src/errors.rs
@@ -692,6 +692,7 @@ pub struct CrateLocationUnknownType<'a> {
     #[primary_span]
     pub span: Span,
     pub path: &'a Path,
+    pub crate_name: Symbol,
 }
 
 #[derive(Diagnostic)]
diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs
index 35f9ef92a1c..15546092e41 100644
--- a/compiler/rustc_metadata/src/locator.rs
+++ b/compiler/rustc_metadata/src/locator.rs
@@ -707,6 +707,12 @@ impl<'a> CrateLocator<'a> {
                     loc.original().clone(),
                 ));
             }
+            if !loc.original().is_file() {
+                return Err(CrateError::ExternLocationNotFile(
+                    self.crate_name,
+                    loc.original().clone(),
+                ));
+            }
             let Some(file) = loc.original().file_name().and_then(|s| s.to_str()) else {
                 return Err(CrateError::ExternLocationNotFile(
                     self.crate_name,
@@ -1020,11 +1026,10 @@ 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 {
-                        sess.emit_err(CrateLocationUnknownType { span, path: &path });
+                        sess.emit_err(CrateLocationUnknownType { span, path: &path, crate_name });
                         sess.emit_err(LibFilenameForm {
                             span,
                             dll_prefix: &locator.dll_prefix,
diff --git a/src/test/ui/errors/issue-104621-extern-bad-file.rs b/src/test/ui/errors/issue-104621-extern-bad-file.rs
new file mode 100644
index 00000000000..3f13d605232
--- /dev/null
+++ b/src/test/ui/errors/issue-104621-extern-bad-file.rs
@@ -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() {}
diff --git a/src/test/ui/errors/issue-104621-extern-bad-file.stderr b/src/test/ui/errors/issue-104621-extern-bad-file.stderr
new file mode 100644
index 00000000000..b8500ad0e04
--- /dev/null
+++ b/src/test/ui/errors/issue-104621-extern-bad-file.stderr
@@ -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`.
diff --git a/src/test/ui/errors/issue-104621-extern-not-file.rs b/src/test/ui/errors/issue-104621-extern-not-file.rs
new file mode 100644
index 00000000000..899e45a306b
--- /dev/null
+++ b/src/test/ui/errors/issue-104621-extern-not-file.rs
@@ -0,0 +1,4 @@
+// compile-flags: --extern foo=.
+
+extern crate foo; //~ ERROR extern location for foo is not a file: .
+fn main() {}
diff --git a/src/test/ui/errors/issue-104621-extern-not-file.stderr b/src/test/ui/errors/issue-104621-extern-not-file.stderr
new file mode 100644
index 00000000000..5aaf9741360
--- /dev/null
+++ b/src/test/ui/errors/issue-104621-extern-not-file.stderr
@@ -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
+