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