Skip to main content

rustc_codegen_llvm/
diagnostics.rs

1use std::ffi::{CString, c_uint};
2use std::path::Path;
3
4use rustc_data_structures::small_c_str::SmallCStr;
5use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level, format_diag_message, msg};
6use rustc_macros::Diagnostic;
7use rustc_span::Span;
8
9#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            SymbolAlreadyDefined<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    SymbolAlreadyDefined {
                        span: __binding_0, symbol_name: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("symbol `{$symbol_name}` is already defined")));
                        ;
                        diag.arg("symbol_name", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
10#[diag("symbol `{$symbol_name}` is already defined")]
11pub(crate) struct SymbolAlreadyDefined<'a> {
12    #[primary_span]
13    pub span: Span,
14    pub symbol_name: &'a str,
15}
16
17#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            SanitizerMemtagRequiresMte {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    SanitizerMemtagRequiresMte => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
18#[diag("`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`")]
19pub(crate) struct SanitizerMemtagRequiresMte;
20
21pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);
22
23impl Diagnostic<'_> for ParseTargetMachineConfig<'_> {
24    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_> {
25        // Reuse the formatted primary message from `LlvmError` without emitting it.
26        let diag = self.0.into_diag(dcx, level);
27        let (message, _) = diag.messages.first().expect("`LlvmError` with no message");
28        let message = format_diag_message(message, &diag.args).into_owned();
29        diag.cancel();
30
31        Diag::new(
32            dcx,
33            level,
34            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to parse target machine config to target machine: {$error}"))msg!("failed to parse target machine config to target machine: {$error}"),
35        )
36        .with_arg("error", message)
37    }
38}
39
40#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            AutoDiffComponentUnavailable {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    AutoDiffComponentUnavailable { err: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to load our autodiff backend: {$err}")));
                        ;
                        diag.arg("err", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
41#[diag("failed to load our autodiff backend: {$err}")]
42pub(crate) struct AutoDiffComponentUnavailable {
43    pub err: String,
44}
45
46#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            AutoDiffComponentMissing {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    AutoDiffComponentMissing { err: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("autodiff backend not found in the sysroot: {$err}")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("it will be distributed via rustup in the future")));
                        ;
                        diag.arg("err", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
47#[diag("autodiff backend not found in the sysroot: {$err}")]
48#[note("it will be distributed via rustup in the future")]
49pub(crate) struct AutoDiffComponentMissing {
50    pub err: String,
51}
52
53#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for AutoDiffWithoutLto {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    AutoDiffWithoutLto => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using the autodiff feature requires setting `lto=\"fat\"` in your Cargo.toml")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
54#[diag("using the autodiff feature requires setting `lto=\"fat\"` in your Cargo.toml")]
55pub(crate) struct AutoDiffWithoutLto;
56
57#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            AutoDiffWithoutEnable {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    AutoDiffWithoutEnable => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using the autodiff feature requires -Z autodiff=Enable")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
58#[diag("using the autodiff feature requires -Z autodiff=Enable")]
59pub(crate) struct AutoDiffWithoutEnable;
60
61#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            RustOffloadComponentUnavailable {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    RustOffloadComponentUnavailable { err: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to load our rust offload backend: {$err}")));
                        ;
                        diag.arg("err", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
62#[diag("failed to load our rust offload backend: {$err}")]
63pub(crate) struct RustOffloadComponentUnavailable {
64    pub err: String,
65}
66
67#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            RustOffloadComponentMissing {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    RustOffloadComponentMissing { err: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("rust offload backend not found in the sysroot: {$err}")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("it will be distributed via rustup in the future")));
                        ;
                        diag.arg("err", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
68#[diag("rust offload backend not found in the sysroot: {$err}")]
69#[note("it will be distributed via rustup in the future")]
70pub(crate) struct RustOffloadComponentMissing {
71    pub err: String,
72}
73
74#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for OffloadWithoutEnable
            {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    OffloadWithoutEnable => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using the offload feature requires -Z offload=<Device or Host=/absolute/path/to/<crate>.ptx or <crate>.elf>")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
75#[diag(
76    "using the offload feature requires -Z offload=<Device or Host=/absolute/path/to/<crate>.ptx or <crate>.elf>"
77)]
78pub(crate) struct OffloadWithoutEnable;
79
80#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for OffloadWithoutFatLTO
            {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    OffloadWithoutFatLTO => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using the offload feature requires -C lto=fat")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
81#[diag("using the offload feature requires -C lto=fat")]
82pub(crate) struct OffloadWithoutFatLTO;
83
84#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            OffloadWithoutAbsPath {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    OffloadWithoutAbsPath => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using the `-Z offload=Host=/absolute/path/to/<crate>.ptx` or `<crate>.elf` flag requires an absolute path")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
85#[diag(
86    "using the `-Z offload=Host=/absolute/path/to/<crate>.ptx` or `<crate>.elf` flag requires an absolute path"
87)]
88pub(crate) struct OffloadWithoutAbsPath;
89
90#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for OffloadWrongFileName
            {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    OffloadWrongFileName => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using the `-Z offload=Host=/absolute/path/to/<crate>.ptx` or `<crate>.elf` flag must point to a .ptx or .elf file produced by the device compilation")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
91#[diag(
92    "using the `-Z offload=Host=/absolute/path/to/<crate>.ptx` or `<crate>.elf` flag must point to a .ptx or .elf file produced by the device compilation"
93)]
94pub(crate) struct OffloadWrongFileName;
95
96#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            OffloadNonexistingPath {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    OffloadNonexistingPath => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the given path/file to `<crate>.ptx` or `<crate>.elf` does not exist. Did you forget to run the device compilation first?")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
97#[diag(
98    "the given path/file to `<crate>.ptx` or `<crate>.elf` does not exist. Did you forget to run the device compilation first?"
99)]
100pub(crate) struct OffloadNonexistingPath;
101
102#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            OffloadWrapImagesFailed {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    OffloadWrapImagesFailed => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("call to WrapImages failed, device image was not wrapped into the host module")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
103#[diag("call to WrapImages failed, device image was not wrapped into the host module")]
104pub(crate) struct OffloadWrapImagesFailed;
105
106#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for LtoBitcodeFromRlib {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    LtoBitcodeFromRlib { err: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to get bitcode from object file for LTO ({$err})")));
                        ;
                        diag.arg("err", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
107#[diag("failed to get bitcode from object file for LTO ({$err})")]
108pub(crate) struct LtoBitcodeFromRlib {
109    pub err: String,
110}
111
112#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            TpdeComponentUnavailable {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    TpdeComponentUnavailable { err: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to load the TPDE backend: {$err}")));
                        ;
                        diag.arg("err", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
113#[diag("failed to load the TPDE backend: {$err}")]
114pub(crate) struct TpdeComponentUnavailable {
115    pub err: String,
116}
117
118#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for TpdeComponentMissing
            {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    TpdeComponentMissing { err: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("TPDE backend not found in the sysroot: {$err}")));
                        ;
                        diag.arg("err", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
119#[diag("TPDE backend not found in the sysroot: {$err}")]
120pub(crate) struct TpdeComponentMissing {
121    pub err: String,
122}
123
124#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for TpdeHighOptLevel {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    TpdeHighOptLevel => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using -Zllvm-tpde with optimization levels higher than 1 is not recommended")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("compilation with TPDE at higher opt levels is more likely to fail, and to have worse runtime performance than LLVM even if it succeeds")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
125#[diag("using -Zllvm-tpde with optimization levels higher than 1 is not recommended")]
126#[note(
127    "compilation with TPDE at higher opt levels is more likely to fail, and to have worse runtime performance than LLVM even if it succeeds"
128)]
129pub(crate) struct TpdeHighOptLevel;
130
131#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for TpdeLtoUsed {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    TpdeLtoUsed => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using -Zllvm-tpde with LTO enabled is not supported")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
132#[diag("using -Zllvm-tpde with LTO enabled is not supported")]
133pub(crate) struct TpdeLtoUsed;
134
135#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            TpdeSplitDebugInfoUsed {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    TpdeSplitDebugInfoUsed => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using -Zllvm-tpde with split debuginfo is not supported")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
136#[diag("using -Zllvm-tpde with split debuginfo is not supported")]
137pub(crate) struct TpdeSplitDebugInfoUsed;
138
139#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for LlvmError<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    LlvmError::WriteOutput { path: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("could not write output to {$path}")));
                        ;
                        diag.arg("path", __binding_0);
                        diag
                    }
                    LlvmError::CreateTargetMachine { triple: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("could not create LLVM TargetMachine for triple: {$triple}")));
                        ;
                        diag.arg("triple", __binding_0);
                        diag
                    }
                    LlvmError::CreateMCSubtargetInfo { triple: __binding_0 } =>
                        {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("could not create LLVM MCSubtargetInfo for triple: {$triple}")));
                        ;
                        diag.arg("triple", __binding_0);
                        diag
                    }
                    LlvmError::RunLlvmPasses => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to run LLVM passes")));
                        ;
                        diag
                    }
                    LlvmError::WriteIr { path: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to write LLVM IR to {$path}")));
                        ;
                        diag.arg("path", __binding_0);
                        diag
                    }
                    LlvmError::PrepareThinLtoContext => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to prepare thin LTO context")));
                        ;
                        diag
                    }
                    LlvmError::LoadBitcode { name: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to load bitcode of module \"{$name}\"")));
                        ;
                        diag.arg("name", __binding_0);
                        diag
                    }
                    LlvmError::WriteThinLtoKey { err: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("error while writing ThinLTO key data: {$err}")));
                        ;
                        diag.arg("err", __binding_0);
                        diag
                    }
                    LlvmError::PrepareThinLtoModule => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to prepare thin LTO module")));
                        ;
                        diag
                    }
                    LlvmError::ParseBitcode => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to parse bitcode for LTO module")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
