Skip to content
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