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