140pub(crate) enum LlvmError<'a> {
141    #[diag("could not write output to {$path}")]
142    WriteOutput { path: &'a Path },
143    #[diag("could not create LLVM TargetMachine for triple: {$triple}")]
144    CreateTargetMachine { triple: SmallCStr },
145    #[diag("could not create LLVM MCSubtargetInfo for triple: {$triple}")]
146    CreateMCSubtargetInfo { triple: SmallCStr },
147    #[diag("failed to run LLVM passes")]
148    RunLlvmPasses,
149    #[diag("failed to write LLVM IR to {$path}")]
150    WriteIr { path: &'a Path },
151    #[diag("failed to prepare thin LTO context")]
152    PrepareThinLtoContext,
153    #[diag("failed to load bitcode of module \"{$name}\"")]
154    LoadBitcode { name: CString },
155    #[diag("error while writing ThinLTO key data: {$err}")]
156    WriteThinLtoKey { err: std::io::Error },
157    #[diag("failed to prepare thin LTO module")]
158    PrepareThinLtoModule,
159    #[diag("failed to parse bitcode for LTO module")]
160    ParseBitcode,
161}
162
163pub(crate) struct WithLlvmError<'a>(pub LlvmError<'a>, pub String);
164
165impl Diagnostic<'_> for WithLlvmError<'_> {
166    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_> {
167        use LlvmError::*;
168        let msg_with_llvm_err = match &self.0 {
169            WriteOutput { .. } => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("could not write output to {$path}: {$llvm_err}"))msg!("could not write output to {$path}: {$llvm_err}"),
170            CreateTargetMachine { .. } => {
171                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("could not create LLVM TargetMachine for triple: {$triple}: {$llvm_err}"))msg!("could not create LLVM TargetMachine for triple: {$triple}: {$llvm_err}")
172            }
173            CreateMCSubtargetInfo { .. } => {
174                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("could not create LLVM MCSubtargetInfo for triple: {$triple}: {$llvm_err}"))msg!("could not create LLVM MCSubtargetInfo for triple: {$triple}: {$llvm_err}")
175            }
176            RunLlvmPasses => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to run LLVM passes: {$llvm_err}"))msg!("failed to run LLVM passes: {$llvm_err}"),
177            WriteIr { .. } => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to write LLVM IR to {$path}: {$llvm_err}"))msg!("failed to write LLVM IR to {$path}: {$llvm_err}"),
178            PrepareThinLtoContext => {
179                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to prepare thin LTO context: {$llvm_err}"))msg!("failed to prepare thin LTO context: {$llvm_err}")
180            }
181            LoadBitcode { .. } => {
182                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to load bitcode of module \"{$name}\": {$llvm_err}"))msg!("failed to load bitcode of module \"{$name}\": {$llvm_err}")
183            }
184            WriteThinLtoKey { .. } => {
185                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("error while writing ThinLTO key data: {$err}: {$llvm_err}"))msg!("error while writing ThinLTO key data: {$err}: {$llvm_err}")
186            }
187            PrepareThinLtoModule => {
188                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to prepare thin LTO module: {$llvm_err}"))msg!("failed to prepare thin LTO module: {$llvm_err}")
189            }
190            ParseBitcode => rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to parse bitcode for LTO module: {$llvm_err}"))msg!("failed to parse bitcode for LTO module: {$llvm_err}"),
191        };
192        self.0
193            .into_diag(dcx, level)
194            .with_primary_message(msg_with_llvm_err)
195            .with_arg("llvm_err", self.1)
196    }
197}
198
199#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            FromLlvmOptimizationDiag<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    FromLlvmOptimizationDiag {
                        filename: __binding_0,
                        line: __binding_1,
                        column: __binding_2,
                        pass_name: __binding_3,
                        kind: __binding_4,
                        message: __binding_5 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$filename}:{$line}:{$column} {$pass_name} ({$kind}): {$message}")));
                        ;
                        diag.arg("filename", __binding_0);
                        diag.arg("line", __binding_1);
                        diag.arg("column", __binding_2);
                        diag.arg("pass_name", __binding_3);
                        diag.arg("kind", __binding_4);
                        diag.arg("message", __binding_5);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
