From 49afea0dfa993b2f05aed4db3cd53195021e9871 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Wed, 10 Jan 2024 17:13:03 +0200 Subject: [PATCH] Format sources into the error message when loading codegen backends cc https://github.com/rust-lang/rustc_codegen_cranelift/issues/1447 --- compiler/rustc_interface/src/util.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 92a6445ed0916..d0b4d18b68810 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -163,13 +163,17 @@ pub(crate) fn run_in_thread_pool_with_globals R + Send, R: Send>( fn load_backend_from_dylib(early_dcx: &EarlyDiagCtxt, path: &Path) -> MakeBackendFn { let lib = unsafe { Library::new(path) }.unwrap_or_else(|err| { - let err = format!("couldn't load codegen backend {path:?}: {err}"); + let err = err.sources().fold(String::new(), |s, c| write!(s, ": {}", c).unwrap()); + let err = format!("couldn't load codegen backend {path:?}{err}"); early_dcx.early_fatal(err); }); let backend_sym = unsafe { lib.get::(b"__rustc_codegen_backend") } .unwrap_or_else(|e| { - let err = format!("couldn't load codegen backend: {e}"); + let err = err.sources().fold(String::new(), |s, c| write!(s, ": {}", c).unwrap()); + let err = format!( + "`__rustc_codegen_backend` symbol lookup in the codegen backend failed: {err}" + ); early_dcx.early_fatal(err); });