1 //! Errors emitted by codegen_ssa
3 use crate::back::command::Command;
5 fluent, DiagnosticArgValue, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic,
8 use rustc_macros::Diagnostic;
9 use rustc_span::{Span, Symbol};
12 use std::path::{Path, PathBuf};
13 use std::process::ExitStatus;
16 #[diag(codegen_ssa::lib_def_write_failure)]
17 pub struct LibDefWriteFailure {
22 #[diag(codegen_ssa::version_script_write_failure)]
23 pub struct VersionScriptWriteFailure {
28 #[diag(codegen_ssa::symbol_file_write_failure)]
29 pub struct SymbolFileWriteFailure {
34 #[diag(codegen_ssa::unsupported_arch)]
35 pub struct UnsupportedArch;
38 #[diag(codegen_ssa::msvc_path_not_found)]
39 pub struct MsvcPathNotFound;
42 #[diag(codegen_ssa::link_exe_not_found)]
43 pub struct LinkExeNotFound;
46 #[diag(codegen_ssa::ld64_unimplemented_modifier)]
47 pub struct Ld64UnimplementedModifier;
50 #[diag(codegen_ssa::linker_unsupported_modifier)]
51 pub struct LinkerUnsupportedModifier;
54 #[diag(codegen_ssa::L4Bender_exporting_symbols_unimplemented)]
55 pub struct L4BenderExportingSymbolsUnimplemented;
58 #[diag(codegen_ssa::no_natvis_directory)]
59 pub struct NoNatvisDirectory {
64 #[diag(codegen_ssa::copy_path_buf)]
65 pub struct CopyPathBuf {
66 pub source_file: PathBuf,
67 pub output_path: PathBuf,
71 // Reports Paths using `Debug` implementation rather than Path's `Display` implementation.
73 #[diag(codegen_ssa::copy_path)]
74 pub struct CopyPath<'a> {
75 from: DebugArgPath<'a>,
80 impl<'a> CopyPath<'a> {
81 pub fn new(from: &'a Path, to: &'a Path, error: Error) -> CopyPath<'a> {
82 CopyPath { from: DebugArgPath(from), to: DebugArgPath(to), error }
86 struct DebugArgPath<'a>(pub &'a Path);
88 impl IntoDiagnosticArg for DebugArgPath<'_> {
89 fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
90 DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self.0)))
95 #[diag(codegen_ssa::ignoring_emit_path)]
96 pub struct IgnoringEmitPath {
97 pub extension: String,
100 #[derive(Diagnostic)]
101 #[diag(codegen_ssa::ignoring_output)]
102 pub struct IgnoringOutput {
103 pub extension: String,
106 #[derive(Diagnostic)]
107 #[diag(codegen_ssa::create_temp_dir)]
108 pub struct CreateTempDir {
112 #[derive(Diagnostic)]
113 #[diag(codegen_ssa::incompatible_linking_modifiers)]
114 pub struct IncompatibleLinkingModifiers;
116 #[derive(Diagnostic)]
117 #[diag(codegen_ssa::add_native_library)]
118 pub struct AddNativeLibrary<'a> {
119 pub library_path: &'a str,
123 #[derive(Diagnostic)]
124 #[diag(codegen_ssa::multiple_external_func_decl)]
125 pub struct MultipleExternalFuncDecl<'a> {
128 pub function: Symbol,
129 pub library_name: &'a str,
132 pub enum LinkRlibError {
134 OnlyRmetaFound { crate_name: Symbol },
135 NotFound { crate_name: Symbol },
138 impl IntoDiagnostic<'_, !> for LinkRlibError {
139 fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> {
141 LinkRlibError::MissingFormat => {
142 handler.struct_fatal(fluent::codegen_ssa::rlib_missing_format)
144 LinkRlibError::OnlyRmetaFound { crate_name } => {
145 let mut diag = handler.struct_fatal(fluent::codegen_ssa::rlib_only_rmeta_found);
146 diag.set_arg("crate_name", crate_name);
149 LinkRlibError::NotFound { crate_name } => {
150 let mut diag = handler.struct_fatal(fluent::codegen_ssa::rlib_not_found);
151 diag.set_arg("crate_name", crate_name);
158 #[derive(Diagnostic)]
159 #[diag(codegen_ssa::thorin_dwarf_linking)]
161 pub struct ThorinDwarfLinking {
162 pub thorin_error: ThorinErrorWrapper,
164 pub struct ThorinErrorWrapper(pub thorin::Error);
166 // FIXME: How should we support translations for external crate errors?
167 impl IntoDiagnosticArg for ThorinErrorWrapper {
168 fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
169 DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self.0)))
173 pub struct LinkingFailed<'a> {
174 pub linker_path: &'a PathBuf,
175 pub exit_status: ExitStatus,
176 pub command: &'a Command,
177 pub escaped_output: &'a str,
180 impl IntoDiagnostic<'_> for LinkingFailed<'_> {
181 fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
182 let mut diag = handler.struct_err(fluent::codegen_ssa::linking_failed);
183 diag.set_arg("linker_path", format!("{}", self.linker_path.display()));
184 diag.set_arg("exit_status", format!("{}", self.exit_status));
186 diag.note(format!("{:?}", self.command)).note(self.escaped_output);
188 // Trying to match an error from OS linkers
189 // which by now we have no way to translate.
190 if self.escaped_output.contains("undefined reference to") {
191 diag.note(fluent::codegen_ssa::extern_funcs_not_found)
192 .note(fluent::codegen_ssa::specify_libraries_to_link)
193 .note(fluent::codegen_ssa::use_cargo_directive);