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 UnsuportedInstructionSet {
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)]
800#[diag(codegen_ssa_missing_memory_ordering)]
801pub(crate) struct MissingMemoryOrdering;
802
803#[derive(Diagnostic)]
804#[diag(codegen_ssa_unknown_atomic_ordering)]
805pub(crate) struct UnknownAtomicOrdering;
806
807#[derive(Diagnostic)]
808#[diag(codegen_ssa_atomic_compare_exchange)]
809pub(crate) struct AtomicCompareExchange;
810
811#[derive(Diagnostic)]
812#[diag(codegen_ssa_unknown_atomic_operation)]
813pub(crate) struct UnknownAtomicOperation;
814
815#[derive(Diagnostic)]
816pub enum InvalidMonomorphization<'tcx> {
817    #[diag(codegen_ssa_invalid_monomorphization_basic_integer_type, code = E0511)]
818    BasicIntegerType {
819        #[primary_span]
820        span: Span,
821        name: Symbol,
822        ty: Ty<'tcx>,
823    },
824
825    #[diag(codegen_ssa_invalid_monomorphization_basic_float_type, code = E0511)]
826    BasicFloatType {
827        #[primary_span]
828        span: Span,
829        name: Symbol,
830        ty: Ty<'tcx>,
831    },
832
833    #[diag(codegen_ssa_invalid_monomorphization_float_to_int_unchecked, code = E0511)]
834    FloatToIntUnchecked {
835        #[primary_span]
836        span: Span,
837        ty: Ty<'tcx>,
838    },
839
840    #[diag(codegen_ssa_invalid_monomorphization_floating_point_vector, code = E0511)]
841    FloatingPointVector {
842        #[primary_span]
843        span: Span,
844        name: Symbol,
845        f_ty: FloatTy,
846        in_ty: Ty<'tcx>,
847    },
848
849    #[diag(codegen_ssa_invalid_monomorphization_floating_point_type, code = E0511)]
850    FloatingPointType {
851        #[primary_span]
852        span: Span,
853        name: Symbol,
854        in_ty: Ty<'tcx>,
855    },
856
857    #[diag(codegen_ssa_invalid_monomorphization_unrecognized_intrinsic, code = E0511)]
858    UnrecognizedIntrinsic {
859        #[primary_span]
860        span: Span,
861        name: Symbol,
862    },
863
864    #[diag(codegen_ssa_invalid_monomorphization_simd_argument, code = E0511)]
865    SimdArgument {
866        #[primary_span]
867        span: Span,
868        name: Symbol,
869        ty: Ty<'tcx>,
870    },
871
872    #[diag(codegen_ssa_invalid_monomorphization_simd_input, code = E0511)]
873    SimdInput {
874        #[primary_span]
875        span: Span,
876        name: Symbol,
877        ty: Ty<'tcx>,
878    },
879
880    #[diag(codegen_ssa_invalid_monomorphization_simd_first, code = E0511)]
881    SimdFirst {
882        #[primary_span]
883        span: Span,
884        name: Symbol,
885        ty: Ty<'tcx>,
886    },
887
888    #[diag(codegen_ssa_invalid_monomorphization_simd_second, code = E0511)]
889    SimdSecond {
890        #[primary_span]
891        span: Span,
892        name: Symbol,
893        ty: Ty<'tcx>,
894    },
895
896    #[diag(codegen_ssa_invalid_monomorphization_simd_third, code = E0511)]
897    SimdThird {
898        #[primary_span]
899        span: Span,
900        name: Symbol,
901        ty: Ty<'tcx>,
902    },
903
904    #[diag(codegen_ssa_invalid_monomorphization_simd_return, code = E0511)]
905    SimdReturn {
906        #[primary_span]
907        span: Span,
908        name: Symbol,
909        ty: Ty<'tcx>,
910    },
911
912    #[diag(codegen_ssa_invalid_monomorphization_invalid_bitmask, code = E0511)]
913    InvalidBitmask {
914        #[primary_span]
915        span: Span,
916        name: Symbol,
917        mask_ty: Ty<'tcx>,
918        expected_int_bits: u64,
919        expected_bytes: u64,
920    },
921
922    #[diag(codegen_ssa_invalid_monomorphization_return_length_input_type, code = E0511)]
923    ReturnLengthInputType {
924        #[primary_span]
925        span: Span,
926        name: Symbol,
927        in_len: u64,
928        in_ty: Ty<'tcx>,
929        ret_ty: Ty<'tcx>,
930        out_len: u64,
931    },
932
933    #[diag(codegen_ssa_invalid_monomorphization_second_argument_length, code = E0511)]
934    SecondArgumentLength {
935        #[primary_span]
936        span: Span,
937        name: Symbol,
938        in_len: u64,
939        in_ty: Ty<'tcx>,
940        arg_ty: Ty<'tcx>,
941        out_len: u64,
942    },
943
944    #[diag(codegen_ssa_invalid_monomorphization_third_argument_length, code = E0511)]
945    ThirdArgumentLength {
946        #[primary_span]
947        span: Span,
948        name: Symbol,
949        in_len: u64,
950        in_ty: Ty<'tcx>,
951        arg_ty: Ty<'tcx>,
952        out_len: u64,
953    },
954
955    #[diag(codegen_ssa_invalid_monomorphization_return_integer_type, code = E0511)]
956    ReturnIntegerType {
957        #[primary_span]
958        span: Span,
959        name: Symbol,
960        ret_ty: Ty<'tcx>,
961        out_ty: Ty<'tcx>,
962    },
963
964    #[diag(codegen_ssa_invalid_monomorphization_simd_shuffle, code = E0511)]
965    SimdShuffle {
966        #[primary_span]
967        span: Span,
968        name: Symbol,
969        ty: Ty<'tcx>,
970    },
971
972    #[diag(codegen_ssa_invalid_monomorphization_return_length, code = E0511)]
973    ReturnLength {
974        #[primary_span]
975        span: Span,
976        name: Symbol,
977        in_len: u64,
978        ret_ty: Ty<'tcx>,
979        out_len: u64,
980    },
981
982    #[diag(codegen_ssa_invalid_monomorphization_return_element, code = E0511)]
983    ReturnElement {
984        #[primary_span]
985        span: Span,
986        name: Symbol,
987        in_elem: Ty<'tcx>,
988        in_ty: Ty<'tcx>,
989        ret_ty: Ty<'tcx>,
990        out_ty: Ty<'tcx>,
991    },
992
993    #[diag(codegen_ssa_invalid_monomorphization_simd_index_out_of_bounds, code = E0511)]
994    SimdIndexOutOfBounds {
995        #[primary_span]
996        span: Span,
997        name: Symbol,
998        arg_idx: u64,
999        total_len: u128,
1000    },
1001
1002    #[diag(codegen_ssa_invalid_monomorphization_inserted_type, code = E0511)]
1003    InsertedType {
1004        #[primary_span]
1005        span: Span,
1006        name: Symbol,
1007        in_elem: Ty<'tcx>,
1008        in_ty: Ty<'tcx>,
1009        out_ty: Ty<'tcx>,
1010    },
1011
1012    #[diag(codegen_ssa_invalid_monomorphization_return_type, code = E0511)]
1013    ReturnType {
1014        #[primary_span]
1015        span: Span,
1016        name: Symbol,
1017        in_elem: Ty<'tcx>,
1018        in_ty: Ty<'tcx>,
1019        ret_ty: Ty<'tcx>,
1020    },
1021
1022    #[diag(codegen_ssa_invalid_monomorphization_expected_return_type, code = E0511)]
1023    ExpectedReturnType {
1024        #[primary_span]
1025        span: Span,
1026        name: Symbol,
1027        in_ty: Ty<'tcx>,
1028        ret_ty: Ty<'tcx>,
1029    },
1030
1031    #[diag(codegen_ssa_invalid_monomorphization_mismatched_lengths, code = E0511)]
1032    MismatchedLengths {
1033        #[primary_span]
1034        span: Span,
1035        name: Symbol,
1036        m_len: u64,
1037        v_len: u64,
1038    },
1039
1040    #[diag(codegen_ssa_invalid_monomorphization_mask_type, code = E0511)]
1041    #[note]
1042    MaskType {
1043        #[primary_span]
1044        span: Span,
1045        name: Symbol,
1046        ty: Ty<'tcx>,
1047    },
1048
1049    #[diag(codegen_ssa_invalid_monomorphization_vector_argument, code = E0511)]
1050    VectorArgument {
1051        #[primary_span]
1052        span: Span,
1053        name: Symbol,
1054        in_ty: Ty<'tcx>,
1055        in_elem: Ty<'tcx>,
1056    },
1057
1058    #[diag(codegen_ssa_invalid_monomorphization_cannot_return, code = E0511)]
1059    CannotReturn {
1060        #[primary_span]
1061        span: Span,
1062        name: Symbol,
1063        ret_ty: Ty<'tcx>,
1064        expected_int_bits: u64,
1065        expected_bytes: u64,
1066    },
1067
1068    #[diag(codegen_ssa_invalid_monomorphization_expected_element_type, code = E0511)]
1069    ExpectedElementType {
1070        #[primary_span]
1071        span: Span,
1072        name: Symbol,
1073        expected_element: Ty<'tcx>,
1074        second_arg: Ty<'tcx>,
1075        in_elem: Ty<'tcx>,
1076        in_ty: Ty<'tcx>,
1077        mutability: ExpectedPointerMutability,
1078    },
1079
1080    #[diag(codegen_ssa_invalid_monomorphization_third_arg_element_type, code = E0511)]
1081    ThirdArgElementType {
1082        #[primary_span]
1083        span: Span,
1084        name: Symbol,
1085        expected_element: Ty<'tcx>,
1086        third_arg: Ty<'tcx>,
1087    },
1088
1089    #[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol_of_size, code = E0511)]
1090    UnsupportedSymbolOfSize {
1091        #[primary_span]
1092        span: Span,
1093        name: Symbol,
1094        symbol: Symbol,
1095        in_ty: Ty<'tcx>,
1096        in_elem: Ty<'tcx>,
1097        size: u64,
1098        ret_ty: Ty<'tcx>,
1099    },
1100
1101    #[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol, code = E0511)]
1102    UnsupportedSymbol {
1103        #[primary_span]
1104        span: Span,
1105        name: Symbol,
1106        symbol: Symbol,
1107        in_ty: Ty<'tcx>,
1108        in_elem: Ty<'tcx>,
1109        ret_ty: Ty<'tcx>,
1110    },
1111
1112    #[diag(codegen_ssa_invalid_monomorphization_cast_wide_pointer, code = E0511)]
1113    CastWidePointer {
1114        #[primary_span]
1115        span: Span,
1116        name: Symbol,
1117        ty: Ty<'tcx>,
1118    },
1119
1120    #[diag(codegen_ssa_invalid_monomorphization_expected_pointer, code = E0511)]
1121    ExpectedPointer {
1122        #[primary_span]
1123        span: Span,
1124        name: Symbol,
1125        ty: Ty<'tcx>,
1126    },
1127
1128    #[diag(codegen_ssa_invalid_monomorphization_expected_usize, code = E0511)]
1129    ExpectedUsize {
1130        #[primary_span]
1131        span: Span,
1132        name: Symbol,
1133        ty: Ty<'tcx>,
1134    },
1135
1136    #[diag(codegen_ssa_invalid_monomorphization_unsupported_cast, code = E0511)]
1137    UnsupportedCast {
1138        #[primary_span]
1139        span: Span,
1140        name: Symbol,
1141        in_ty: Ty<'tcx>,
1142        in_elem: Ty<'tcx>,
1143        ret_ty: Ty<'tcx>,
1144        out_elem: Ty<'tcx>,
1145    },
1146
1147    #[diag(codegen_ssa_invalid_monomorphization_unsupported_operation, code = E0511)]
1148    UnsupportedOperation {
1149        #[primary_span]
1150        span: Span,
1151        name: Symbol,
1152        in_ty: Ty<'tcx>,
1153        in_elem: Ty<'tcx>,
1154    },
1155
1156    #[diag(codegen_ssa_invalid_monomorphization_expected_vector_element_type, code = E0511)]
1157    ExpectedVectorElementType {
1158        #[primary_span]
1159        span: Span,
1160        name: Symbol,
1161        expected_element: Ty<'tcx>,
1162        vector_type: Ty<'tcx>,
1163    },
1164}
1165
1166pub enum ExpectedPointerMutability {
1167    Mut,
1168    Not,
1169}
1170
1171impl IntoDiagArg for ExpectedPointerMutability {
1172    fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
1173        match self {
1174            ExpectedPointerMutability::Mut => DiagArgValue::Str(Cow::Borrowed("*mut")),
1175            ExpectedPointerMutability::Not => DiagArgValue::Str(Cow::Borrowed("*_")),
1176        }
1177    }
1178}
1179
1180#[derive(Diagnostic)]
1181#[diag(codegen_ssa_invalid_no_sanitize)]
1182#[note]
1183pub(crate) struct InvalidNoSanitize {
1184    #[primary_span]
1185    pub span: Span,
1186}
1187
1188#[derive(Diagnostic)]
1189#[diag(codegen_ssa_invalid_link_ordinal_nargs)]
1190#[note]
1191pub(crate) struct InvalidLinkOrdinalNargs {
1192    #[primary_span]
1193    pub span: Span,
1194}
1195
1196#[derive(Diagnostic)]
1197#[diag(codegen_ssa_illegal_link_ordinal_format)]
1198#[note]
1199pub(crate) struct InvalidLinkOrdinalFormat {
1200    #[primary_span]
1201    pub span: Span,
1202}
1203
1204#[derive(Diagnostic)]
1205#[diag(codegen_ssa_target_feature_safe_trait)]
1206pub(crate) struct TargetFeatureSafeTrait {
1207    #[primary_span]
1208    #[label]
1209    pub span: Span,
1210    #[label(codegen_ssa_label_def)]
1211    pub def: Span,
1212}
1213
1214#[derive(Diagnostic)]
1215#[diag(codegen_ssa_forbidden_target_feature_attr)]
1216pub struct ForbiddenTargetFeatureAttr<'a> {
1217    #[primary_span]
1218    pub span: Span,
1219    pub feature: &'a str,
1220    pub reason: &'a str,
1221}
1222
1223#[derive(Diagnostic)]
1224#[diag(codegen_ssa_failed_to_get_layout)]
1225pub struct FailedToGetLayout<'tcx> {
1226    #[primary_span]
1227    pub span: Span,
1228    pub ty: Ty<'tcx>,
1229    pub err: LayoutError<'tcx>,
1230}
1231
1232#[derive(Diagnostic)]
1233#[diag(codegen_ssa_dlltool_fail_import_library)]
1234pub(crate) struct DlltoolFailImportLibrary<'a> {
1235    pub dlltool_path: Cow<'a, str>,
1236    pub dlltool_args: String,
1237    pub stdout: Cow<'a, str>,
1238    pub stderr: Cow<'a, str>,
1239}
1240
1241#[derive(Diagnostic)]
1242#[diag(codegen_ssa_error_writing_def_file)]
1243pub(crate) struct ErrorWritingDEFFile {
1244    pub error: std::io::Error,
1245}
1246
1247#[derive(Diagnostic)]
1248#[diag(codegen_ssa_error_calling_dlltool)]
1249pub(crate) struct ErrorCallingDllTool<'a> {
1250    pub dlltool_path: Cow<'a, str>,
1251    pub error: std::io::Error,
1252}
1253
1254#[derive(Diagnostic)]
1255#[diag(codegen_ssa_error_creating_remark_dir)]
1256pub(crate) struct ErrorCreatingRemarkDir {
1257    pub error: std::io::Error,
1258}
1259
1260#[derive(Diagnostic)]
1261#[diag(codegen_ssa_compiler_builtins_cannot_call)]
1262pub struct CompilerBuiltinsCannotCall {
1263    pub caller: String,
1264    pub callee: String,
1265    #[primary_span]
1266    pub span: Span,
1267}
1268
1269#[derive(Diagnostic)]
1270#[diag(codegen_ssa_error_creating_import_library)]
1271pub(crate) struct ErrorCreatingImportLibrary<'a> {
1272    pub lib_name: &'a str,
1273    pub error: String,
1274}
1275
1276pub struct TargetFeatureDisableOrEnable<'a> {
1277    pub features: &'a [&'a str],
1278    pub span: Option<Span>,
1279    pub missing_features: Option<MissingFeatures>,
1280}
1281
1282#[derive(Subdiagnostic)]
1283#[help(codegen_ssa_missing_features)]
1284pub struct MissingFeatures;
1285
1286impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> {
1287    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1288        let mut diag = Diag::new(dcx, level, fluent::codegen_ssa_target_feature_disable_or_enable);
1289        if let Some(span) = self.span {
1290            diag.span(span);
1291        };
1292        if let Some(missing_features) = self.missing_features {
1293            diag.subdiagnostic(missing_features);
1294        }
1295        diag.arg("features", self.features.join(", "));
1296        diag
1297    }
1298}
1299
1300#[derive(Diagnostic)]
1301#[diag(codegen_ssa_aix_strip_not_used)]
1302pub(crate) struct AixStripNotUsed;
1303
1304#[derive(LintDiagnostic)]
1305#[diag(codegen_ssa_mixed_export_name_and_no_mangle)]
1306pub(crate) struct MixedExportNameAndNoMangle {
1307    #[label]
1308    pub no_mangle: Span,
1309    pub no_mangle_attr: String,
1310    #[note]
1311    pub export_name: Span,
1312    #[suggestion(style = "verbose", code = "", applicability = "machine-applicable")]
1313    pub removal_span: Span,
1314}
1315
1316#[derive(Diagnostic, Debug)]
1317pub(crate) enum XcrunError {
1318    #[diag(codegen_ssa_xcrun_failed_invoking)]
1319    FailedInvoking { sdk_name: &'static str, command_formatted: String, error: std::io::Error },
1320
1321    #[diag(codegen_ssa_xcrun_unsuccessful)]
1322    #[note]
1323    Unsuccessful {
1324        sdk_name: &'static str,
1325        command_formatted: String,
1326        stdout: String,
1327        stderr: String,
1328    },
1329}
1330
1331#[derive(Diagnostic, Debug)]
1332#[diag(codegen_ssa_xcrun_sdk_path_warning)]
1333#[note]
1334pub(crate) struct XcrunSdkPathWarning {
1335    pub sdk_name: &'static str,
1336    pub stderr: String,
1337}