diff --git a/compiler/rustc_codegen_llvm/src/diagnostics.rs b/compiler/rustc_codegen_llvm/src/diagnostics.rs index 54f8ffbb881da..fb43b36fe39b9 100644 --- a/compiler/rustc_codegen_llvm/src/diagnostics.rs +++ b/compiler/rustc_codegen_llvm/src/diagnostics.rs @@ -1,4 +1,4 @@ -use std::ffi::CString; +use std::ffi::{CString, c_uint}; use std::path::Path; use rustc_data_structures::small_c_str::SmallCStr; @@ -265,3 +265,15 @@ pub(crate) struct IntrinsicWrongArch<'a> { pub(crate) struct UnknownLlvmTargetFeaturePrefix<'a> { pub feature: &'a str, } + +#[derive(Diagnostic)] +#[diag( + "LLVM version mismatch: this compiler was built for LLVM {$expected_version}, but LLVM {$llvm_major}.{$llvm_minor}.{$llvm_patch} was found{$dll_loc}" +)] +pub(crate) struct LlvmVersionMismatch<'a> { + pub expected_version: c_uint, + pub llvm_major: c_uint, + pub llvm_minor: c_uint, + pub llvm_patch: c_uint, + pub dll_loc: &'a str, +} diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 9819699ca5228..82ddcca3e1530 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -56,20 +56,17 @@ unsafe fn configure_llvm(sess: &Session) { llvm::LLVMGetVersion(&mut llvm_major, &mut llvm_minor, &mut llvm_patch); let expected_version = llvm::LLVMRustVersionMajor(); if llvm_major != expected_version { - panic!( - concat!( - "LLVM version mismatch: this compiler was built for LLVM {}, ", - "but LLVM {}.{}.{} was found{}" - ), + sess.dcx().emit_fatal(diagnostics::LlvmVersionMismatch { expected_version, llvm_major, llvm_minor, llvm_patch, - match rustc_session::filesearch::dll_path(llvm::LLVMGetVersion as *mut _) { + dll_loc: &match rustc_session::filesearch::dll_path(llvm::LLVMGetVersion as *mut _) + { Ok(path) => format!(" at {}", path.display()), Err(_) => String::new(), - } - ); + }, + }) } } diff --git a/compiler/rustc_macros/src/diagnostics/message.rs b/compiler/rustc_macros/src/diagnostics/message.rs index 63561e409b0ae..8eff9a4fa9e8a 100644 --- a/compiler/rustc_macros/src/diagnostics/message.rs +++ b/compiler/rustc_macros/src/diagnostics/message.rs @@ -133,6 +133,7 @@ const ALLOWED_CAPITALIZED_WORDS: &[&str] = &[ "Cargo", "Ferris", "GCC", + "LLVM", "MIR", "NaNs", "OK",