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_ld64_unimplemented_modifier)]
35 pub struct Ld64UnimplementedModifier;
38 #[diag(codegen_ssa_linker_unsupported_modifier)]
39 pub struct LinkerUnsupportedModifier;
42 #[diag(codegen_ssa_L4Bender_exporting_symbols_unimplemented)]
43 pub struct L4BenderExportingSymbolsUnimplemented;
46 #[diag(codegen_ssa_no_natvis_directory)]
47 pub struct NoNatvisDirectory {
52 #[diag(codegen_ssa_copy_path_buf)]
53 pub struct CopyPathBuf {
54 pub source_file: PathBuf,
55 pub output_path: PathBuf,
59 // Reports Paths using `Debug` implementation rather than Path's `Display` implementation.
61 #[diag(codegen_ssa_copy_path)]
62 pub struct CopyPath<'a> {
63 from: DebugArgPath<'a>,
68 impl<'a> CopyPath<'a> {
69 pub fn new(from: &'a Path, to: &'a Path, error: Error) -> CopyPath<'a> {
70 CopyPath { from: DebugArgPath(from), to: DebugArgPath(to), error }
74 struct DebugArgPath<'a>(pub &'a Path);
76 impl IntoDiagnosticArg for DebugArgPath<'_> {
77 fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
78 DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self.0)))
83 #[diag(codegen_ssa_ignoring_emit_path)]
84 pub struct IgnoringEmitPath {
85 pub extension: String,
89 #[diag(codegen_ssa_ignoring_output)]
90 pub struct IgnoringOutput {
91 pub extension: String,
95 #[diag(codegen_ssa_create_temp_dir)]
96 pub struct CreateTempDir {
100 #[derive(Diagnostic)]
101 #[diag(codegen_ssa_incompatible_linking_modifiers)]
102 pub struct IncompatibleLinkingModifiers;
104 #[derive(Diagnostic)]
105 #[diag(codegen_ssa_add_native_library)]
106 pub struct AddNativeLibrary {
107 pub library_path: PathBuf,
111 #[derive(Diagnostic)]
112 #[diag(codegen_ssa_multiple_external_func_decl)]
113 pub struct MultipleExternalFuncDecl<'a> {
116 pub function: Symbol,
117 pub library_name: &'a str,
120 #[derive(Diagnostic)]
121 pub enum LinkRlibError {
122 #[diag(codegen_ssa_rlib_missing_format)]
125 #[diag(codegen_ssa_rlib_only_rmeta_found)]
126 OnlyRmetaFound { crate_name: Symbol },
128 #[diag(codegen_ssa_rlib_not_found)]
129 NotFound { crate_name: Symbol },
131 #[diag(codegen_ssa_rlib_incompatible_dependency_formats)]
132 IncompatibleDependencyFormats { ty1: String, ty2: String, list1: String, list2: String },
135 pub struct ThorinErrorWrapper(pub thorin::Error);
137 impl IntoDiagnostic<'_> for ThorinErrorWrapper {
138 fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
141 thorin::Error::ReadInput(_) => {
142 diag = handler.struct_err(fluent::codegen_ssa_thorin_read_input_failure);
145 thorin::Error::ParseFileKind(_) => {
146 diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_input_file_kind);
149 thorin::Error::ParseObjectFile(_) => {
150 diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_input_object_file);
153 thorin::Error::ParseArchiveFile(_) => {
154 diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_input_archive_file);
157 thorin::Error::ParseArchiveMember(_) => {
158 diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_archive_member);
161 thorin::Error::InvalidInputKind => {
162 diag = handler.struct_err(fluent::codegen_ssa_thorin_invalid_input_kind);
165 thorin::Error::DecompressData(_) => {
166 diag = handler.struct_err(fluent::codegen_ssa_thorin_decompress_data);
169 thorin::Error::NamelessSection(_, offset) => {
170 diag = handler.struct_err(fluent::codegen_ssa_thorin_section_without_name);
171 diag.set_arg("offset", format!("0x{:08x}", offset));
174 thorin::Error::RelocationWithInvalidSymbol(section, offset) => {
176 handler.struct_err(fluent::codegen_ssa_thorin_relocation_with_invalid_symbol);
177 diag.set_arg("section", section);
178 diag.set_arg("offset", format!("0x{:08x}", offset));
181 thorin::Error::MultipleRelocations(section, offset) => {
182 diag = handler.struct_err(fluent::codegen_ssa_thorin_multiple_relocations);
183 diag.set_arg("section", section);
184 diag.set_arg("offset", format!("0x{:08x}", offset));
187 thorin::Error::UnsupportedRelocation(section, offset) => {
188 diag = handler.struct_err(fluent::codegen_ssa_thorin_unsupported_relocation);
189 diag.set_arg("section", section);
190 diag.set_arg("offset", format!("0x{:08x}", offset));
193 thorin::Error::MissingDwoName(id) => {
194 diag = handler.struct_err(fluent::codegen_ssa_thorin_missing_dwo_name);
195 diag.set_arg("id", format!("0x{:08x}", id));
198 thorin::Error::NoCompilationUnits => {
199 diag = handler.struct_err(fluent::codegen_ssa_thorin_no_compilation_units);
202 thorin::Error::NoDie => {
203 diag = handler.struct_err(fluent::codegen_ssa_thorin_no_die);
206 thorin::Error::TopLevelDieNotUnit => {
207 diag = handler.struct_err(fluent::codegen_ssa_thorin_top_level_die_not_unit);
210 thorin::Error::MissingRequiredSection(section) => {
211 diag = handler.struct_err(fluent::codegen_ssa_thorin_missing_required_section);
212 diag.set_arg("section", section);
215 thorin::Error::ParseUnitAbbreviations(_) => {
216 diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_unit_abbreviations);
219 thorin::Error::ParseUnitAttribute(_) => {
220 diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_unit_attribute);
223 thorin::Error::ParseUnitHeader(_) => {
224 diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_unit_header);
227 thorin::Error::ParseUnit(_) => {
228 diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_unit);
231 thorin::Error::IncompatibleIndexVersion(section, format, actual) => {
232 diag = handler.struct_err(fluent::codegen_ssa_thorin_incompatible_index_version);
233 diag.set_arg("section", section);
234 diag.set_arg("actual", actual);
235 diag.set_arg("format", format);
238 thorin::Error::OffsetAtIndex(_, index) => {
239 diag = handler.struct_err(fluent::codegen_ssa_thorin_offset_at_index);
240 diag.set_arg("index", index);
243 thorin::Error::StrAtOffset(_, offset) => {
244 diag = handler.struct_err(fluent::codegen_ssa_thorin_str_at_offset);
245 diag.set_arg("offset", format!("0x{:08x}", offset));
248 thorin::Error::ParseIndex(_, section) => {
249 diag = handler.struct_err(fluent::codegen_ssa_thorin_parse_index);
250 diag.set_arg("section", section);
253 thorin::Error::UnitNotInIndex(unit) => {
254 diag = handler.struct_err(fluent::codegen_ssa_thorin_unit_not_in_index);
255 diag.set_arg("unit", format!("0x{:08x}", unit));
258 thorin::Error::RowNotInIndex(_, row) => {
259 diag = handler.struct_err(fluent::codegen_ssa_thorin_row_not_in_index);
260 diag.set_arg("row", row);
263 thorin::Error::SectionNotInRow => {
264 diag = handler.struct_err(fluent::codegen_ssa_thorin_section_not_in_row);
267 thorin::Error::EmptyUnit(unit) => {
268 diag = handler.struct_err(fluent::codegen_ssa_thorin_empty_unit);
269 diag.set_arg("unit", format!("0x{:08x}", unit));
272 thorin::Error::MultipleDebugInfoSection => {
273 diag = handler.struct_err(fluent::codegen_ssa_thorin_multiple_debug_info_section);
276 thorin::Error::MultipleDebugTypesSection => {
277 diag = handler.struct_err(fluent::codegen_ssa_thorin_multiple_debug_types_section);
280 thorin::Error::NotSplitUnit => {
281 diag = handler.struct_err(fluent::codegen_ssa_thorin_not_split_unit);
284 thorin::Error::DuplicateUnit(unit) => {
285 diag = handler.struct_err(fluent::codegen_ssa_thorin_duplicate_unit);
286 diag.set_arg("unit", format!("0x{:08x}", unit));
289 thorin::Error::MissingReferencedUnit(unit) => {
290 diag = handler.struct_err(fluent::codegen_ssa_thorin_missing_referenced_unit);
291 diag.set_arg("unit", format!("0x{:08x}", unit));
294 thorin::Error::NoOutputObjectCreated => {
295 diag = handler.struct_err(fluent::codegen_ssa_thorin_not_output_object_created);
298 thorin::Error::MixedInputEncodings => {
299 diag = handler.struct_err(fluent::codegen_ssa_thorin_mixed_input_encodings);
302 thorin::Error::Io(e) => {
303 diag = handler.struct_err(fluent::codegen_ssa_thorin_io);
304 diag.set_arg("error", format!("{e}"));
307 thorin::Error::ObjectRead(e) => {
308 diag = handler.struct_err(fluent::codegen_ssa_thorin_object_read);
309 diag.set_arg("error", format!("{e}"));
312 thorin::Error::ObjectWrite(e) => {
313 diag = handler.struct_err(fluent::codegen_ssa_thorin_object_write);
314 diag.set_arg("error", format!("{e}"));
317 thorin::Error::GimliRead(e) => {
318 diag = handler.struct_err(fluent::codegen_ssa_thorin_gimli_read);
319 diag.set_arg("error", format!("{e}"));
322 thorin::Error::GimliWrite(e) => {
323 diag = handler.struct_err(fluent::codegen_ssa_thorin_gimli_write);
324 diag.set_arg("error", format!("{e}"));
327 _ => unimplemented!("Untranslated thorin error"),
332 pub struct LinkingFailed<'a> {
333 pub linker_path: &'a PathBuf,
334 pub exit_status: ExitStatus,
335 pub command: &'a Command,
336 pub escaped_output: &'a str,
339 impl IntoDiagnostic<'_> for LinkingFailed<'_> {
340 fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
341 let mut diag = handler.struct_err(fluent::codegen_ssa_linking_failed);
342 diag.set_arg("linker_path", format!("{}", self.linker_path.display()));
343 diag.set_arg("exit_status", format!("{}", self.exit_status));
345 diag.note(format!("{:?}", self.command)).note(self.escaped_output);
347 // Trying to match an error from OS linkers
348 // which by now we have no way to translate.
349 if self.escaped_output.contains("undefined reference to") {
350 diag.note(fluent::codegen_ssa_extern_funcs_not_found)
351 .note(fluent::codegen_ssa_specify_libraries_to_link)
352 .note(fluent::codegen_ssa_use_cargo_directive);
358 #[derive(Diagnostic)]
359 #[diag(codegen_ssa_link_exe_unexpected_error)]
360 pub struct LinkExeUnexpectedError;
362 #[derive(Diagnostic)]
363 #[diag(codegen_ssa_repair_vs_build_tools)]
364 pub struct RepairVSBuildTools;
366 #[derive(Diagnostic)]
367 #[diag(codegen_ssa_missing_cpp_build_tool_component)]
368 pub struct MissingCppBuildToolComponent;
370 #[derive(Diagnostic)]
371 #[diag(codegen_ssa_select_cpp_build_tool_workload)]
372 pub struct SelectCppBuildToolWorkload;
374 #[derive(Diagnostic)]
375 #[diag(codegen_ssa_visual_studio_not_installed)]
376 pub struct VisualStudioNotInstalled;
378 #[derive(Diagnostic)]
379 #[diag(codegen_ssa_linker_not_found)]
381 pub struct LinkerNotFound {
382 pub linker_path: PathBuf,
386 #[derive(Diagnostic)]
387 #[diag(codegen_ssa_unable_to_exe_linker)]
389 #[note(command_note)]
390 pub struct UnableToExeLinker {
391 pub linker_path: PathBuf,
393 pub command_formatted: String,
396 #[derive(Diagnostic)]
397 #[diag(codegen_ssa_msvc_missing_linker)]
398 pub struct MsvcMissingLinker;
400 #[derive(Diagnostic)]
401 #[diag(codegen_ssa_check_installed_visual_studio)]
402 pub struct CheckInstalledVisualStudio;
404 #[derive(Diagnostic)]
405 #[diag(codegen_ssa_unsufficient_vs_code_product)]
406 pub struct UnsufficientVSCodeProduct;
408 #[derive(Diagnostic)]
409 #[diag(codegen_ssa_processing_dymutil_failed)]
411 pub struct ProcessingDymutilFailed {
412 pub status: ExitStatus,
416 #[derive(Diagnostic)]
417 #[diag(codegen_ssa_unable_to_run_dsymutil)]
419 pub struct UnableToRunDsymutil {
423 #[derive(Diagnostic)]
424 #[diag(codegen_ssa_stripping_debu_info_failed)]
426 pub struct StrippingDebugInfoFailed<'a> {
428 pub status: ExitStatus,
432 #[derive(Diagnostic)]
433 #[diag(codegen_ssa_unable_to_run)]
434 pub struct UnableToRun<'a> {
439 #[derive(Diagnostic)]
440 #[diag(codegen_ssa_linker_file_stem)]
441 pub struct LinkerFileStem;
443 #[derive(Diagnostic)]
444 #[diag(codegen_ssa_static_library_native_artifacts)]
445 pub struct StaticLibraryNativeArtifacts;
447 #[derive(Diagnostic)]
448 #[diag(codegen_ssa_native_static_libs)]
449 pub struct NativeStaticLibs {
450 pub arguments: String,
453 #[derive(Diagnostic)]
454 #[diag(codegen_ssa_link_script_unavailable)]
455 pub struct LinkScriptUnavailable;
457 #[derive(Diagnostic)]
458 #[diag(codegen_ssa_link_script_write_failure)]
459 pub struct LinkScriptWriteFailure {
464 #[derive(Diagnostic)]
465 #[diag(codegen_ssa_failed_to_write)]
466 pub struct FailedToWrite {
471 #[derive(Diagnostic)]
472 #[diag(codegen_ssa_unable_to_write_debugger_visualizer)]
473 pub struct UnableToWriteDebuggerVisualizer {
478 #[derive(Diagnostic)]
479 #[diag(codegen_ssa_rlib_archive_build_failure)]
480 pub struct RlibArchiveBuildFailure {
484 #[derive(Diagnostic)]
485 #[diag(codegen_ssa_option_gcc_only)]
486 pub struct OptionGccOnly;
488 #[derive(Diagnostic)]
489 pub enum ExtractBundledLibsError<'a> {
490 #[diag(codegen_ssa_extract_bundled_libs_open_file)]
491 OpenFile { rlib: &'a Path, error: String },
493 #[diag(codegen_ssa_extract_bundled_libs_mmap_file)]
494 MmapFile { rlib: &'a Path, error: String },
496 #[diag(codegen_ssa_extract_bundled_libs_parse_archive)]
497 ParseArchive { rlib: &'a Path, error: String },
499 #[diag(codegen_ssa_extract_bundled_libs_read_entry)]
500 ReadEntry { rlib: &'a Path, error: String },
502 #[diag(codegen_ssa_extract_bundled_libs_archive_member)]
503 ArchiveMember { rlib: &'a Path, error: String },
505 #[diag(codegen_ssa_extract_bundled_libs_convert_name)]
506 ConvertName { rlib: &'a Path, error: String },
508 #[diag(codegen_ssa_extract_bundled_libs_write_file)]
509 WriteFile { rlib: &'a Path, error: String },
512 #[derive(Diagnostic)]
513 #[diag(codegen_ssa_unsupported_arch)]
514 pub struct UnsupportedArch<'a> {
519 #[derive(Diagnostic)]
520 pub enum AppleSdkRootError<'a> {
521 #[diag(codegen_ssa_apple_sdk_error_sdk_path)]
522 SdkPath { sdk_name: &'a str, error: Error },