Rollup merge of #110932 - sameer:master, r=michaelwoerister

include source error for LoadLibraryExW

In #107595, we added retry behavior for LoadLibraryExW on Windows. If it fails we do not print the underlying error that Windows returned. This made #110889 a little harder to debug.

In this PR I am adding the source error in the message if it is available.
This commit is contained in:
Dylan DPC 2023-04-29 11:27:55 +05:30 committed by GitHub
commit 650f8fddd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,6 +27,7 @@ use rustc_span::{Span, DUMMY_SP};
use rustc_target::spec::{PanicStrategy, TargetTriple};
use proc_macro::bridge::client::ProcMacro;
use std::error::Error;
use std::ops::Fn;
use std::path::Path;
use std::time::Duration;
@ -1094,5 +1095,12 @@ fn load_dylib(path: &Path, max_attempts: usize) -> Result<libloading::Library, S
}
debug!("Failed to load proc-macro `{}` even after {} attempts.", path.display(), max_attempts);
Err(format!("{} (retried {} times)", last_error.unwrap(), max_attempts))
let last_error = last_error.unwrap();
let message = if let Some(src) = last_error.source() {
format!("{last_error} ({src}) (retried {max_attempts} times)")
} else {
format!("{last_error} (retried {max_attempts} times)")
};
Err(message)
}