From 640e99ccc982586352b1ad94c350af3cbeff3c2e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 4 Mar 2024 14:30:46 +0100 Subject: [PATCH 1/2] Fix duplicated path in the "not found dylib" error --- compiler/rustc_metadata/src/creader.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index f65fe1a29c7cc..564c35f881d60 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -1132,7 +1132,13 @@ fn load_dylib(path: &Path, max_attempts: usize) -> Result { // 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); From 5e6e140b0cf44079cd0f42ba8bfcbf874859dd68 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 4 Mar 2024 14:31:23 +0100 Subject: [PATCH 2/2] Add regression ui test for duplicated path in dylib error --- tests/ui/codegen/duplicated-path-in-error.rs | 7 +++++++ tests/ui/codegen/duplicated-path-in-error.stderr | 2 ++ 2 files changed, 9 insertions(+) create mode 100644 tests/ui/codegen/duplicated-path-in-error.rs create mode 100644 tests/ui/codegen/duplicated-path-in-error.stderr diff --git a/tests/ui/codegen/duplicated-path-in-error.rs b/tests/ui/codegen/duplicated-path-in-error.rs new file mode 100644 index 0000000000000..cff20dd9bd639 --- /dev/null +++ b/tests/ui/codegen/duplicated-path-in-error.rs @@ -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() {} diff --git a/tests/ui/codegen/duplicated-path-in-error.stderr b/tests/ui/codegen/duplicated-path-in-error.stderr new file mode 100644 index 0000000000000..d0d34e2f93468 --- /dev/null +++ b/tests/ui/codegen/duplicated-path-in-error.stderr @@ -0,0 +1,2 @@ +error: couldn't load codegen backend /non-existing-one.so: cannot open shared object file: No such file or directory +