Skip to content

Commit 54b6292

Browse files
authored
Rollup merge of #104621 - YC:master, r=davidtwco
Fix --extern library finding errors - `crate_name` is not specified/passed to `metadata_crate_location_unknown_type` https://github.com/rust-lang/rust/blob/c493bae0d8efd75723460ce5c371f726efa93f15/compiler/rustc_error_messages/locales/en-US/metadata.ftl#L274-L275 - `metadata_lib_filename_form` is missing `$` - Add additional check to ensure that library is file Testing 1. Create file `a.rs` ```rust extern crate t; fn main() {} ``` 1. Create empty file `x` 1. Create empty directory `y` 1. Run ```sh $ rustc -o a a.rs --extern t=x $ rustc -o a a.rs --extern t=y ``` Both currently panic with stable.
2 parents 36815c6 + 7169c7d commit 54b6292

File tree

7 files changed

+50
-3
lines changed

7 files changed

+50
-3
lines changed

compiler/rustc_error_messages/locales/en-US/metadata.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ metadata_crate_location_unknown_type =
275275
extern location for {$crate_name} is of an unknown type: {$path}
276276
277277
metadata_lib_filename_form =
278-
file name should be lib*.rlib or {dll_prefix}*.{dll_suffix}
278+
file name should be lib*.rlib or {$dll_prefix}*{$dll_suffix}
279279
280280
metadata_multiple_import_name_type =
281281
multiple `import_name_type` arguments in a single `#[link]` attribute

compiler/rustc_metadata/src/errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ pub struct CrateLocationUnknownType<'a> {
692692
#[primary_span]
693693
pub span: Span,
694694
pub path: &'a Path,
695+
pub crate_name: Symbol,
695696
}
696697

697698
#[derive(Diagnostic)]

compiler/rustc_metadata/src/locator.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,12 @@ impl<'a> CrateLocator<'a> {
707707
loc.original().clone(),
708708
));
709709
}
710+
if !loc.original().is_file() {
711+
return Err(CrateError::ExternLocationNotFile(
712+
self.crate_name,
713+
loc.original().clone(),
714+
));
715+
}
710716
let Some(file) = loc.original().file_name().and_then(|s| s.to_str()) else {
711717
return Err(CrateError::ExternLocationNotFile(
712718
self.crate_name,
@@ -1020,11 +1026,10 @@ impl CrateError {
10201026
None => String::new(),
10211027
Some(r) => format!(" which `{}` depends on", r.name),
10221028
};
1023-
// FIXME: There are no tests for CrateLocationUnknownType or LibFilenameForm
10241029
if !locator.crate_rejections.via_filename.is_empty() {
10251030
let mismatches = locator.crate_rejections.via_filename.iter();
10261031
for CrateMismatch { path, .. } in mismatches {
1027-
sess.emit_err(CrateLocationUnknownType { span, path: &path });
1032+
sess.emit_err(CrateLocationUnknownType { span, path: &path, crate_name });
10281033
sess.emit_err(LibFilenameForm {
10291034
span,
10301035
dll_prefix: &locator.dll_prefix,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// compile-flags: --extern foo={{src-base}}/errors/issue-104621-extern-bad-file.rs
2+
// only-linux
3+
4+
extern crate foo;
5+
//~^ ERROR extern location for foo is of an unknown type
6+
//~| ERROR file name should be lib*.rlib or lib*.so
7+
//~| ERROR can't find crate for `foo` [E0463]
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: extern location for foo is of an unknown type: $DIR/issue-104621-extern-bad-file.rs
2+
--> $DIR/issue-104621-extern-bad-file.rs:4:1
3+
|
4+
LL | extern crate foo;
5+
| ^^^^^^^^^^^^^^^^^
6+
7+
error: file name should be lib*.rlib or lib*.so
8+
--> $DIR/issue-104621-extern-bad-file.rs:4:1
9+
|
10+
LL | extern crate foo;
11+
| ^^^^^^^^^^^^^^^^^
12+
13+
error[E0463]: can't find crate for `foo`
14+
--> $DIR/issue-104621-extern-bad-file.rs:4:1
15+
|
16+
LL | extern crate foo;
17+
| ^^^^^^^^^^^^^^^^^ can't find crate
18+
19+
error: aborting due to 3 previous errors
20+
21+
For more information about this error, try `rustc --explain E0463`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// compile-flags: --extern foo=.
2+
3+
extern crate foo; //~ ERROR extern location for foo is not a file: .
4+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: extern location for foo is not a file: .
2+
--> $DIR/issue-104621-extern-not-file.rs:3:1
3+
|
4+
LL | extern crate foo;
5+
| ^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)