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