Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix --extern library finding errors #104621

Merged
merged 5 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_error_messages/locales/en-US/metadata.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ pub struct CrateLocationUnknownType<'a> {
#[primary_span]
pub span: Span,
pub path: &'a Path,
pub crate_name: Symbol,
}

#[derive(Diagnostic)]
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
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
YC marked this conversation as resolved.
Show resolved Hide resolved
--> $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