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 duplicated path in the "not found dylib" error #121978

Merged
merged 2 commits into from
Mar 6, 2024
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
8 changes: 7 additions & 1 deletion compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,13 @@ fn load_dylib(path: &Path, max_attempts: usize) -> Result<libloading::Library, S
Err(err) => {
// Only try to recover from this specific error.
if !matches!(err, libloading::Error::LoadLibraryExW { .. }) {
return Err(err.to_string());
let err = format_dlopen_err(&err);
// We include the path of the dylib in the error ourselves, so
// if it's in the error, we strip it.
if let Some(err) = err.strip_prefix(&format!(": {}", path.display())) {
return Err(err.to_string());
}
return Err(err);
}

last_error = Some(err);
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/codegen/duplicated-path-in-error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@ only-linux
//@ compile-flags: -Zcodegen-backend=/non-existing-one.so

// This test ensures that the error of the "not found dylib" doesn't duplicate
// the path of the dylib.

fn main() {}
2 changes: 2 additions & 0 deletions tests/ui/codegen/duplicated-path-in-error.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: couldn't load codegen backend /non-existing-one.so: cannot open shared object file: No such file or directory

Loading