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