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_stem().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]+").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 needs_braces = rlibs.len() >= 2;
499 if needs_braces {
500 arg.push("{");
501 }
502 let mut first = true;
503 for mut rlib in rlibs {
504 if !first {
505 arg.push(",");
506 }
507 first = false;
508 if is_sysroot_dir {
509 rlib = unsafe {
511 OsString::from_encoded_bytes_unchecked(
512 crate_hash
513 .replace(rlib.as_encoded_bytes(), b"-*")
514 .into_owned(),
515 )
516 };
517 }
518 arg.push(rlib);
519 }
520 if needs_braces {
521 arg.push("}");
522 }
523 arg.push(".rlib");
524 arg
525 }
526 }
527 }));
528
529 diag.note(format!("{:?}", self.command).trim_start_matches("env -i").to_owned());
530 diag.note("some arguments are omitted. use `--verbose` to show all linker arguments");
531 }
532
533 diag.note(self.escaped_output);
534
535 if contains_undefined_ref {
538 diag.note(fluent::codegen_ssa_extern_funcs_not_found)
539 .note(fluent::codegen_ssa_specify_libraries_to_link);
540
541 if rustc_session::utils::was_invoked_from_cargo() {
542 diag.note(fluent::codegen_ssa_use_cargo_directive);
543 }
544 }
545 diag
546 }
547}
548
549#[derive(Diagnostic)]
550#[diag(codegen_ssa_link_exe_unexpected_error)]
551pub(crate) struct LinkExeUnexpectedError;
552
553#[derive(Diagnostic)]
554#[diag(codegen_ssa_repair_vs_build_tools)]
555pub(crate) struct RepairVSBuildTools;
556
557#[derive(Diagnostic)]
558#[diag(codegen_ssa_missing_cpp_build_tool_component)]
559pub(crate) struct MissingCppBuildToolComponent;
560
561#[derive(Diagnostic)]
562#[diag(codegen_ssa_select_cpp_build_tool_workload)]
563pub(crate) struct SelectCppBuildToolWorkload;
564
565#[derive(Diagnostic)]
566#[diag(codegen_ssa_visual_studio_not_installed)]
567pub(crate) struct VisualStudioNotInstalled;
568
569#[derive(Diagnostic)]
570#[diag(codegen_ssa_linker_not_found)]
571#[note]
572pub(crate) struct LinkerNotFound {
573 pub linker_path: PathBuf,
574 pub error: Error,
575}
576
577#[derive(Diagnostic)]
578#[diag(codegen_ssa_unable_to_exe_linker)]
579#[note]
580#[note(codegen_ssa_command_note)]
581pub(crate) struct UnableToExeLinker {
582 pub linker_path: PathBuf,
583 pub error: Error,
584 pub command_formatted: String,
585}
586
587#[derive(Diagnostic)]
588#[diag(codegen_ssa_msvc_missing_linker)]
589pub(crate) struct MsvcMissingLinker;
590
591#[derive(Diagnostic)]
592#[diag(codegen_ssa_self_contained_linker_missing)]
593pub(crate) struct SelfContainedLinkerMissing;
594
595#[derive(Diagnostic)]
596#[diag(codegen_ssa_check_installed_visual_studio)]
597pub(crate) struct CheckInstalledVisualStudio;
598
599#[derive(Diagnostic)]
600#[diag(codegen_ssa_insufficient_vs_code_product)]
601pub(crate) struct InsufficientVSCodeProduct;
602
603#[derive(Diagnostic)]
604#[diag(codegen_ssa_cpu_required)]
605pub(crate) struct CpuRequired;
606
607#[derive(Diagnostic)]
608#[diag(codegen_ssa_processing_dymutil_failed)]
609#[note]
610pub(crate) struct ProcessingDymutilFailed {
611 pub status: ExitStatus,
612 pub output: String,
613}
614
615#[derive(Diagnostic)]
616#[diag(codegen_ssa_unable_to_run_dsymutil)]
617pub(crate) struct UnableToRunDsymutil {
618 pub error: Error,
619}
620
621#[derive(Diagnostic)]
622#[diag(codegen_ssa_stripping_debug_info_failed)]
623#[note]
624pub(crate) struct StrippingDebugInfoFailed<'a> {
625 pub util: &'a str,
626 pub status: ExitStatus,
627 pub output: String,
628}
629
630#[derive(Diagnostic)]
631#[diag(codegen_ssa_unable_to_run)]
632pub(crate) struct UnableToRun<'a> {
633 pub util: &'a str,
634 pub error: Error,
635}
636
637#[derive(Diagnostic)]
638#[diag(codegen_ssa_linker_file_stem)]
639pub(crate) struct LinkerFileStem;
640
641#[derive(Diagnostic)]
642#[diag(codegen_ssa_static_library_native_artifacts)]
643pub(crate) struct StaticLibraryNativeArtifacts;
644
645#[derive(Diagnostic)]
646#[diag(codegen_ssa_static_library_native_artifacts_to_file)]
647pub(crate) struct StaticLibraryNativeArtifactsToFile<'a> {
648 pub path: &'a Path,
649}
650
651#[derive(Diagnostic)]
652#[diag(codegen_ssa_link_script_unavailable)]
653pub(crate) struct LinkScriptUnavailable;
654
655#[derive(Diagnostic)]
656#[diag(codegen_ssa_link_script_write_failure)]
657pub(crate) struct LinkScriptWriteFailure {
658 pub path: PathBuf,
659 pub error: Error,
660}
661
662#[derive(Diagnostic)]
663#[diag(codegen_ssa_failed_to_write)]
664pub(crate) struct FailedToWrite {
665 pub path: PathBuf,
666 pub error: Error,
667}
668
669#[derive(Diagnostic)]
670#[diag(codegen_ssa_unable_to_write_debugger_visualizer)]
671pub(crate) struct UnableToWriteDebuggerVisualizer {
672 pub path: PathBuf,
673 pub error: Error,
674}
675
676#[derive(Diagnostic)]
677#[diag(codegen_ssa_rlib_archive_build_failure)]
678pub(crate) struct RlibArchiveBuildFailure {
679 pub path: PathBuf,
680 pub error: Error,
681}
682
683#[derive(Diagnostic)]
684pub enum ExtractBundledLibsError<'a> {
686 #[diag(codegen_ssa_extract_bundled_libs_open_file)]
687 OpenFile { rlib: &'a Path, error: Box<dyn std::error::Error> },
688
689 #[diag(codegen_ssa_extract_bundled_libs_mmap_file)]
690 MmapFile { rlib: &'a Path, error: Box<dyn std::error::Error> },
691
692 #[diag(codegen_ssa_extract_bundled_libs_parse_archive)]
693 ParseArchive { rlib: &'a Path, error: Box<dyn std::error::Error> },
694
695 #[diag(codegen_ssa_extract_bundled_libs_read_entry)]
696 ReadEntry { rlib: &'a Path, error: Box<dyn std::error::Error> },
697
698 #[diag(codegen_ssa_extract_bundled_libs_archive_member)]
699 ArchiveMember { rlib: &'a Path, error: Box<dyn std::error::Error> },
700
701 #[diag(codegen_ssa_extract_bundled_libs_convert_name)]
702 ConvertName { rlib: &'a Path, error: Box<dyn std::error::Error> },
703
704 #[diag(codegen_ssa_extract_bundled_libs_write_file)]
705 WriteFile { rlib: &'a Path, error: Box<dyn std::error::Error> },
706
707 #[diag(codegen_ssa_extract_bundled_libs_write_file)]
708 ExtractSection { rlib: &'a Path, error: Box<dyn std::error::Error> },
709}
710
711#[derive(Diagnostic)]
712#[diag(codegen_ssa_read_file)]
713pub(crate) struct ReadFileError {
714 pub message: std::io::Error,
715}
716
717#[derive(Diagnostic)]
718#[diag(codegen_ssa_unsupported_link_self_contained)]
719pub(crate) struct UnsupportedLinkSelfContained;
720
721#[derive(Diagnostic)]
722#[diag(codegen_ssa_archive_build_failure)]
723pub struct ArchiveBuildFailure {
725 pub path: PathBuf,
726 pub error: std::io::Error,
727}
728
729#[derive(Diagnostic)]
730#[diag(codegen_ssa_unknown_archive_kind)]
731pub struct UnknownArchiveKind<'a> {
733 pub kind: &'a str,
734}
735
736#[derive(Diagnostic)]
737#[diag(codegen_ssa_multiple_main_functions)]
738#[help]
739pub(crate) struct MultipleMainFunctions {
740 #[primary_span]
741 pub span: Span,
742}
743
744#[derive(Diagnostic)]
745#[diag(codegen_ssa_invalid_windows_subsystem)]
746pub(crate) struct InvalidWindowsSubsystem {
747 pub subsystem: Symbol,
748}
749
750#[derive(Diagnostic)]
751#[diag(codegen_ssa_shuffle_indices_evaluation)]
752pub(crate) struct ShuffleIndicesEvaluation {
753 #[primary_span]
754 pub span: Span,
755}
756
757#[derive(Diagnostic)]
758pub enum InvalidMonomorphization<'tcx> {
759 #[diag(codegen_ssa_invalid_monomorphization_basic_integer_type, code = E0511)]
760 BasicIntegerType {
761 #[primary_span]
762 span: Span,
763 name: Symbol,
764 ty: Ty<'tcx>,
765 },
766
767 #[diag(codegen_ssa_invalid_monomorphization_basic_float_type, code = E0511)]
768 BasicFloatType {
769 #[primary_span]
770 span: Span,
771 name: Symbol,
772 ty: Ty<'tcx>,
773 },
774
775 #[diag(codegen_ssa_invalid_monomorphization_float_to_int_unchecked, code = E0511)]
776 FloatToIntUnchecked {
777 #[primary_span]
778 span: Span,
779 ty: Ty<'tcx>,
780 },
781
782 #[diag(codegen_ssa_invalid_monomorphization_floating_point_vector, code = E0511)]
783 FloatingPointVector {
784 #[primary_span]
785 span: Span,
786 name: Symbol,
787 f_ty: FloatTy,
788 in_ty: Ty<'tcx>,
789 },
790
791 #[diag(codegen_ssa_invalid_monomorphization_floating_point_type, code = E0511)]
792 FloatingPointType {
793 #[primary_span]
794 span: Span,
795 name: Symbol,
796 in_ty: Ty<'tcx>,
797 },
798
799 #[diag(codegen_ssa_invalid_monomorphization_unrecognized_intrinsic, code = E0511)]
800 UnrecognizedIntrinsic {
801 #[primary_span]
802 span: Span,
803 name: Symbol,
804 },
805
806 #[diag(codegen_ssa_invalid_monomorphization_simd_argument, code = E0511)]
807 SimdArgument {
808 #[primary_span]
809 span: Span,
810 name: Symbol,
811 ty: Ty<'tcx>,
812 },
813
814 #[diag(codegen_ssa_invalid_monomorphization_simd_input, code = E0511)]
815 SimdInput {
816 #[primary_span]
817 span: Span,
818 name: Symbol,
819 ty: Ty<'tcx>,
820 },
821
822 #[diag(codegen_ssa_invalid_monomorphization_simd_first, code = E0511)]
823 SimdFirst {
824 #[primary_span]
825 span: Span,
826 name: Symbol,
827 ty: Ty<'tcx>,
828 },
829
830 #[diag(codegen_ssa_invalid_monomorphization_simd_second, code = E0511)]
831 SimdSecond {
832 #[primary_span]
833 span: Span,
834 name: Symbol,
835 ty: Ty<'tcx>,
836 },
837
838 #[diag(codegen_ssa_invalid_monomorphization_simd_third, code = E0511)]
839 SimdThird {
840 #[primary_span]
841 span: Span,
842 name: Symbol,
843 ty: Ty<'tcx>,
844 },
845
846 #[diag(codegen_ssa_invalid_monomorphization_simd_return, code = E0511)]
847 SimdReturn {
848 #[primary_span]
849 span: Span,
850 name: Symbol,
851 ty: Ty<'tcx>,
852 },
853
854 #[diag(codegen_ssa_invalid_monomorphization_invalid_bitmask, code = E0511)]
855 InvalidBitmask {
856 #[primary_span]
857 span: Span,
858 name: Symbol,
859 mask_ty: Ty<'tcx>,
860 expected_int_bits: u64,
861 expected_bytes: u64,
862 },
863
864 #[diag(codegen_ssa_invalid_monomorphization_return_length_input_type, code = E0511)]
865 ReturnLengthInputType {
866 #[primary_span]
867 span: Span,
868 name: Symbol,
869 in_len: u64,
870 in_ty: Ty<'tcx>,
871 ret_ty: Ty<'tcx>,
872 out_len: u64,
873 },
874
875 #[diag(codegen_ssa_invalid_monomorphization_second_argument_length, code = E0511)]
876 SecondArgumentLength {
877 #[primary_span]
878 span: Span,
879 name: Symbol,
880 in_len: u64,
881 in_ty: Ty<'tcx>,
882 arg_ty: Ty<'tcx>,
883 out_len: u64,
884 },
885
886 #[diag(codegen_ssa_invalid_monomorphization_third_argument_length, code = E0511)]
887 ThirdArgumentLength {
888 #[primary_span]
889 span: Span,
890 name: Symbol,
891 in_len: u64,
892 in_ty: Ty<'tcx>,
893 arg_ty: Ty<'tcx>,
894 out_len: u64,
895 },
896
897 #[diag(codegen_ssa_invalid_monomorphization_return_integer_type, code = E0511)]
898 ReturnIntegerType {
899 #[primary_span]
900 span: Span,
901 name: Symbol,
902 ret_ty: Ty<'tcx>,
903 out_ty: Ty<'tcx>,
904 },
905
906 #[diag(codegen_ssa_invalid_monomorphization_simd_shuffle, code = E0511)]
907 SimdShuffle {
908 #[primary_span]
909 span: Span,
910 name: Symbol,
911 ty: Ty<'tcx>,
912 },
913
914 #[diag(codegen_ssa_invalid_monomorphization_return_length, code = E0511)]
915 ReturnLength {
916 #[primary_span]
917 span: Span,
918 name: Symbol,
919 in_len: u64,
920 ret_ty: Ty<'tcx>,
921 out_len: u64,
922 },
923
924 #[diag(codegen_ssa_invalid_monomorphization_return_element, code = E0511)]
925 ReturnElement {
926 #[primary_span]
927 span: Span,
928 name: Symbol,
929 in_elem: Ty<'tcx>,
930 in_ty: Ty<'tcx>,
931 ret_ty: Ty<'tcx>,
932 out_ty: Ty<'tcx>,
933 },
934
935 #[diag(codegen_ssa_invalid_monomorphization_simd_index_out_of_bounds, code = E0511)]
936 SimdIndexOutOfBounds {
937 #[primary_span]
938 span: Span,
939 name: Symbol,
940 arg_idx: u64,
941 total_len: u128,
942 },
943
944 #[diag(codegen_ssa_invalid_monomorphization_inserted_type, code = E0511)]
945 InsertedType {
946 #[primary_span]
947 span: Span,
948 name: Symbol,
949 in_elem: Ty<'tcx>,
950 in_ty: Ty<'tcx>,
951 out_ty: Ty<'tcx>,
952 },
953
954 #[diag(codegen_ssa_invalid_monomorphization_return_type, code = E0511)]
955 ReturnType {
956 #[primary_span]
957 span: Span,
958 name: Symbol,
959 in_elem: Ty<'tcx>,
960 in_ty: Ty<'tcx>,
961 ret_ty: Ty<'tcx>,
962 },
963
964 #[diag(codegen_ssa_invalid_monomorphization_expected_return_type, code = E0511)]
965 ExpectedReturnType {
966 #[primary_span]
967 span: Span,
968 name: Symbol,
969 in_ty: Ty<'tcx>,
970 ret_ty: Ty<'tcx>,
971 },
972
973 #[diag(codegen_ssa_invalid_monomorphization_mismatched_lengths, code = E0511)]
974 MismatchedLengths {
975 #[primary_span]
976 span: Span,
977 name: Symbol,
978 m_len: u64,
979 v_len: u64,
980 },
981
982 #[diag(codegen_ssa_invalid_monomorphization_mask_wrong_element_type, code = E0511)]
983 MaskWrongElementType {
984 #[primary_span]
985 span: Span,
986 name: Symbol,
987 ty: Ty<'tcx>,
988 },
989
990 #[diag(codegen_ssa_invalid_monomorphization_cannot_return, code = E0511)]
991 CannotReturn {
992 #[primary_span]
993 span: Span,
994 name: Symbol,
995 ret_ty: Ty<'tcx>,
996 expected_int_bits: u64,
997 expected_bytes: u64,
998 },
999
1000 #[diag(codegen_ssa_invalid_monomorphization_expected_element_type, code = E0511)]
1001 ExpectedElementType {
1002 #[primary_span]
1003 span: Span,
1004 name: Symbol,
1005 expected_element: Ty<'tcx>,
1006 second_arg: Ty<'tcx>,
1007 in_elem: Ty<'tcx>,
1008 in_ty: Ty<'tcx>,
1009 mutability: ExpectedPointerMutability,
1010 },
1011
1012 #[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol_of_size, code = E0511)]
1013 UnsupportedSymbolOfSize {
1014 #[primary_span]
1015 span: Span,
1016 name: Symbol,
1017 symbol: Symbol,
1018 in_ty: Ty<'tcx>,
1019 in_elem: Ty<'tcx>,
1020 size: u64,
1021 ret_ty: Ty<'tcx>,
1022 },
1023
1024 #[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol, code = E0511)]
1025 UnsupportedSymbol {
1026 #[primary_span]
1027 span: Span,
1028 name: Symbol,
1029 symbol: Symbol,
1030 in_ty: Ty<'tcx>,
1031 in_elem: Ty<'tcx>,
1032 ret_ty: Ty<'tcx>,
1033 },
1034
1035 #[diag(codegen_ssa_invalid_monomorphization_cast_wide_pointer, code = E0511)]
1036 CastWidePointer {
1037 #[primary_span]
1038 span: Span,
1039 name: Symbol,
1040 ty: Ty<'tcx>,
1041 },
1042
1043 #[diag(codegen_ssa_invalid_monomorphization_expected_pointer, code = E0511)]
1044 ExpectedPointer {
1045 #[primary_span]
1046 span: Span,
1047 name: Symbol,
1048 ty: Ty<'tcx>,
1049 },
1050
1051 #[diag(codegen_ssa_invalid_monomorphization_expected_usize, code = E0511)]
1052 ExpectedUsize {
1053 #[primary_span]
1054 span: Span,
1055 name: Symbol,
1056 ty: Ty<'tcx>,
1057 },
1058
1059 #[diag(codegen_ssa_invalid_monomorphization_unsupported_cast, code = E0511)]
1060 UnsupportedCast {
1061 #[primary_span]
1062 span: Span,
1063 name: Symbol,
1064 in_ty: Ty<'tcx>,
1065 in_elem: Ty<'tcx>,
1066 ret_ty: Ty<'tcx>,
1067 out_elem: Ty<'tcx>,
1068 },
1069
1070 #[diag(codegen_ssa_invalid_monomorphization_unsupported_operation, code = E0511)]
1071 UnsupportedOperation {
1072 #[primary_span]
1073 span: Span,
1074 name: Symbol,
1075 in_ty: Ty<'tcx>,
1076 in_elem: Ty<'tcx>,
1077 },
1078
1079 #[diag(codegen_ssa_invalid_monomorphization_expected_vector_element_type, code = E0511)]
1080 ExpectedVectorElementType {
1081 #[primary_span]
1082 span: Span,
1083 name: Symbol,
1084 expected_element: Ty<'tcx>,
1085 vector_type: Ty<'tcx>,
1086 },
1087}
1088
1089pub enum ExpectedPointerMutability {
1090 Mut,
1091 Not,
1092}
1093
1094impl IntoDiagArg for ExpectedPointerMutability {
1095 fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
1096 match self {
1097 ExpectedPointerMutability::Mut => DiagArgValue::Str(Cow::Borrowed("*mut")),
1098 ExpectedPointerMutability::Not => DiagArgValue::Str(Cow::Borrowed("*_")),
1099 }
1100 }
1101}
1102
1103#[derive(Diagnostic)]
1104#[diag(codegen_ssa_invalid_no_sanitize)]
1105#[note]
1106pub(crate) struct InvalidNoSanitize {
1107 #[primary_span]
1108 pub span: Span,
1109}
1110
1111#[derive(Diagnostic)]
1112#[diag(codegen_ssa_invalid_link_ordinal_nargs)]
1113#[note]
1114pub(crate) struct InvalidLinkOrdinalNargs {
1115 #[primary_span]
1116 pub span: Span,
1117}
1118
1119#[derive(Diagnostic)]
1120#[diag(codegen_ssa_illegal_link_ordinal_format)]
1121#[note]
1122pub(crate) struct InvalidLinkOrdinalFormat {
1123 #[primary_span]
1124 pub span: Span,
1125}
1126
1127#[derive(Diagnostic)]
1128#[diag(codegen_ssa_target_feature_safe_trait)]
1129pub(crate) struct TargetFeatureSafeTrait {
1130 #[primary_span]
1131 #[label]
1132 pub span: Span,
1133 #[label(codegen_ssa_label_def)]
1134 pub def: Span,
1135}
1136
1137#[derive(Diagnostic)]
1138#[diag(codegen_ssa_forbidden_target_feature_attr)]
1139pub struct ForbiddenTargetFeatureAttr<'a> {
1140 #[primary_span]
1141 pub span: Span,
1142 pub feature: &'a str,
1143 pub reason: &'a str,
1144}
1145
1146#[derive(Diagnostic)]
1147#[diag(codegen_ssa_failed_to_get_layout)]
1148pub struct FailedToGetLayout<'tcx> {
1149 #[primary_span]
1150 pub span: Span,
1151 pub ty: Ty<'tcx>,
1152 pub err: LayoutError<'tcx>,
1153}
1154
1155#[derive(Diagnostic)]
1156#[diag(codegen_ssa_dlltool_fail_import_library)]
1157pub(crate) struct DlltoolFailImportLibrary<'a> {
1158 pub dlltool_path: Cow<'a, str>,
1159 pub dlltool_args: String,
1160 pub stdout: Cow<'a, str>,
1161 pub stderr: Cow<'a, str>,
1162}
1163
1164#[derive(Diagnostic)]
1165#[diag(codegen_ssa_error_writing_def_file)]
1166pub(crate) struct ErrorWritingDEFFile {
1167 pub error: std::io::Error,
1168}
1169
1170#[derive(Diagnostic)]
1171#[diag(codegen_ssa_error_calling_dlltool)]
1172pub(crate) struct ErrorCallingDllTool<'a> {
1173 pub dlltool_path: Cow<'a, str>,
1174 pub error: std::io::Error,
1175}
1176
1177#[derive(Diagnostic)]
1178#[diag(codegen_ssa_error_creating_remark_dir)]
1179pub(crate) struct ErrorCreatingRemarkDir {
1180 pub error: std::io::Error,
1181}
1182
1183#[derive(Diagnostic)]
1184#[diag(codegen_ssa_compiler_builtins_cannot_call)]
1185pub struct CompilerBuiltinsCannotCall {
1186 pub caller: String,
1187 pub callee: String,
1188 #[primary_span]
1189 pub span: Span,
1190}
1191
1192#[derive(Diagnostic)]
1193#[diag(codegen_ssa_error_creating_import_library)]
1194pub(crate) struct ErrorCreatingImportLibrary<'a> {
1195 pub lib_name: &'a str,
1196 pub error: String,
1197}
1198
1199#[derive(Diagnostic)]
1200#[diag(codegen_ssa_aix_strip_not_used)]
1201pub(crate) struct AixStripNotUsed;
1202
1203#[derive(Diagnostic, Debug)]
1204pub(crate) enum XcrunError {
1205 #[diag(codegen_ssa_xcrun_failed_invoking)]
1206 FailedInvoking { sdk_name: &'static str, command_formatted: String, error: std::io::Error },
1207
1208 #[diag(codegen_ssa_xcrun_unsuccessful)]
1209 #[note]
1210 Unsuccessful {
1211 sdk_name: &'static str,
1212 command_formatted: String,
1213 stdout: String,
1214 stderr: String,
1215 },
1216}
1217
1218#[derive(Diagnostic, Debug)]
1219#[diag(codegen_ssa_xcrun_sdk_path_warning)]
1220#[note]
1221pub(crate) struct XcrunSdkPathWarning {
1222 pub sdk_name: &'static str,
1223 pub stderr: String,
1224}
1225
1226#[derive(LintDiagnostic)]
1227#[diag(codegen_ssa_aarch64_softfloat_neon)]
1228pub(crate) struct Aarch64SoftfloatNeon;
1229
1230#[derive(Diagnostic)]
1231#[diag(codegen_ssa_unknown_ctarget_feature_prefix)]
1232#[note]
1233pub(crate) struct UnknownCTargetFeaturePrefix<'a> {
1234 pub feature: &'a str,
1235}
1236
1237#[derive(Subdiagnostic)]
1238pub(crate) enum PossibleFeature<'a> {
1239 #[help(codegen_ssa_possible_feature)]
1240 Some { rust_feature: &'a str },
1241 #[help(codegen_ssa_consider_filing_feature_request)]
1242 None,
1243}
1244
1245#[derive(Diagnostic)]
1246#[diag(codegen_ssa_unknown_ctarget_feature)]
1247#[note]
1248pub(crate) struct UnknownCTargetFeature<'a> {
1249 pub feature: &'a str,
1250 #[subdiagnostic]
1251 pub rust_feature: PossibleFeature<'a>,
1252}
1253
1254#[derive(Diagnostic)]
1255#[diag(codegen_ssa_unstable_ctarget_feature)]
1256#[note]
1257pub(crate) struct UnstableCTargetFeature<'a> {
1258 pub feature: &'a str,
1259}
1260
1261#[derive(Diagnostic)]
1262#[diag(codegen_ssa_forbidden_ctarget_feature)]
1263#[note]
1264#[note(codegen_ssa_forbidden_ctarget_feature_issue)]
1265pub(crate) struct ForbiddenCTargetFeature<'a> {
1266 pub feature: &'a str,
1267 pub enabled: &'a str,
1268 pub reason: &'a str,
1269}
1270
1271pub struct TargetFeatureDisableOrEnable<'a> {
1272 pub features: &'a [&'a str],
1273 pub span: Option<Span>,
1274 pub missing_features: Option<MissingFeatures>,
1275}
1276
1277#[derive(Subdiagnostic)]
1278#[help(codegen_ssa_missing_features)]
1279pub struct MissingFeatures;
1280
1281impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> {
1282 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1283 let mut diag = Diag::new(dcx, level, fluent::codegen_ssa_target_feature_disable_or_enable);
1284 if let Some(span) = self.span {
1285 diag.span(span);
1286 };
1287 if let Some(missing_features) = self.missing_features {
1288 diag.subdiagnostic(missing_features);
1289 }
1290 diag.arg("features", self.features.join(", "));
1291 diag
1292 }
1293}
1294
1295#[derive(Diagnostic)]
1296#[diag(codegen_ssa_no_mangle_nameless)]
1297pub(crate) struct NoMangleNameless {
1298 #[primary_span]
1299 pub span: Span,
1300 pub definition: String,
1301}
1302
1303#[derive(Diagnostic)]
1304#[diag(codegen_ssa_feature_not_valid)]
1305pub(crate) struct FeatureNotValid<'a> {
1306 pub feature: &'a str,
1307 #[primary_span]
1308 #[label]
1309 pub span: Span,
1310 #[help]
1311 pub plus_hint: bool,
1312}