mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-31 17:12:53 +00:00
Rollup merge of #121978 - GuillaumeGomez:dylib-duplicated-path, r=bjorn3
Fix duplicated path in the "not found dylib" error While working on the gcc backend, I couldn't figure out why I had this error: ``` error: couldn't load codegen backend /checkout/compiler/rustc_codegen_gcc/target/release/librustc_codegen_gcc.so/checkout/compiler/rustc_codegen_gcc/target/release/librustc_codegen_gcc.so: cannot open shared object file: No such file or directory ``` As you can see, the path is duplicated for some reason. After investigating a bit more, I realized that `libloading::Error::LoadLibraryExW` starts with the path of the not found dylib, making it appear twice in our error afterward (because we do render it like this: `{path}{err}`, and since the `err` starts with the path...). Thanks to `````@bjorn3````` for linking me to https://github.com/rust-lang/rust/pull/121392. :)
This commit is contained in:
commit
f5ff6d5ae5
@ -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);
|
||||
|
7
tests/ui/codegen/duplicated-path-in-error.rs
Normal file
7
tests/ui/codegen/duplicated-path-in-error.rs
Normal file
@ -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
tests/ui/codegen/duplicated-path-in-error.stderr
Normal file
2
tests/ui/codegen/duplicated-path-in-error.stderr
Normal file
@ -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…
Reference in New Issue
Block a user