200#[diag("{$filename}:{$line}:{$column} {$pass_name} ({$kind}): {$message}")]
201pub(crate) struct FromLlvmOptimizationDiag<'a> {
202    pub filename: &'a str,
203    pub line: std::ffi::c_uint,
204    pub column: std::ffi::c_uint,
205    pub pass_name: &'a str,
206    pub kind: &'a str,
207    pub message: &'a str,
208}
209
210#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for FromLlvmDiag {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    FromLlvmDiag { message: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$message}")));
                        ;
                        diag.arg("message", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
211#[diag("{$message}")]
212pub(crate) struct FromLlvmDiag {
213    pub message: String,
214}
215
216#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            WriteBytecode<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    WriteBytecode { path: __binding_0, err: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to write bytecode to {$path}: {$err}")));
                        ;
                        diag.arg("path", __binding_0);
                        diag.arg("err", __binding_1);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
217#[diag("failed to write bytecode to {$path}: {$err}")]
218pub(crate) struct WriteBytecode<'a> {
219    pub path: &'a Path,
220    pub err: std::io::Error,
221}
222
223#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for CopyBitcode {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    CopyBitcode { err: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to copy bitcode to object file: {$err}")));
                        ;
                        diag.arg("err", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
224#[diag("failed to copy bitcode to object file: {$err}")]
225pub(crate) struct CopyBitcode {
226    pub err: std::io::Error,
227}
228
229#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            UnsupportedCompression {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    UnsupportedCompression { algorithm: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unsupported debuginfo compression algorithm {$algorithm} - will fall back to uncompressed debuginfo")));
                        ;
                        diag.arg("algorithm", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
230#[diag(
231    "unsupported debuginfo compression algorithm {$algorithm} - will fall back to uncompressed debuginfo"
232)]
233pub(crate) struct UnsupportedCompression {
234    pub algorithm: &'static str,
235}
236
237#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            MismatchedDataLayout<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    MismatchedDataLayout {
                        rustc_target: __binding_0,
                        rustc_layout: __binding_1,
                        llvm_target: __binding_2,
                        llvm_layout: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("data-layout for target `{$rustc_target}`, `{$rustc_layout}`, differs from LLVM target's `{$llvm_target}` default layout, `{$llvm_layout}`")));
                        ;
                        diag.arg("rustc_target", __binding_0);
                        diag.arg("rustc_layout", __binding_1);
                        diag.arg("llvm_target", __binding_2);
                        diag.arg("llvm_layout", __binding_3);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
