rustc_codegen_ssa/
errors.rs

1//! Errors emitted by codegen_ssa
2
3use std::borrow::Cow;
4use std::ffi::OsString;
5use std::io::Error;
6use std::path::{Path, PathBuf};
7use std::process::ExitStatus;
8
9use rustc_errors::codes::*;
10use rustc_errors::{
11    Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, Level,
12};
13use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
14use rustc_middle::ty::layout::LayoutError;
15use rustc_middle::ty::{FloatTy, Ty};
16use rustc_span::{Span, Symbol};
17
18use crate::assert_module_sources::CguReuse;
19use crate::back::command::Command;
20use crate::fluent_generated as fluent;
21
22#[derive(Diagnostic)]
23#[diag(codegen_ssa_incorrect_cgu_reuse_type)]
24pub(crate) struct IncorrectCguReuseType<'a> {
25    #[primary_span]
26    pub span: Span,
27    pub cgu_user_name: &'a str,
28    pub actual_reuse: CguReuse,
29    pub expected_reuse: CguReuse,
30    pub at_least: u8,
31}
32
33#[derive(Diagnostic)]
34#[diag(codegen_ssa_cgu_not_recorded)]
35pub(crate) struct CguNotRecorded<'a> {
36    pub cgu_user_name: &'a str,
37    pub cgu_name: &'a str,
38}
39
40#[derive(Diagnostic)]
41#[diag(codegen_ssa_autodiff_without_lto)]
42pub struct AutodiffWithoutLto;
43
44#[derive(Diagnostic)]
45#[diag(codegen_ssa_unknown_reuse_kind)]
46pub(crate) struct UnknownReuseKind {
47    #[primary_span]
48    pub span: Span,
49    pub kind: Symbol,
50}
51
52#[derive(Diagnostic)]
53#[diag(codegen_ssa_missing_query_depgraph)]
54pub(crate) struct MissingQueryDepGraph {
55    #[primary_span]
56    pub span: Span,
57}
58
59#[derive(Diagnostic)]
60#[diag(codegen_ssa_malformed_cgu_name)]
61pub(crate) struct MalformedCguName {
62    #[primary_span]
63    pub span: Span,
64    pub user_path: String,
65    pub crate_name: String,
66}
67
68#[derive(Diagnostic)]
69#[diag(codegen_ssa_no_module_named)]
70pub(crate) struct NoModuleNamed<'a> {
71    #[primary_span]
72    pub span: Span,
73    pub user_path: &'a str,
74    pub cgu_name: Symbol,
75    pub cgu_names: String,
76}
77
78#[derive(Diagnostic)]
79#[diag(codegen_ssa_field_associated_value_expected)]
80pub(crate) struct FieldAssociatedValueExpected {
81    #[primary_span]
82    pub span: Span,
83    pub name: Symbol,
84}
85
86#[derive(Diagnostic)]
87#[diag(codegen_ssa_no_field)]
88pub(crate) struct NoField {
89    #[primary_span]
90    pub span: Span,
91    pub name: Symbol,
92}
93
94#[derive(Diagnostic)]
95#[diag(codegen_ssa_lib_def_write_failure)]
96pub(crate) struct LibDefWriteFailure {
97    pub error: Error,
98}
99
100#[derive(Diagnostic)]
101#[diag(codegen_ssa_version_script_write_failure)]
102pub(crate) struct VersionScriptWriteFailure {
103    pub error: Error,
104}
105
106#[derive(Diagnostic)]
107#[diag(codegen_ssa_symbol_file_write_failure)]
108pub(crate) struct SymbolFileWriteFailure {
109    pub error: Error,
110}
111
112#[derive(Diagnostic)]
113#[diag(codegen_ssa_ld64_unimplemented_modifier)]
114pub(crate) struct Ld64UnimplementedModifier;
115
116#[derive(Diagnostic)]
117#[diag(codegen_ssa_linker_unsupported_modifier)]
118pub(crate) struct LinkerUnsupportedModifier;
119
120#[derive(Diagnostic)]
121#[diag(codegen_ssa_L4Bender_exporting_symbols_unimplemented)]
122pub(crate) struct L4BenderExportingSymbolsUnimplemented;
123
124#[derive(Diagnostic)]
125#[diag(codegen_ssa_no_natvis_directory)]
126pub(crate) struct NoNatvisDirectory {
127    pub error: Error,
128}
129
130#[derive(Diagnostic)]
131#[diag(codegen_ssa_no_saved_object_file)]
132pub(crate) struct NoSavedObjectFile<'a> {
133    pub cgu_name: &'a str,
134}
135
136#[derive(Diagnostic)]
137#[diag(codegen_ssa_requires_rust_abi, code = E0737)]
138pub(crate) struct RequiresRustAbi {
139    #[primary_span]
140    pub span: Span,
141}
142
143#[derive(Diagnostic)]
144#[diag(codegen_ssa_null_on_export, code = E0648)]
145pub(crate) struct NullOnExport {
146    #[primary_span]
147    pub span: Span,
148}
149
150#[derive(Diagnostic)]
151#[diag(codegen_ssa_unsupported_instruction_set, code = E0779)]
152pub(crate) struct UnsupportedInstructionSet {
153    #[primary_span]
154    pub span: Span,
155}
156
157#[derive(Diagnostic)]
158#[diag(codegen_ssa_invalid_instruction_set, code = E0779)]
159pub(crate) struct InvalidInstructionSet {
160    #[primary_span]
161    pub span: Span,
162}
163
164#[derive(Diagnostic)]
165#[diag(codegen_ssa_bare_instruction_set, code = E0778)]
166pub(crate) struct BareInstructionSet {
167    #[primary_span]
168    pub span: Span,
169}
170
171#[derive(Diagnostic)]
172#[diag(codegen_ssa_multiple_instruction_set, code = E0779)]
173pub(crate) struct MultipleInstructionSet {
174    #[primary_span]
175    pub span: Span,
176}
177
178#[derive(Diagnostic)]
179#[diag(codegen_ssa_expected_name_value_pair)]
180pub(crate) struct ExpectedNameValuePair {
181    #[primary_span]
182    pub span: Span,
183}
184
185#[derive(Diagnostic)]
186#[diag(codegen_ssa_unexpected_parameter_name)]
187pub(crate) struct UnexpectedParameterName {
188    #[primary_span]
189    #[label]
190    pub span: Span,
191    pub prefix_nops: Symbol,
192    pub entry_nops: Symbol,
193}
194
195#[derive(Diagnostic)]
196#[diag(codegen_ssa_invalid_literal_value)]
197pub(crate) struct InvalidLiteralValue {
198    #[primary_span]
199    #[label]
200    pub span: Span,
201}
202
203#[derive(Diagnostic)]
204#[diag(codegen_ssa_out_of_range_integer)]
205pub(crate) struct OutOfRangeInteger {
206    #[primary_span]
207    #[label]
208    pub span: Span,
209}
210
211#[derive(Diagnostic)]
212#[diag(codegen_ssa_expected_one_argument, code = E0534)]
213pub(crate) struct ExpectedOneArgument {
214    #[primary_span]
215    pub span: Span,
216}
217
218#[derive(Diagnostic)]
219#[diag(codegen_ssa_expected_one_argument, code = E0722)]
220pub(crate) struct ExpectedOneArgumentOptimize {
221    #[primary_span]
222    pub span: Span,
223}
224
225#[derive(Diagnostic)]
226#[diag(codegen_ssa_invalid_argument, code = E0535)]
227#[help]
228pub(crate) struct InvalidArgument {
229    #[primary_span]
230    pub span: Span,
231}
232
233#[derive(Diagnostic)]
234#[diag(codegen_ssa_invalid_argument, code = E0722)]
235pub(crate) struct InvalidArgumentOptimize {
236    #[primary_span]
237    pub span: Span,
238}
239
240#[derive(Diagnostic)]
241#[diag(codegen_ssa_copy_path_buf)]
242pub(crate) struct CopyPathBuf {
243    pub source_file: PathBuf,
244    pub output_path: PathBuf,
245    pub error: Error,
246}
247
248// Reports Paths using `Debug` implementation rather than Path's `Display` implementation.
249#[derive(Diagnostic)]
250#[diag(codegen_ssa_copy_path)]
251pub struct CopyPath<'a> {
252    from: DebugArgPath<'a>,
253    to: DebugArgPath<'a>,
254    error: Error,
255}
256
257impl<'a> CopyPath<'a> {
258    pub fn new(from: &'a Path, to: &'a Path, error: Error) -> CopyPath<'a> {
259        CopyPath { from: DebugArgPath(from), to: DebugArgPath(to), error }
260    }
261}
262
263struct DebugArgPath<'a>(pub &'a Path);
264
265impl IntoDiagArg for DebugArgPath<'_> {
266    fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> rustc_errors::DiagArgValue {
267        DiagArgValue::Str(Cow::Owned(format!("{:?}", self.0)))
268    }
269}
270
271#[derive(Diagnostic)]
272#[diag(codegen_ssa_binary_output_to_tty)]
273pub struct BinaryOutputToTty {
274    pub shorthand: &'static str,
275}
276
277#[derive(Diagnostic)]
278#[diag(codegen_ssa_ignoring_emit_path)]
279pub struct IgnoringEmitPath {
280    pub extension: &'static str,
281}
282
283#[derive(Diagnostic)]
284#[diag(codegen_ssa_ignoring_output)]
285pub struct IgnoringOutput {
286    pub extension: &'static str,
287}
288
289#[derive(Diagnostic)]
290#[diag(codegen_ssa_create_temp_dir)]
291pub(crate) struct CreateTempDir {
292    pub error: Error,
293}
294
295#[derive(Diagnostic)]
296#[diag(codegen_ssa_add_native_library)]
297pub(crate) struct AddNativeLibrary {
298    pub library_path: PathBuf,
299    pub error: Error,
300}
301
302#[derive(Diagnostic)]
303#[diag(codegen_ssa_multiple_external_func_decl)]
304pub(crate) struct MultipleExternalFuncDecl<'a> {
305    #[primary_span]
306    pub span: Span,
307    pub function: Symbol,
308    pub library_name: &'a str,
309}
310
311#[derive(Diagnostic)]
312pub enum LinkRlibError {
313    #[diag(codegen_ssa_rlib_missing_format)]
314    MissingFormat,
315
316    #[diag(codegen_ssa_rlib_only_rmeta_found)]
317    OnlyRmetaFound { crate_name: Symbol },
318
319    #[diag(codegen_ssa_rlib_not_found)]
320    NotFound { crate_name: Symbol },
321
322    #[diag(codegen_ssa_rlib_incompatible_dependency_formats)]
323    IncompatibleDependencyFormats { ty1: String, ty2: String, list1: String, list2: String },
324}
325
326pub(crate) struct ThorinErrorWrapper(pub thorin::Error);
327
328impl<G: EmissionGuarantee> Diagnostic<'_, G> for ThorinErrorWrapper {
329    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
330        let build = |msg| Diag::new(dcx, level, msg);
331        match self.0 {
332            thorin::Error::ReadInput(_) => build(fluent::codegen_ssa_thorin_read_input_failure),
333            thorin::Error::ParseFileKind(_) => {
334                build(fluent::codegen_ssa_thorin_parse_input_file_kind)
335            }
336            thorin::Error::ParseObjectFile(_) => {
337                build(fluent::codegen_ssa_thorin_parse_input_object_file)
338            }
339            thorin::Error::ParseArchiveFile(_) => {
340                build(fluent::codegen_ssa_thorin_parse_input_archive_file)
341            }
342            thorin::Error::ParseArchiveMember(_) => {
343                build(fluent::codegen_ssa_thorin_parse_archive_member)
344            }
345            thorin::Error::InvalidInputKind => build(fluent::codegen_ssa_thorin_invalid_input_kind),
346            thorin::Error::DecompressData(_) => build(fluent::codegen_ssa_thorin_decompress_data),
347            thorin::Error::NamelessSection(_, offset) => {
348                build(fluent::codegen_ssa_thorin_section_without_name)
349                    .with_arg("offset", format!("0x{offset:08x}"))
350            }
351            thorin::Error::RelocationWithInvalidSymbol(section, offset) => {
352                build(fluent::codegen_ssa_thorin_relocation_with_invalid_symbol)
353                    .with_arg("section", section)
354                    .with_arg("offset", format!("0x{offset:08x}"))
355            }
356            thorin::Error::MultipleRelocations(section, offset) => {
357                build(fluent::codegen_ssa_thorin_multiple_relocations)
358                    .with_arg("section", section)
359                    .with_arg("offset", format!("0x{offset:08x}"))
360            }
361            thorin::Error::UnsupportedRelocation(section, offset) => {
362                build(fluent::codegen_ssa_thorin_unsupported_relocation)
363                    .with_arg("section", section)
364                    .with_arg("offset", format!("0x{offset:08x}"))
365            }
366            thorin::Error::MissingDwoName(id) => build(fluent::codegen_ssa_thorin_missing_dwo_name)
367                .with_arg("id", format!("0x{id:08x}")),
368            thorin::Error::NoCompilationUnits => {
369                build(fluent::codegen_ssa_thorin_no_compilation_units)
370            }
371            thorin::Error::NoDie => build(fluent::codegen_ssa_thorin_no_die),
372            thorin::Error::TopLevelDieNotUnit => {
373                build(fluent::codegen_ssa_thorin_top_level_die_not_unit)
374            }
375            thorin::Error::MissingRequiredSection(section) => {
376                build(fluent::codegen_ssa_thorin_missing_required_section)
377                    .with_arg("section", section)
378            }
379            thorin::Error::ParseUnitAbbreviations(_) => {
380                build(fluent::codegen_ssa_thorin_parse_unit_abbreviations)
381            }
382            thorin::Error::ParseUnitAttribute(_) => {
383                build(fluent::codegen_ssa_thorin_parse_unit_attribute)
384            }
385            thorin::Error::ParseUnitHeader(_) => {
386                build(fluent::codegen_ssa_thorin_parse_unit_header)
387            }
388            thorin::Error::ParseUnit(_) => build(fluent::codegen_ssa_thorin_parse_unit),
389            thorin::Error::IncompatibleIndexVersion(section, format, actual) => {
390                build(fluent::codegen_ssa_thorin_incompatible_index_version)
391                    .with_arg("section", section)
392                    .with_arg("actual", actual)
393                    .with_arg("format", format)
394            }
395            thorin::Error::OffsetAtIndex(_, index) => {
396                build(fluent::codegen_ssa_thorin_offset_at_index).with_arg("index", index)
397            }
398            thorin::Error::StrAtOffset(_, offset) => {
399                build(fluent::codegen_ssa_thorin_str_at_offset)
400                    .with_arg("offset", format!("0x{offset:08x}"))
401            }
402            thorin::Error::ParseIndex(_, section) => {
403                build(fluent::codegen_ssa_thorin_parse_index).with_arg("section", section)
404            }
405            thorin::Error::UnitNotInIndex(unit) => {
406                build(fluent::codegen_ssa_thorin_unit_not_in_index)
407                    .with_arg("unit", format!("0x{unit:08x}"))
408            }
409            thorin::Error::RowNotInIndex(_, row) => {
410                build(fluent::codegen_ssa_thorin_row_not_in_index).with_arg("row", row)
411            }
412            thorin::Error::SectionNotInRow => build(fluent::codegen_ssa_thorin_section_not_in_row),
413            thorin::Error::EmptyUnit(unit) => build(fluent::codegen_ssa_thorin_empty_unit)
414                .with_arg("unit", format!("0x{unit:08x}")),
415            thorin::Error::MultipleDebugInfoSection => {
416                build(fluent::codegen_ssa_thorin_multiple_debug_info_section)
417            }
418            thorin::Error::MultipleDebugTypesSection => {
419                build(fluent::codegen_ssa_thorin_multiple_debug_types_section)
420            }
421            thorin::Error::NotSplitUnit => build(fluent::codegen_ssa_thorin_not_split_unit),
422            thorin::Error::DuplicateUnit(unit) => build(fluent::codegen_ssa_thorin_duplicate_unit)
423                .with_arg("unit", format!("0x{unit:08x}")),
424            thorin::Error::MissingReferencedUnit(unit) => {
425                build(fluent::codegen_ssa_thorin_missing_referenced_unit)
426                    .with_arg("unit", format!("0x{unit:08x}"))
427            }
428            thorin::Error::NoOutputObjectCreated => {
429                build(fluent::codegen_ssa_thorin_not_output_object_created)
430            }
431            thorin::Error::MixedInputEncodings => {
432                build(fluent::codegen_ssa_thorin_mixed_input_encodings)
433            }
434            thorin::Error::Io(e) => {
435                build(fluent::codegen_ssa_thorin_io).with_arg("error", format!("{e}"))
436            }
437            thorin::Error::ObjectRead(e) => {
438                build(fluent::codegen_ssa_thorin_object_read).with_arg("error", format!("{e}"))
439            }
440            thorin::Error::ObjectWrite(e) => {
441                build(fluent::codegen_ssa_thorin_object_write).with_arg("error", format!("{e}"))
442            }
443            thorin::Error::GimliRead(e) => {
444                build(fluent::codegen_ssa_thorin_gimli_read).with_arg("error", format!("{e}"))
445            }
446            thorin::Error::GimliWrite(e) => {
447                build(fluent::codegen_ssa_thorin_gimli_write).with_arg("error", format!("{e}"))
448            }
449            _ => unimplemented!("Untranslated thorin error"),
450        }
451    }
452}
453
454pub(crate) struct LinkingFailed<'a> {
455    pub linker_path: &'a Path,
456    pub exit_status: ExitStatus,
457    pub command: Command,
458    pub escaped_output: String,
459    pub verbose: bool,
460    pub sysroot_dir: PathBuf,
461}
462
463impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
464    fn into_diag(mut self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
465        let mut diag = Diag::new(dcx, level, fluent::codegen_ssa_linking_failed);
466        diag.arg("linker_path", format!("{}", self.linker_path.display()));
467        diag.arg("exit_status", format!("{}", self.exit_status));
468
469        let contains_undefined_ref = self.escaped_output.contains("undefined reference to");
470
471        if self.verbose {
472            diag.note(format!("{:?}", self.command));
473        } else {
474            self.command.env_clear();
475
476            enum ArgGroup {
477                Regular(OsString),
478                Objects(usize),
479                Rlibs(PathBuf, Vec<OsString>),
480            }
481
482            // Omit rust object files and fold rlibs in the error by default to make linker errors a
483            // bit less verbose.
484            let orig_args = self.command.take_args();
485            let mut args: Vec<ArgGroup> = vec![];
486            for arg in orig_args {
487                if arg.as_encoded_bytes().ends_with(b".rcgu.o") {
488                    if let Some(ArgGroup::Objects(n)) = args.last_mut() {
489                        *n += 1;
490                    } else {
491                        args.push(ArgGroup::Objects(1));
492                    }
493                } else if arg.as_encoded_bytes().ends_with(b".rlib") {
494                    let rlib_path = Path::new(&arg);
495                    let dir = rlib_path.parent().unwrap();
496                    let filename = rlib_path.file_name().unwrap().to_owned();
497                    if let Some(ArgGroup::Rlibs(parent, rlibs)) = args.last_mut() {
498                        if parent == dir {
499                            rlibs.push(filename);
500                        } else {
501                            args.push(ArgGroup::Rlibs(dir.to_owned(), vec![filename]));
502                        }
503                    } else {
504                        args.push(ArgGroup::Rlibs(dir.to_owned(), vec![filename]));
505                    }
506                } else {
507                    args.push(ArgGroup::Regular(arg));
508                }
509            }
510            let crate_hash = regex::bytes::Regex::new(r"-[0-9a-f]+\.rlib$").unwrap();
511            self.command.args(args.into_iter().map(|arg_group| {
512                match arg_group {
513                    // SAFETY: we are only matching on ASCII, not any surrogate pairs, so any replacements we do will still be valid.
514                    ArgGroup::Regular(arg) => unsafe {
515                        use bstr::ByteSlice;
516                        OsString::from_encoded_bytes_unchecked(
517                            arg.as_encoded_bytes().replace(
518                                self.sysroot_dir.as_os_str().as_encoded_bytes(),
519                                b"<sysroot>",
520                            ),
521                        )
522                    },
523                    ArgGroup::Objects(n) => OsString::from(format!("<{n} object files omitted>")),
524                    ArgGroup::Rlibs(mut dir, rlibs) => {
525                        let is_sysroot_dir = match dir.strip_prefix(&self.sysroot_dir) {
526                            Ok(short) => {
527                                dir = Path::new("<sysroot>").join(short);
528                                true
529                            }
530                            Err(_) => false,
531                        };
532                        let mut arg = dir.into_os_string();
533                        arg.push("/{");
534                        let mut first = true;
535                        for mut rlib in rlibs {
536                            if !first {
537                                arg.push(",");
538                            }
539                            first = false;
540                            if is_sysroot_dir {
541                                // SAFETY: Regex works one byte at a type, and our regex will not match surrogate pairs (because it only matches ascii).
542                                rlib = unsafe {
543                                    OsString::from_encoded_bytes_unchecked(
544                                        crate_hash
545                                            .replace(rlib.as_encoded_bytes(), b"-*")
546                                            .into_owned(),
547                                    )
548                                };
549                            }
550                            arg.push(rlib);
551                        }
552                        arg.push("}.rlib");
553                        arg
554                    }
555                }
556            }));
557
558            diag.note(format!("{:?}", self.command).trim_start_matches("env -i").to_owned());
559            diag.note("some arguments are omitted. use `--verbose` to show all linker arguments");
560        }
561
562        diag.note(self.escaped_output);
563
564        // Trying to match an error from OS linkers
565        // which by now we have no way to translate.
566        if contains_undefined_ref {
567            diag.note(fluent::codegen_ssa_extern_funcs_not_found)
568                .note(fluent::codegen_ssa_specify_libraries_to_link);
569
570            if rustc_session::utils::was_invoked_from_cargo() {
571                diag.note(fluent::codegen_ssa_use_cargo_directive);
572            }
573        }
574        diag
575    }
576}
577
578#[derive(Diagnostic)]
579#[diag(codegen_ssa_link_exe_unexpected_error)]
580pub(crate) struct LinkExeUnexpectedError;
581
582#[derive(Diagnostic)]
583#[diag(codegen_ssa_repair_vs_build_tools)]
584pub(crate) struct RepairVSBuildTools;
585
586#[derive(Diagnostic)]
587#[diag(codegen_ssa_missing_cpp_build_tool_component)]
588pub(crate) struct MissingCppBuildToolComponent;
589
590#[derive(Diagnostic)]
591#[diag(codegen_ssa_select_cpp_build_tool_workload)]
592pub(crate) struct SelectCppBuildToolWorkload;
593
594#[derive(Diagnostic)]
595#[diag(codegen_ssa_visual_studio_not_installed)]
596pub(crate) struct VisualStudioNotInstalled;
597
598#[derive(Diagnostic)]
599#[diag(codegen_ssa_linker_not_found)]
600#[note]
601pub(crate) struct LinkerNotFound {
602    pub linker_path: PathBuf,
603    pub error: Error,
604}
605
606#[derive(Diagnostic)]
607#[diag(codegen_ssa_unable_to_exe_linker)]
608#[note]
609#[note(codegen_ssa_command_note)]
610pub(crate) struct UnableToExeLinker {
611    pub linker_path: PathBuf,
612    pub error: Error,
613    pub command_formatted: String,
614}
615
616#[derive(Diagnostic)]
617#[diag(codegen_ssa_msvc_missing_linker)]
618pub(crate) struct MsvcMissingLinker;
619
620#[derive(Diagnostic)]
621#[diag(codegen_ssa_self_contained_linker_missing)]
622pub(crate) struct SelfContainedLinkerMissing;
623
624#[derive(Diagnostic)]
625#[diag(codegen_ssa_check_installed_visual_studio)]
626pub(crate) struct CheckInstalledVisualStudio;
627
628#[derive(Diagnostic)]
629#[diag(codegen_ssa_insufficient_vs_code_product)]
630pub(crate) struct InsufficientVSCodeProduct;
631
632#[derive(Diagnostic)]
633#[diag(codegen_ssa_cpu_required)]
634pub(crate) struct CpuRequired;
635
636#[derive(Diagnostic)]
637#[diag(codegen_ssa_processing_dymutil_failed)]
638#[note]
639pub(crate) struct ProcessingDymutilFailed {
640    pub status: ExitStatus,
641    pub output: String,
642}
643
644#[derive(Diagnostic)]
645#[diag(codegen_ssa_unable_to_run_dsymutil)]
646pub(crate) struct UnableToRunDsymutil {
647    pub error: Error,
648}
649
650#[derive(Diagnostic)]
651#[diag(codegen_ssa_stripping_debug_info_failed)]
652#[note]
653pub(crate) struct StrippingDebugInfoFailed<'a> {
654    pub util: &'a str,
655    pub status: ExitStatus,
656    pub output: String,
657}
658
659#[derive(Diagnostic)]
660#[diag(codegen_ssa_unable_to_run)]
661pub(crate) struct UnableToRun<'a> {
662    pub util: &'a str,
663    pub error: Error,
664}
665
666#[derive(Diagnostic)]
667#[diag(codegen_ssa_linker_file_stem)]
668pub(crate) struct LinkerFileStem;
669
670#[derive(Diagnostic)]
671#[diag(codegen_ssa_static_library_native_artifacts)]
672pub(crate) struct StaticLibraryNativeArtifacts;
673
674#[derive(Diagnostic)]
675#[diag(codegen_ssa_static_library_native_artifacts_to_file)]
676pub(crate) struct StaticLibraryNativeArtifactsToFile<'a> {
677    pub path: &'a Path,
678}
679
680#[derive(Diagnostic)]
681#[diag(codegen_ssa_link_script_unavailable)]
682pub(crate) struct LinkScriptUnavailable;
683
684#[derive(Diagnostic)]
685#[diag(codegen_ssa_link_script_write_failure)]
686pub(crate) struct LinkScriptWriteFailure {
687    pub path: PathBuf,
688    pub error: Error,
689}
690
691#[derive(Diagnostic)]
692#[diag(codegen_ssa_failed_to_write)]
693pub(crate) struct FailedToWrite {
694    pub path: PathBuf,
695    pub error: Error,
696}
697
698#[derive(Diagnostic)]
699#[diag(codegen_ssa_unable_to_write_debugger_visualizer)]
700pub(crate) struct UnableToWriteDebuggerVisualizer {
701    pub path: PathBuf,
702    pub error: Error,
703}
704
705#[derive(Diagnostic)]
706#[diag(codegen_ssa_rlib_archive_build_failure)]
707pub(crate) struct RlibArchiveBuildFailure {
708    pub path: PathBuf,
709    pub error: Error,
710}
711
712#[derive(Diagnostic)]
713// Public for rustc_codegen_llvm::back::archive
714pub enum ExtractBundledLibsError<'a> {
715    #[diag(codegen_ssa_extract_bundled_libs_open_file)]
716    OpenFile { rlib: &'a Path, error: Box<dyn std::error::Error> },
717
718    #[diag(codegen_ssa_extract_bundled_libs_mmap_file)]
719    MmapFile { rlib: &'a Path, error: Box<dyn std::error::Error> },
720
721    #[diag(codegen_ssa_extract_bundled_libs_parse_archive)]
722    ParseArchive { rlib: &'a Path, error: Box<dyn std::error::Error> },
723
724    #[diag(codegen_ssa_extract_bundled_libs_read_entry)]
725    ReadEntry { rlib: &'a Path, error: Box<dyn std::error::Error> },
726
727    #[diag(codegen_ssa_extract_bundled_libs_archive_member)]
728    ArchiveMember { rlib: &'a Path, error: Box<dyn std::error::Error> },
729
730    #[diag(codegen_ssa_extract_bundled_libs_convert_name)]
731    ConvertName { rlib: &'a Path, error: Box<dyn std::error::Error> },
732
733    #[diag(codegen_ssa_extract_bundled_libs_write_file)]
734    WriteFile { rlib: &'a Path, error: Box<dyn std::error::Error> },
735
736    #[diag(codegen_ssa_extract_bundled_libs_write_file)]
737    ExtractSection { rlib: &'a Path, error: Box<dyn std::error::Error> },
738}
739
740#[derive(Diagnostic)]
741#[diag(codegen_ssa_read_file)]
742pub(crate) struct ReadFileError {
743    pub message: std::io::Error,
744}
745
746#[derive(Diagnostic)]
747#[diag(codegen_ssa_unsupported_link_self_contained)]
748pub(crate) struct UnsupportedLinkSelfContained;
749
750#[derive(Diagnostic)]
751#[diag(codegen_ssa_archive_build_failure)]
752// Public for rustc_codegen_llvm::back::archive
753pub struct ArchiveBuildFailure {
754    pub path: PathBuf,
755    pub error: std::io::Error,
756}
757
758#[derive(Diagnostic)]
759#[diag(codegen_ssa_unknown_archive_kind)]
760// Public for rustc_codegen_llvm::back::archive
761pub struct UnknownArchiveKind<'a> {
762    pub kind: &'a str,
763}
764
765#[derive(Diagnostic)]
766#[diag(codegen_ssa_expected_used_symbol)]
767pub(crate) struct ExpectedUsedSymbol {
768    #[primary_span]
769    pub span: Span,
770}
771
772#[derive(Diagnostic)]
773#[diag(codegen_ssa_multiple_main_functions)]
774#[help]
775pub(crate) struct MultipleMainFunctions {
776    #[primary_span]
777    pub span: Span,
778}
779
780#[derive(Diagnostic)]
781#[diag(codegen_ssa_metadata_object_file_write)]
782pub(crate) struct MetadataObjectFileWrite {
783    pub error: Error,
784}
785
786#[derive(Diagnostic)]
787#[diag(codegen_ssa_invalid_windows_subsystem)]
788pub(crate) struct InvalidWindowsSubsystem {
789    pub subsystem: Symbol,
790}
791
792#[derive(Diagnostic)]
793#[diag(codegen_ssa_shuffle_indices_evaluation)]
794pub(crate) struct ShuffleIndicesEvaluation {
795    #[primary_span]
796    pub span: Span,
797}
798
799#[derive(Diagnostic)]
800pub enum InvalidMonomorphization<'tcx> {
801    #[diag(codegen_ssa_invalid_monomorphization_basic_integer_type, code = E0511)]
802    BasicIntegerType {
803        #[primary_span]
804        span: Span,
805        name: Symbol,
806        ty: Ty<'tcx>,
807    },
808
809    #[diag(codegen_ssa_invalid_monomorphization_basic_float_type, code = E0511)]
810    BasicFloatType {
811        #[primary_span]
812        span: Span,
813        name: Symbol,
814        ty: Ty<'tcx>,
815    },
816
817    #[diag(codegen_ssa_invalid_monomorphization_float_to_int_unchecked, code = E0511)]
818    FloatToIntUnchecked {
819        #[primary_span]
820        span: Span,
821        ty: Ty<'tcx>,
822    },
823
824    #[diag(codegen_ssa_invalid_monomorphization_floating_point_vector, code = E0511)]
825    FloatingPointVector {
826        #[primary_span]
827        span: Span,
828        name: Symbol,
829        f_ty: FloatTy,
830        in_ty: Ty<'tcx>,
831    },
832
833    #[diag(codegen_ssa_invalid_monomorphization_floating_point_type, code = E0511)]
834    FloatingPointType {
835        #[primary_span]
836        span: Span,
837        name: Symbol,
838        in_ty: Ty<'tcx>,
839    },
840
841    #[diag(codegen_ssa_invalid_monomorphization_unrecognized_intrinsic, code = E0511)]
842    UnrecognizedIntrinsic {
843        #[primary_span]
844        span: Span,
845        name: Symbol,
846    },
847
848    #[diag(codegen_ssa_invalid_monomorphization_simd_argument, code = E0511)]
849    SimdArgument {
850        #[primary_span]
851        span: Span,
852        name: Symbol,
853        ty: Ty<'tcx>,
854    },
855
856    #[diag(codegen_ssa_invalid_monomorphization_simd_input, code = E0511)]
857    SimdInput {
858        #[primary_span]
859        span: Span,
860        name: Symbol,
861        ty: Ty<'tcx>,
862    },
863
864    #[diag(codegen_ssa_invalid_monomorphization_simd_first, code = E0511)]
865    SimdFirst {
866        #[primary_span]
867        span: Span,
868        name: Symbol,
869        ty: Ty<'tcx>,
870    },
871
872    #[diag(codegen_ssa_invalid_monomorphization_simd_second, code = E0511)]
873    SimdSecond {
874        #[primary_span]
875        span: Span,
876        name: Symbol,
877        ty: Ty<'tcx>,
878    },
879
880    #[diag(codegen_ssa_invalid_monomorphization_simd_third, code = E0511)]
881    SimdThird {
882        #[primary_span]
883        span: Span,
884        name: Symbol,
885        ty: Ty<'tcx>,
886    },
887
888    #[diag(codegen_ssa_invalid_monomorphization_simd_return, code = E0511)]
889    SimdReturn {
890        #[primary_span]
891        span: Span,
892        name: Symbol,
893        ty: Ty<'tcx>,
894    },
895
896    #[diag(codegen_ssa_invalid_monomorphization_invalid_bitmask, code = E0511)]
897    InvalidBitmask {
898        #[primary_span]
899        span: Span,
900        name: Symbol,
901        mask_ty: Ty<'tcx>,
902        expected_int_bits: u64,
903        expected_bytes: u64,
904    },
905
906    #[diag(codegen_ssa_invalid_monomorphization_return_length_input_type, code = E0511)]
907    ReturnLengthInputType {
908        #[primary_span]
909        span: Span,
910        name: Symbol,
911        in_len: u64,
912        in_ty: Ty<'tcx>,
913        ret_ty: Ty<'tcx>,
914        out_len: u64,
915    },
916
917    #[diag(codegen_ssa_invalid_monomorphization_second_argument_length, code = E0511)]
918    SecondArgumentLength {
919        #[primary_span]
920        span: Span,
921        name: Symbol,
922        in_len: u64,
923        in_ty: Ty<'tcx>,
924        arg_ty: Ty<'tcx>,
925        out_len: u64,
926    },
927
928    #[diag(codegen_ssa_invalid_monomorphization_third_argument_length, code = E0511)]
929    ThirdArgumentLength {
930        #[primary_span]
931        span: Span,
932        name: Symbol,
933        in_len: u64,
934        in_ty: Ty<'tcx>,
935        arg_ty: Ty<'tcx>,
936        out_len: u64,
937    },
938
939    #[diag(codegen_ssa_invalid_monomorphization_return_integer_type, code = E0511)]
940    ReturnIntegerType {
941        #[primary_span]
942        span: Span,
943        name: Symbol,
944        ret_ty: Ty<'tcx>,
945        out_ty: Ty<'tcx>,
946    },
947
948    #[diag(codegen_ssa_invalid_monomorphization_simd_shuffle, code = E0511)]
949    SimdShuffle {
950        #[primary_span]
951        span: Span,
952        name: Symbol,
953        ty: Ty<'tcx>,
954    },
955
956    #[diag(codegen_ssa_invalid_monomorphization_return_length, code = E0511)]
957    ReturnLength {
958        #[primary_span]
959        span: Span,
960        name: Symbol,
961        in_len: u64,
962        ret_ty: Ty<'tcx>,
963        out_len: u64,
964    },
965
966    #[diag(codegen_ssa_invalid_monomorphization_return_element, code = E0511)]
967    ReturnElement {
968        #[primary_span]
969        span: Span,
970        name: Symbol,
971        in_elem: Ty<'tcx>,
972        in_ty: Ty<'tcx>,
973        ret_ty: Ty<'tcx>,
974        out_ty: Ty<'tcx>,
975    },
976
977    #[diag(codegen_ssa_invalid_monomorphization_simd_index_out_of_bounds, code = E0511)]
978    SimdIndexOutOfBounds {
979        #[primary_span]
980        span: Span,
981        name: Symbol,
982        arg_idx: u64,
983        total_len: u128,
984    },
985
986    #[diag(codegen_ssa_invalid_monomorphization_inserted_type, code = E0511)]
987    InsertedType {
988        #[primary_span]
989        span: Span,
990        name: Symbol,
991        in_elem: Ty<'tcx>,
992        in_ty: Ty<'tcx>,
993        out_ty: Ty<'tcx>,
994    },
995
996    #[diag(codegen_ssa_invalid_monomorphization_return_type, code = E0511)]
997    ReturnType {
998        #[primary_span]
999        span: Span,
1000        name: Symbol,
1001        in_elem: Ty<'tcx>,
1002        in_ty: Ty<'tcx>,
1003        ret_ty: Ty<'tcx>,
1004    },
1005
1006    #[diag(codegen_ssa_invalid_monomorphization_expected_return_type, code = E0511)]
1007    ExpectedReturnType {
1008        #[primary_span]
1009        span: Span,
1010        name: Symbol,
1011        in_ty: Ty<'tcx>,
1012        ret_ty: Ty<'tcx>,
1013    },
1014
1015    #[diag(codegen_ssa_invalid_monomorphization_mismatched_lengths, code = E0511)]
1016    MismatchedLengths {
1017        #[primary_span]
1018        span: Span,
1019        name: Symbol,
1020        m_len: u64,
1021        v_len: u64,
1022    },
1023
1024    #[diag(codegen_ssa_invalid_monomorphization_mask_wrong_element_type, code = E0511)]
1025    MaskWrongElementType {
1026        #[primary_span]
1027        span: Span,
1028        name: Symbol,
1029        ty: Ty<'tcx>,
1030    },
1031
1032    #[diag(codegen_ssa_invalid_monomorphization_cannot_return, code = E0511)]
1033    CannotReturn {
1034        #[primary_span]
1035        span: Span,
1036        name: Symbol,
1037        ret_ty: Ty<'tcx>,
1038        expected_int_bits: u64,
1039        expected_bytes: u64,
1040    },
1041
1042    #[diag(codegen_ssa_invalid_monomorphization_expected_element_type, code = E0511)]
1043    ExpectedElementType {
1044        #[primary_span]
1045        span: Span,
1046        name: Symbol,
1047        expected_element: Ty<'tcx>,
1048        second_arg: Ty<'tcx>,
1049        in_elem: Ty<'tcx>,
1050        in_ty: Ty<'tcx>,
1051        mutability: ExpectedPointerMutability,
1052    },
1053
1054    #[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol_of_size, code = E0511)]
1055    UnsupportedSymbolOfSize {
1056        #[primary_span]
1057        span: Span,
1058        name: Symbol,
1059        symbol: Symbol,
1060        in_ty: Ty<'tcx>,
1061        in_elem: Ty<'tcx>,
1062        size: u64,
1063        ret_ty: Ty<'tcx>,
1064    },
1065
1066    #[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol, code = E0511)]
1067    UnsupportedSymbol {
1068        #[primary_span]
1069        span: Span,
1070        name: Symbol,
1071        symbol: Symbol,
1072        in_ty: Ty<'tcx>,
1073        in_elem: Ty<'tcx>,
1074        ret_ty: Ty<'tcx>,
1075    },
1076
1077    #[diag(codegen_ssa_invalid_monomorphization_cast_wide_pointer, code = E0511)]
1078    CastWidePointer {
1079        #[primary_span]
1080        span: Span,
1081        name: Symbol,
1082        ty: Ty<'tcx>,
1083    },
1084
1085    #[diag(codegen_ssa_invalid_monomorphization_expected_pointer, code = E0511)]
1086    ExpectedPointer {
1087        #[primary_span]
1088        span: Span,
1089        name: Symbol,
1090        ty: Ty<'tcx>,
1091    },
1092
1093    #[diag(codegen_ssa_invalid_monomorphization_expected_usize, code = E0511)]
1094    ExpectedUsize {
1095        #[primary_span]
1096        span: Span,
1097        name: Symbol,
1098        ty: Ty<'tcx>,
1099    },
1100
1101    #[diag(codegen_ssa_invalid_monomorphization_unsupported_cast, code = E0511)]
1102    UnsupportedCast {
1103        #[primary_span]
1104        span: Span,
1105        name: Symbol,
1106        in_ty: Ty<'tcx>,
1107        in_elem: Ty<'tcx>,
1108        ret_ty: Ty<'tcx>,
1109        out_elem: Ty<'tcx>,
1110    },
1111
1112    #[diag(codegen_ssa_invalid_monomorphization_unsupported_operation, code = E0511)]
1113    UnsupportedOperation {
1114        #[primary_span]
1115        span: Span,
1116        name: Symbol,
1117        in_ty: Ty<'tcx>,
1118        in_elem: Ty<'tcx>,
1119    },
1120
1121    #[diag(codegen_ssa_invalid_monomorphization_expected_vector_element_type, code = E0511)]
1122    ExpectedVectorElementType {
1123        #[primary_span]
1124        span: Span,
1125        name: Symbol,
1126        expected_element: Ty<'tcx>,
1127        vector_type: Ty<'tcx>,
1128    },
1129}
1130
1131pub enum ExpectedPointerMutability {
1132    Mut,
1133    Not,
1134}
1135
1136impl IntoDiagArg for ExpectedPointerMutability {
1137    fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
1138        match self {
1139            ExpectedPointerMutability::Mut => DiagArgValue::Str(Cow::Borrowed("*mut")),
1140            ExpectedPointerMutability::Not => DiagArgValue::Str(Cow::Borrowed("*_")),
1141        }
1142    }
1143}
1144
1145#[derive(Diagnostic)]
1146#[diag(codegen_ssa_invalid_no_sanitize)]
1147#[note]
1148pub(crate) struct InvalidNoSanitize {
1149    #[primary_span]
1150    pub span: Span,
1151}
1152
1153#[derive(Diagnostic)]
1154#[diag(codegen_ssa_invalid_link_ordinal_nargs)]
1155#[note]
1156pub(crate) struct InvalidLinkOrdinalNargs {
1157    #[primary_span]
1158    pub span: Span,
1159}
1160
1161#[derive(Diagnostic)]
1162#[diag(codegen_ssa_illegal_link_ordinal_format)]
1163#[note]
1164pub(crate) struct InvalidLinkOrdinalFormat {
1165    #[primary_span]
1166    pub span: Span,
1167}
1168
1169#[derive(Diagnostic)]
1170#[diag(codegen_ssa_target_feature_safe_trait)]
1171pub(crate) struct TargetFeatureSafeTrait {
1172    #[primary_span]
1173    #[label]
1174    pub span: Span,
1175    #[label(codegen_ssa_label_def)]
1176    pub def: Span,
1177}
1178
1179#[derive(Diagnostic)]
1180#[diag(codegen_ssa_forbidden_target_feature_attr)]
1181pub struct ForbiddenTargetFeatureAttr<'a> {
1182    #[primary_span]
1183    pub span: Span,
1184    pub feature: &'a str,
1185    pub reason: &'a str,
1186}
1187
1188#[derive(Diagnostic)]
1189#[diag(codegen_ssa_failed_to_get_layout)]
1190pub struct FailedToGetLayout<'tcx> {
1191    #[primary_span]
1192    pub span: Span,
1193    pub ty: Ty<'tcx>,
1194    pub err: LayoutError<'tcx>,
1195}
1196
1197#[derive(Diagnostic)]
1198#[diag(codegen_ssa_dlltool_fail_import_library)]
1199pub(crate) struct DlltoolFailImportLibrary<'a> {
1200    pub dlltool_path: Cow<'a, str>,
1201    pub dlltool_args: String,
1202    pub stdout: Cow<'a, str>,
1203    pub stderr: Cow<'a, str>,
1204}
1205
1206#[derive(Diagnostic)]
1207#[diag(codegen_ssa_error_writing_def_file)]
1208pub(crate) struct ErrorWritingDEFFile {
1209    pub error: std::io::Error,
1210}
1211
1212#[derive(Diagnostic)]
1213#[diag(codegen_ssa_error_calling_dlltool)]
1214pub(crate) struct ErrorCallingDllTool<'a> {
1215    pub dlltool_path: Cow<'a, str>,
1216    pub error: std::io::Error,
1217}
1218
1219#[derive(Diagnostic)]
1220#[diag(codegen_ssa_error_creating_remark_dir)]
1221pub(crate) struct ErrorCreatingRemarkDir {
1222    pub error: std::io::Error,
1223}
1224
1225#[derive(Diagnostic)]
1226#[diag(codegen_ssa_compiler_builtins_cannot_call)]
1227pub struct CompilerBuiltinsCannotCall {
1228    pub caller: String,
1229    pub callee: String,
1230    #[primary_span]
1231    pub span: Span,
1232}
1233
1234#[derive(Diagnostic)]
1235#[diag(codegen_ssa_error_creating_import_library)]
1236pub(crate) struct ErrorCreatingImportLibrary<'a> {
1237    pub lib_name: &'a str,
1238    pub error: String,
1239}
1240
1241pub struct TargetFeatureDisableOrEnable<'a> {
1242    pub features: &'a [&'a str],
1243    pub span: Option<Span>,
1244    pub missing_features: Option<MissingFeatures>,
1245}
1246
1247#[derive(Subdiagnostic)]
1248#[help(codegen_ssa_missing_features)]
1249pub struct MissingFeatures;
1250
1251impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> {
1252    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1253        let mut diag = Diag::new(dcx, level, fluent::codegen_ssa_target_feature_disable_or_enable);
1254        if let Some(span) = self.span {
1255            diag.span(span);
1256        };
1257        if let Some(missing_features) = self.missing_features {
1258            diag.subdiagnostic(missing_features);
1259        }
1260        diag.arg("features", self.features.join(", "));
1261        diag
1262    }
1263}
1264
1265#[derive(Diagnostic)]
1266#[diag(codegen_ssa_aix_strip_not_used)]
1267pub(crate) struct AixStripNotUsed;
1268
1269#[derive(LintDiagnostic)]
1270#[diag(codegen_ssa_mixed_export_name_and_no_mangle)]
1271pub(crate) struct MixedExportNameAndNoMangle {
1272    #[label]
1273    pub no_mangle: Span,
1274    pub no_mangle_attr: String,
1275    #[note]
1276    pub export_name: Span,
1277    #[suggestion(style = "verbose", code = "", applicability = "machine-applicable")]
1278    pub removal_span: Span,
1279}
1280
1281#[derive(Diagnostic, Debug)]
1282pub(crate) enum XcrunError {
1283    #[diag(codegen_ssa_xcrun_failed_invoking)]
1284    FailedInvoking { sdk_name: &'static str, command_formatted: String, error: std::io::Error },
1285
1286    #[diag(codegen_ssa_xcrun_unsuccessful)]
1287    #[note]
1288    Unsuccessful {
1289        sdk_name: &'static str,
1290        command_formatted: String,
1291        stdout: String,
1292        stderr: String,
1293    },
1294}
1295
1296#[derive(Diagnostic, Debug)]
1297#[diag(codegen_ssa_xcrun_sdk_path_warning)]
1298#[note]
1299pub(crate) struct XcrunSdkPathWarning {
1300    pub sdk_name: &'static str,
1301    pub stderr: String,
1302}
1303
1304#[derive(LintDiagnostic)]
1305#[diag(codegen_ssa_aarch64_softfloat_neon)]
1306pub(crate) struct Aarch64SoftfloatNeon;