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