238#[diag(
239    "data-layout for target `{$rustc_target}`, `{$rustc_layout}`, differs from LLVM target's `{$llvm_target}` default layout, `{$llvm_layout}`"
240)]
241pub(crate) struct MismatchedDataLayout<'a> {
242    pub rustc_target: &'a str,
243    pub rustc_layout: &'a str,
244    pub llvm_target: &'a str,
245    pub llvm_layout: &'a str,
246}
247
248#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            FixedX18InvalidArch<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    FixedX18InvalidArch { arch: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the `-Zfixed-x18` flag is not supported on the `{$arch}` architecture")));
                        ;
                        diag.arg("arch", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
249#[diag("the `-Zfixed-x18` flag is not supported on the `{$arch}` architecture")]
250pub(crate) struct FixedX18InvalidArch<'a> {
251    pub arch: &'a str,
252}
253
254#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            PackedStackBackchainNeedsSoftfloat {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    PackedStackBackchainNeedsSoftfloat => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`-Zpacked-stack` is incompatible with `backchain` target feature")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("enabling both `-Zpacked-stack` and the `backchain` target feature is incompatible with the default s390x ABI. Switch to s390x-unknown-none-softfloat if you need both attributes")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
255#[diag("`-Zpacked-stack` is incompatible with `backchain` target feature")]
256#[note(
257    "enabling both `-Zpacked-stack` and the `backchain` target feature is incompatible with the default s390x ABI. Switch to s390x-unknown-none-softfloat if you need both attributes"
258)]
259pub(crate) struct PackedStackBackchainNeedsSoftfloat;
260
261#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            IntrinsicSignatureMismatch<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    IntrinsicSignatureMismatch {
                        name: __binding_0,
                        llvm_fn_ty: __binding_1,
                        rust_fn_ty: __binding_2,
                        span: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("intrinsic signature mismatch for `{$name}`: expected signature `{$llvm_fn_ty}`, found `{$rust_fn_ty}`")));
                        ;
                        diag.arg("name", __binding_0);
                        diag.arg("llvm_fn_ty", __binding_1);
                        diag.arg("rust_fn_ty", __binding_2);
                        diag.span(__binding_3);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
262#[diag(
263    "intrinsic signature mismatch for `{$name}`: expected signature `{$llvm_fn_ty}`, found `{$rust_fn_ty}`"
264)]
265pub(crate) struct IntrinsicSignatureMismatch<'a> {
266    pub name: &'a str,
267    pub llvm_fn_ty: &'a str,
268    pub rust_fn_ty: &'a str,
269    #[primary_span]
270    pub span: Span,
271}
272
273#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            UnknownIntrinsic<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    UnknownIntrinsic { name: __binding_0, span: __binding_1 } =>
                        {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unknown LLVM intrinsic `{$name}`")));
                        ;
                        diag.arg("name", __binding_0);
                        diag.span(__binding_1);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
274#[diag("unknown LLVM intrinsic `{$name}`")]
275pub(crate) struct UnknownIntrinsic<'a> {
276    pub name: &'a str,
277    #[primary_span]
278    pub span: Span,
279}
280
281#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            IntrinsicWrongArch<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    IntrinsicWrongArch {
                        name: __binding_0,
                        target_arch: __binding_1,
                        span: __binding_2 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("intrinsic `{$name}` cannot be used with target arch `{$target_arch}`")));
                        ;
                        diag.arg("name", __binding_0);
                        diag.arg("target_arch", __binding_1);
                        diag.span(__binding_2);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
282#[diag("intrinsic `{$name}` cannot be used with target arch `{$target_arch}`")]
283pub(crate) struct IntrinsicWrongArch<'a> {
284    pub name: &'a str,
285    pub target_arch: &'a str,
286    #[primary_span]
287    pub span: Span,
288}
289
290#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            UnknownLlvmTargetFeaturePrefix<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    UnknownLlvmTargetFeaturePrefix { feature: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("ignoring feature with missing prefix in `-Zllvm-target-feature`: `{$feature}`")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("features must begin with a `+` to enable or `-` to disable it")));
                        ;
                        diag.arg("feature", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
291#[diag("ignoring feature with missing prefix in `-Zllvm-target-feature`: `{$feature}`")]
292#[note("features must begin with a `+` to enable or `-` to disable it")]
293pub(crate) struct UnknownLlvmTargetFeaturePrefix<'a> {
294    pub feature: &'a str,
295}
296
297#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            LlvmVersionMismatch<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    LlvmVersionMismatch {
                        expected_version: __binding_0,
                        llvm_major: __binding_1,
                        llvm_minor: __binding_2,
                        llvm_patch: __binding_3,
                        dll_loc: __binding_4 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("LLVM version mismatch: this compiler was built for LLVM {$expected_version}, but LLVM {$llvm_major}.{$llvm_minor}.{$llvm_patch} was found{$dll_loc}")));
                        ;
                        diag.arg("expected_version", __binding_0);
                        diag.arg("llvm_major", __binding_1);
                        diag.arg("llvm_minor", __binding_2);
                        diag.arg("llvm_patch", __binding_3);
                        diag.arg("dll_loc", __binding_4);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
298#[diag(
299    "LLVM version mismatch: this compiler was built for LLVM {$expected_version}, but LLVM {$llvm_major}.{$llvm_minor}.{$llvm_patch} was found{$dll_loc}"
300)]
301pub(crate) struct LlvmVersionMismatch<'a> {
302    pub expected_version: c_uint,
303    pub llvm_major: c_uint,
304    pub llvm_minor: c_uint,
305    pub llvm_patch: c_uint,
306    pub dll_loc: &'a str,
307}