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_null_on_export, code = E0648)]
145pub(crate) struct NullOnExport {
146 #[primary_span]
147 pub span: Span,
148}
149
150#[derive(Diagnostic)]
151#[diag(codegen_ssa_unsupported_instruction_set, code = E0779)]
152pub(crate) struct UnsupportedInstructionSet {
153 #[primary_span]
154 pub span: Span,
155}
156
157#[derive(Diagnostic)]
158#[diag(codegen_ssa_invalid_instruction_set, code = E0779)]
159pub(crate) struct InvalidInstructionSet {
160 #[primary_span]
161 pub span: Span,
162}
163
164#[derive(Diagnostic)]
165#[diag(codegen_ssa_bare_instruction_set, code = E0778)]
166pub(crate) struct BareInstructionSet {
167 #[primary_span]
168 pub span: Span,
169}
170
171#[derive(Diagnostic)]
172#[diag(codegen_ssa_multiple_instruction_set, code = E0779)]
173pub(crate) struct MultipleInstructionSet {
174 #[primary_span]
175 pub span: Span,
176}
177
178#[derive(Diagnostic)]
179#[diag(codegen_ssa_expected_name_value_pair)]
180pub(crate) struct ExpectedNameValuePair {
181 #[primary_span]
182 pub span: Span,
183}
184
185#[derive(Diagnostic)]
186#[diag(codegen_ssa_unexpected_parameter_name)]
187pub(crate) struct UnexpectedParameterName {
188 #[primary_span]
189 #[label]
190 pub span: Span,
191 pub prefix_nops: Symbol,
192 pub entry_nops: Symbol,
193}
194
195#[derive(Diagnostic)]
196#[diag(codegen_ssa_invalid_literal_value)]
197pub(crate) struct InvalidLiteralValue {
198 #[primary_span]
199 #[label]
200 pub span: Span,
201}
202
203#[derive(Diagnostic)]
204#[diag(codegen_ssa_out_of_range_integer)]
205pub(crate) struct OutOfRangeInteger {
206 #[primary_span]
207 #[label]
208 pub span: Span,
209}
210
211#[derive(Diagnostic)]
212#[diag(codegen_ssa_copy_path_buf)]
213pub(crate) struct CopyPathBuf {
214 pub source_file: PathBuf,
215 pub output_path: PathBuf,
216 pub error: Error,
217}
218
219#[derive(Diagnostic)]
221#[diag(codegen_ssa_copy_path)]
222pub struct CopyPath<'a> {
223 from: DebugArgPath<'a>,
224 to: DebugArgPath<'a>,
225 error: Error,
226}
227
228impl<'a> CopyPath<'a> {
229 pub fn new(from: &'a Path, to: &'a Path, error: Error) -> CopyPath<'a> {
230 CopyPath { from: DebugArgPath(from), to: DebugArgPath(to), error }
231 }
232}
233
234struct DebugArgPath<'a>(pub &'a Path);
235
236impl IntoDiagArg for DebugArgPath<'_> {
237 fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> rustc_errors::DiagArgValue {
238 DiagArgValue::Str(Cow::Owned(format!("{:?}", self.0)))
239 }
240}
241
242#[derive(Diagnostic)]
243#[diag(codegen_ssa_binary_output_to_tty)]
244pub struct BinaryOutputToTty {
245 pub shorthand: &'static str,
246}
247
248#[derive(Diagnostic)]
249#[diag(codegen_ssa_ignoring_emit_path)]
250pub struct IgnoringEmitPath {
251 pub extension: &'static str,
252}
253
254#[derive(Diagnostic)]
255#[diag(codegen_ssa_ignoring_output)]
256pub struct IgnoringOutput {
257 pub extension: &'static str,
258}
259
260#[derive(Diagnostic)]
261#[diag(codegen_ssa_create_temp_dir)]
262pub(crate) struct CreateTempDir {
263 pub error: Error,
264}
265
266#[derive(Diagnostic)]
267#[diag(codegen_ssa_add_native_library)]
268pub(crate) struct AddNativeLibrary {
269 pub library_path: PathBuf,
270 pub error: Error,
271}
272
273#[derive(Diagnostic)]
274#[diag(codegen_ssa_multiple_external_func_decl)]
275pub(crate) struct MultipleExternalFuncDecl<'a> {
276 #[primary_span]
277 pub span: Span,
278 pub function: Symbol,
279 pub library_name: &'a str,
280}
281
282#[derive(Diagnostic)]
283pub enum LinkRlibError {
284 #[diag(codegen_ssa_rlib_missing_format)]
285 MissingFormat,
286
287 #[diag(codegen_ssa_rlib_only_rmeta_found)]
288 OnlyRmetaFound { crate_name: Symbol },
289
290 #[diag(codegen_ssa_rlib_not_found)]
291 NotFound { crate_name: Symbol },
292
293 #[diag(codegen_ssa_rlib_incompatible_dependency_formats)]
294 IncompatibleDependencyFormats { ty1: String, ty2: String, list1: String, list2: String },
295}
296
297pub(crate) struct ThorinErrorWrapper(pub thorin::Error);
298
299impl<G: EmissionGuarantee> Diagnostic<'_, G> for ThorinErrorWrapper {
300 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
301 let build = |msg| Diag::new(dcx, level, msg);
302 match self.0 {
303 thorin::Error::ReadInput(_) => build(fluent::codegen_ssa_thorin_read_input_failure),
304 thorin::Error::ParseFileKind(_) => {
305 build(fluent::codegen_ssa_thorin_parse_input_file_kind)
306 }
307 thorin::Error::ParseObjectFile(_) => {
308 build(fluent::codegen_ssa_thorin_parse_input_object_file)
309 }
310 thorin::Error::ParseArchiveFile(_) => {
311 build(fluent::codegen_ssa_thorin_parse_input_archive_file)
312 }
313 thorin::Error::ParseArchiveMember(_) => {
314 build(fluent::codegen_ssa_thorin_parse_archive_member)
315 }
316 thorin::Error::InvalidInputKind => build(fluent::codegen_ssa_thorin_invalid_input_kind),
317 thorin::Error::DecompressData(_) => build(fluent::codegen_ssa_thorin_decompress_data),
318 thorin::Error::NamelessSection(_, offset) => {
319 build(fluent::codegen_ssa_thorin_section_without_name)
320 .with_arg("offset", format!("0x{offset:08x}"))
321 }
322 thorin::Error::RelocationWithInvalidSymbol(section, offset) => {
323 build(fluent::codegen_ssa_thorin_relocation_with_invalid_symbol)
324 .with_arg("section", section)
325 .with_arg("offset", format!("0x{offset:08x}"))
326 }
327 thorin::Error::MultipleRelocations(section, offset) => {
328 build(fluent::codegen_ssa_thorin_multiple_relocations)
329 .with_arg("section", section)
330 .with_arg("offset", format!("0x{offset:08x}"))
331 }
332 thorin::Error::UnsupportedRelocation(section, offset) => {
333 build(fluent::codegen_ssa_thorin_unsupported_relocation)
334 .with_arg("section", section)
335 .with_arg("offset", format!("0x{offset:08x}"))
336 }
337 thorin::Error::MissingDwoName(id) => build(fluent::codegen_ssa_thorin_missing_dwo_name)
338 .with_arg("id", format!("0x{id:08x}")),
339 thorin::Error::NoCompilationUnits => {
340 build(fluent::codegen_ssa_thorin_no_compilation_units)
341 }
342 thorin::Error::NoDie => build(fluent::codegen_ssa_thorin_no_die),
343 thorin::Error::TopLevelDieNotUnit => {
344 build(fluent::codegen_ssa_thorin_top_level_die_not_unit)
345 }
346 thorin::Error::MissingRequiredSection(section) => {
347 build(fluent::codegen_ssa_thorin_missing_required_section)
348 .with_arg("section", section)
349 }
350 thorin::Error::ParseUnitAbbreviations(_) => {
351 build(fluent::codegen_ssa_thorin_parse_unit_abbreviations)
352 }
353 thorin::Error::ParseUnitAttribute(_) => {
354 build(fluent::codegen_ssa_thorin_parse_unit_attribute)
355 }
356 thorin::Error::ParseUnitHeader(_) => {
357 build(fluent::codegen_ssa_thorin_parse_unit_header)
358 }
359 thorin::Error::ParseUnit(_) => build(fluent::codegen_ssa_thorin_parse_unit),
360 thorin::Error::IncompatibleIndexVersion(section, format, actual) => {
361 build(fluent::codegen_ssa_thorin_incompatible_index_version)
362 .with_arg("section", section)
363 .with_arg("actual", actual)
364 .with_arg("format", format)
365 }
366 thorin::Error::OffsetAtIndex(_, index) => {
367 build(fluent::codegen_ssa_thorin_offset_at_index).with_arg("index", index)
368 }
369 thorin::Error::StrAtOffset(_, offset) => {
370 build(fluent::codegen_ssa_thorin_str_at_offset)
371 .with_arg("offset", format!("0x{offset:08x}"))
372 }
373 thorin::Error::ParseIndex(_, section) => {
374 build(fluent::codegen_ssa_thorin_parse_index).with_arg("section", section)
375 }
376 thorin::Error::UnitNotInIndex(unit) => {
377 build(fluent::codegen_ssa_thorin_unit_not_in_index)
378 .with_arg("unit", format!("0x{unit:08x}"))
379 }
380 thorin::Error::RowNotInIndex(_, row) => {
381 build(fluent::codegen_ssa_thorin_row_not_in_index).with_arg("row", row)
382 }
383 thorin::Error::SectionNotInRow => build(fluent::codegen_ssa_thorin_section_not_in_row),
384 thorin::Error::EmptyUnit(unit) => build(fluent::codegen_ssa_thorin_empty_unit)
385 .with_arg("unit", format!("0x{unit:08x}")),
386 thorin::Error::MultipleDebugInfoSection => {
387 build(fluent::codegen_ssa_thorin_multiple_debug_info_section)
388 }
389 thorin::Error::MultipleDebugTypesSection => {
390 build(fluent::codegen_ssa_thorin_multiple_debug_types_section)
391 }
392 thorin::Error::NotSplitUnit => build(fluent::codegen_ssa_thorin_not_split_unit),
393 thorin::Error::DuplicateUnit(unit) => build(fluent::codegen_ssa_thorin_duplicate_unit)
394 .with_arg("unit", format!("0x{unit:08x}")),
395 thorin::Error::MissingReferencedUnit(unit) => {
396 build(fluent::codegen_ssa_thorin_missing_referenced_unit)
397 .with_arg("unit", format!("0x{unit:08x}"))
398 }
399 thorin::Error::NoOutputObjectCreated => {
400 build(fluent::codegen_ssa_thorin_not_output_object_created)
401 }
402 thorin::Error::MixedInputEncodings => {
403 build(fluent::codegen_ssa_thorin_mixed_input_encodings)
404 }
405 thorin::Error::Io(e) => {
406 build(fluent::codegen_ssa_thorin_io).with_arg("error", format!("{e}"))
407 }
408 thorin::Error::ObjectRead(e) => {
409 build(fluent::codegen_ssa_thorin_object_read).with_arg("error", format!("{e}"))
410 }
411 thorin::Error::ObjectWrite(e) => {
412 build(fluent::codegen_ssa_thorin_object_write).with_arg("error", format!("{e}"))
413 }
414 thorin::Error::GimliRead(e) => {
415 build(fluent::codegen_ssa_thorin_gimli_read).with_arg("error", format!("{e}"))
416 }
417 thorin::Error::GimliWrite(e) => {
418 build(fluent::codegen_ssa_thorin_gimli_write).with_arg("error", format!("{e}"))
419 }
420 _ => unimplemented!("Untranslated thorin error"),
421 }
422 }
423}
424
425pub(crate) struct LinkingFailed<'a> {
426 pub linker_path: &'a Path,
427 pub exit_status: ExitStatus,
428 pub command: Command,
429 pub escaped_output: String,
430 pub verbose: bool,
431 pub sysroot_dir: PathBuf,
432}
433
434impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
435 fn into_diag(mut self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
436 let mut diag = Diag::new(dcx, level, fluent::codegen_ssa_linking_failed);
437 diag.arg("linker_path", format!("{}", self.linker_path.display()));
438 diag.arg("exit_status", format!("{}", self.exit_status));
439
440 let contains_undefined_ref = self.escaped_output.contains("undefined reference to");
441
442 if self.verbose {
443 diag.note(format!("{:?}", self.command));
444 } else {
445 self.command.env_clear();
446
447 enum ArgGroup {
448 Regular(OsString),
449 Objects(usize),
450 Rlibs(PathBuf, Vec<OsString>),
451 }
452
453 let orig_args = self.command.take_args();
456 let mut args: Vec<ArgGroup> = vec![];
457 for arg in orig_args {
458 if arg.as_encoded_bytes().ends_with(b".rcgu.o") {
459 if let Some(ArgGroup::Objects(n)) = args.last_mut() {
460 *n += 1;
461 } else {
462 args.push(ArgGroup::Objects(1));
463 }
464 } else if arg.as_encoded_bytes().ends_with(b".rlib") {
465 let rlib_path = Path::new(&arg);
466 let dir = rlib_path.parent().unwrap();
467 let filename = rlib_path.file_name().unwrap().to_owned();
468 if let Some(ArgGroup::Rlibs(parent, rlibs)) = args.last_mut() {
469 if parent == dir {
470 rlibs.push(filename);
471 } else {
472 args.push(ArgGroup::Rlibs(dir.to_owned(), vec![filename]));
473 }
474 } else {
475 args.push(ArgGroup::Rlibs(dir.to_owned(), vec![filename]));
476 }
477 } else {
478 args.push(ArgGroup::Regular(arg));
479 }
480 }
481 let crate_hash = regex::bytes::Regex::new(r"-[0-9a-f]+\.rlib$").unwrap();
482 self.command.args(args.into_iter().map(|arg_group| {
483 match arg_group {
484 ArgGroup::Regular(arg) => unsafe {
486 use bstr::ByteSlice;
487 OsString::from_encoded_bytes_unchecked(
488 arg.as_encoded_bytes().replace(
489 self.sysroot_dir.as_os_str().as_encoded_bytes(),
490 b"<sysroot>",
491 ),
492 )
493 },
494 ArgGroup::Objects(n) => OsString::from(format!("<{n} object files omitted>")),
495 ArgGroup::Rlibs(mut dir, rlibs) => {
496 let is_sysroot_dir = match dir.strip_prefix(&self.sysroot_dir) {
497 Ok(short) => {
498 dir = Path::new("<sysroot>").join(short);
499 true
500 }
501 Err(_) => false,
502 };
503 let mut arg = dir.into_os_string();
504 arg.push("/{");
505 let mut first = true;
506 for mut rlib in rlibs {
507 if !first {
508 arg.push(",");
509 }
510 first = false;
511 if is_sysroot_dir {
512 rlib = unsafe {
514 OsString::from_encoded_bytes_unchecked(
515 crate_hash
516 .replace(rlib.as_encoded_bytes(), b"-*")
517 .into_owned(),
518 )
519 };
520 }
521 arg.push(rlib);
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_expected_used_symbol)]
738pub(crate) struct ExpectedUsedSymbol {
739 #[primary_span]
740 pub span: Span,
741}
742
743#[derive(Diagnostic)]
744#[diag(codegen_ssa_multiple_main_functions)]
745#[help]
746pub(crate) struct MultipleMainFunctions {
747 #[primary_span]
748 pub span: Span,
749}
750
751#[derive(Diagnostic)]
752#[diag(codegen_ssa_invalid_windows_subsystem)]
753pub(crate) struct InvalidWindowsSubsystem {
754 pub subsystem: Symbol,
755}
756
757#[derive(Diagnostic)]
758#[diag(codegen_ssa_shuffle_indices_evaluation)]
759pub(crate) struct ShuffleIndicesEvaluation {
760 #[primary_span]
761 pub span: Span,
762}
763
764#[derive(Diagnostic)]
765pub enum InvalidMonomorphization<'tcx> {
766 #[diag(codegen_ssa_invalid_monomorphization_basic_integer_type, code = E0511)]
767 BasicIntegerType {
768 #[primary_span]
769 span: Span,
770 name: Symbol,
771 ty: Ty<'tcx>,
772 },
773
774 #[diag(codegen_ssa_invalid_monomorphization_basic_float_type, code = E0511)]
775 BasicFloatType {
776 #[primary_span]
777 span: Span,
778 name: Symbol,
779 ty: Ty<'tcx>,
780 },
781
782 #[diag(codegen_ssa_invalid_monomorphization_float_to_int_unchecked, code = E0511)]
783 FloatToIntUnchecked {
784 #[primary_span]
785 span: Span,
786 ty: Ty<'tcx>,
787 },
788
789 #[diag(codegen_ssa_invalid_monomorphization_floating_point_vector, code = E0511)]
790 FloatingPointVector {
791 #[primary_span]
792 span: Span,
793 name: Symbol,
794 f_ty: FloatTy,
795 in_ty: Ty<'tcx>,
796 },
797
798 #[diag(codegen_ssa_invalid_monomorphization_floating_point_type, code = E0511)]
799 FloatingPointType {
800 #[primary_span]
801 span: Span,
802 name: Symbol,
803 in_ty: Ty<'tcx>,
804 },
805
806 #[diag(codegen_ssa_invalid_monomorphization_unrecognized_intrinsic, code = E0511)]
807 UnrecognizedIntrinsic {
808 #[primary_span]
809 span: Span,
810 name: Symbol,
811 },
812
813 #[diag(codegen_ssa_invalid_monomorphization_simd_argument, code = E0511)]
814 SimdArgument {
815 #[primary_span]
816 span: Span,
817 name: Symbol,
818 ty: Ty<'tcx>,
819 },
820
821 #[diag(codegen_ssa_invalid_monomorphization_simd_input, code = E0511)]
822 SimdInput {
823 #[primary_span]
824 span: Span,
825 name: Symbol,
826 ty: Ty<'tcx>,
827 },
828
829 #[diag(codegen_ssa_invalid_monomorphization_simd_first, code = E0511)]
830 SimdFirst {
831 #[primary_span]
832 span: Span,
833 name: Symbol,
834 ty: Ty<'tcx>,
835 },
836
837 #[diag(codegen_ssa_invalid_monomorphization_simd_second, code = E0511)]
838 SimdSecond {
839 #[primary_span]
840 span: Span,
841 name: Symbol,
842 ty: Ty<'tcx>,
843 },
844
845 #[diag(codegen_ssa_invalid_monomorphization_simd_third, code = E0511)]
846 SimdThird {
847 #[primary_span]
848 span: Span,
849 name: Symbol,
850 ty: Ty<'tcx>,
851 },
852
853 #[diag(codegen_ssa_invalid_monomorphization_simd_return, code = E0511)]
854 SimdReturn {
855 #[primary_span]
856 span: Span,
857 name: Symbol,
858 ty: Ty<'tcx>,
859 },
860
861 #[diag(codegen_ssa_invalid_monomorphization_invalid_bitmask, code = E0511)]
862 InvalidBitmask {
863 #[primary_span]
864 span: Span,
865 name: Symbol,
866 mask_ty: Ty<'tcx>,
867 expected_int_bits: u64,
868 expected_bytes: u64,
869 },
870
871 #[diag(codegen_ssa_invalid_monomorphization_return_length_input_type, code = E0511)]
872 ReturnLengthInputType {
873 #[primary_span]
874 span: Span,
875 name: Symbol,
876 in_len: u64,
877 in_ty: Ty<'tcx>,
878 ret_ty: Ty<'tcx>,
879 out_len: u64,
880 },
881
882 #[diag(codegen_ssa_invalid_monomorphization_second_argument_length, code = E0511)]
883 SecondArgumentLength {
884 #[primary_span]
885 span: Span,
886 name: Symbol,
887 in_len: u64,
888 in_ty: Ty<'tcx>,
889 arg_ty: Ty<'tcx>,
890 out_len: u64,
891 },
892
893 #[diag(codegen_ssa_invalid_monomorphization_third_argument_length, code = E0511)]
894 ThirdArgumentLength {
895 #[primary_span]
896 span: Span,
897 name: Symbol,
898 in_len: u64,
899 in_ty: Ty<'tcx>,
900 arg_ty: Ty<'tcx>,
901 out_len: u64,
902 },
903
904 #[diag(codegen_ssa_invalid_monomorphization_return_integer_type, code = E0511)]
905 ReturnIntegerType {
906 #[primary_span]
907 span: Span,
908 name: Symbol,
909 ret_ty: Ty<'tcx>,
910 out_ty: Ty<'tcx>,
911 },
912
913 #[diag(codegen_ssa_invalid_monomorphization_simd_shuffle, code = E0511)]
914 SimdShuffle {
915 #[primary_span]
916 span: Span,
917 name: Symbol,
918 ty: Ty<'tcx>,
919 },
920
921 #[diag(codegen_ssa_invalid_monomorphization_return_length, code = E0511)]
922 ReturnLength {
923 #[primary_span]
924 span: Span,
925 name: Symbol,
926 in_len: u64,
927 ret_ty: Ty<'tcx>,
928 out_len: u64,
929 },
930
931 #[diag(codegen_ssa_invalid_monomorphization_return_element, code = E0511)]
932 ReturnElement {
933 #[primary_span]
934 span: Span,
935 name: Symbol,
936 in_elem: Ty<'tcx>,
937 in_ty: Ty<'tcx>,
938 ret_ty: Ty<'tcx>,
939 out_ty: Ty<'tcx>,
940 },
941
942 #[diag(codegen_ssa_invalid_monomorphization_simd_index_out_of_bounds, code = E0511)]
943 SimdIndexOutOfBounds {
944 #[primary_span]
945 span: Span,
946 name: Symbol,
947 arg_idx: u64,
948 total_len: u128,
949 },
950
951 #[diag(codegen_ssa_invalid_monomorphization_inserted_type, code = E0511)]
952 InsertedType {
953 #[primary_span]
954 span: Span,
955 name: Symbol,
956 in_elem: Ty<'tcx>,
957 in_ty: Ty<'tcx>,
958 out_ty: Ty<'tcx>,
959 },
960
961 #[diag(codegen_ssa_invalid_monomorphization_return_type, code = E0511)]
962 ReturnType {
963 #[primary_span]
964 span: Span,
965 name: Symbol,
966 in_elem: Ty<'tcx>,
967 in_ty: Ty<'tcx>,
968 ret_ty: Ty<'tcx>,
969 },
970
971 #[diag(codegen_ssa_invalid_monomorphization_expected_return_type, code = E0511)]
972 ExpectedReturnType {
973 #[primary_span]
974 span: Span,
975 name: Symbol,
976 in_ty: Ty<'tcx>,
977 ret_ty: Ty<'tcx>,
978 },
979
980 #[diag(codegen_ssa_invalid_monomorphization_mismatched_lengths, code = E0511)]
981 MismatchedLengths {
982 #[primary_span]
983 span: Span,
984 name: Symbol,
985 m_len: u64,
986 v_len: u64,
987 },
988
989 #[diag(codegen_ssa_invalid_monomorphization_mask_wrong_element_type, code = E0511)]
990 MaskWrongElementType {
991 #[primary_span]
992 span: Span,
993 name: Symbol,
994 ty: Ty<'tcx>,
995 },
996
997 #[diag(codegen_ssa_invalid_monomorphization_cannot_return, code = E0511)]
998 CannotReturn {
999 #[primary_span]
1000 span: Span,
1001 name: Symbol,
1002 ret_ty: Ty<'tcx>,
1003 expected_int_bits: u64,
1004 expected_bytes: u64,
1005 },
1006
1007 #[diag(codegen_ssa_invalid_monomorphization_expected_element_type, code = E0511)]
1008 ExpectedElementType {
1009 #[primary_span]
1010 span: Span,
1011 name: Symbol,
1012 expected_element: Ty<'tcx>,
1013 second_arg: Ty<'tcx>,
1014 in_elem: Ty<'tcx>,
1015 in_ty: Ty<'tcx>,
1016 mutability: ExpectedPointerMutability,
1017 },
1018
1019 #[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol_of_size, code = E0511)]
1020 UnsupportedSymbolOfSize {
1021 #[primary_span]
1022 span: Span,
1023 name: Symbol,
1024 symbol: Symbol,
1025 in_ty: Ty<'tcx>,
1026 in_elem: Ty<'tcx>,
1027 size: u64,
1028 ret_ty: Ty<'tcx>,
1029 },
1030
1031 #[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol, code = E0511)]
1032 UnsupportedSymbol {
1033 #[primary_span]
1034 span: Span,
1035 name: Symbol,
1036 symbol: Symbol,
1037 in_ty: Ty<'tcx>,
1038 in_elem: Ty<'tcx>,
1039 ret_ty: Ty<'tcx>,
1040 },
1041
1042 #[diag(codegen_ssa_invalid_monomorphization_cast_wide_pointer, code = E0511)]
1043 CastWidePointer {
1044 #[primary_span]
1045 span: Span,
1046 name: Symbol,
1047 ty: Ty<'tcx>,
1048 },
1049
1050 #[diag(codegen_ssa_invalid_monomorphization_expected_pointer, code = E0511)]
1051 ExpectedPointer {
1052 #[primary_span]
1053 span: Span,
1054 name: Symbol,
1055 ty: Ty<'tcx>,
1056 },
1057
1058 #[diag(codegen_ssa_invalid_monomorphization_expected_usize, code = E0511)]
1059 ExpectedUsize {
1060 #[primary_span]
1061 span: Span,
1062 name: Symbol,
1063 ty: Ty<'tcx>,
1064 },
1065
1066 #[diag(codegen_ssa_invalid_monomorphization_unsupported_cast, code = E0511)]
1067 UnsupportedCast {
1068 #[primary_span]
1069 span: Span,
1070 name: Symbol,
1071 in_ty: Ty<'tcx>,
1072 in_elem: Ty<'tcx>,
1073 ret_ty: Ty<'tcx>,
1074 out_elem: Ty<'tcx>,
1075 },
1076
1077 #[diag(codegen_ssa_invalid_monomorphization_unsupported_operation, code = E0511)]
1078 UnsupportedOperation {
1079 #[primary_span]
1080 span: Span,
1081 name: Symbol,
1082 in_ty: Ty<'tcx>,
1083 in_elem: Ty<'tcx>,
1084 },
1085
1086 #[diag(codegen_ssa_invalid_monomorphization_expected_vector_element_type, code = E0511)]
1087 ExpectedVectorElementType {
1088 #[primary_span]
1089 span: Span,
1090 name: Symbol,
1091 expected_element: Ty<'tcx>,
1092 vector_type: Ty<'tcx>,
1093 },
1094}
1095
1096pub enum ExpectedPointerMutability {
1097 Mut,
1098 Not,
1099}
1100
1101impl IntoDiagArg for ExpectedPointerMutability {
1102 fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
1103 match self {
1104 ExpectedPointerMutability::Mut => DiagArgValue::Str(Cow::Borrowed("*mut")),
1105 ExpectedPointerMutability::Not => DiagArgValue::Str(Cow::Borrowed("*_")),
1106 }
1107 }
1108}
1109
1110#[derive(Diagnostic)]
1111#[diag(codegen_ssa_invalid_no_sanitize)]
1112#[note]
1113pub(crate) struct InvalidNoSanitize {
1114 #[primary_span]
1115 pub span: Span,
1116}
1117
1118#[derive(Diagnostic)]
1119#[diag(codegen_ssa_invalid_link_ordinal_nargs)]
1120#[note]
1121pub(crate) struct InvalidLinkOrdinalNargs {
1122 #[primary_span]
1123 pub span: Span,
1124}
1125
1126#[derive(Diagnostic)]
1127#[diag(codegen_ssa_illegal_link_ordinal_format)]
1128#[note]
1129pub(crate) struct InvalidLinkOrdinalFormat {
1130 #[primary_span]
1131 pub span: Span,
1132}
1133
1134#[derive(Diagnostic)]
1135#[diag(codegen_ssa_target_feature_safe_trait)]
1136pub(crate) struct TargetFeatureSafeTrait {
1137 #[primary_span]
1138 #[label]
1139 pub span: Span,
1140 #[label(codegen_ssa_label_def)]
1141 pub def: Span,
1142}
1143
1144#[derive(Diagnostic)]
1145#[diag(codegen_ssa_forbidden_target_feature_attr)]
1146pub struct ForbiddenTargetFeatureAttr<'a> {
1147 #[primary_span]
1148 pub span: Span,
1149 pub feature: &'a str,
1150 pub reason: &'a str,
1151}
1152
1153#[derive(Diagnostic)]
1154#[diag(codegen_ssa_failed_to_get_layout)]
1155pub struct FailedToGetLayout<'tcx> {
1156 #[primary_span]
1157 pub span: Span,
1158 pub ty: Ty<'tcx>,
1159 pub err: LayoutError<'tcx>,
1160}
1161
1162#[derive(Diagnostic)]
1163#[diag(codegen_ssa_dlltool_fail_import_library)]
1164pub(crate) struct DlltoolFailImportLibrary<'a> {
1165 pub dlltool_path: Cow<'a, str>,
1166 pub dlltool_args: String,
1167 pub stdout: Cow<'a, str>,
1168 pub stderr: Cow<'a, str>,
1169}
1170
1171#[derive(Diagnostic)]
1172#[diag(codegen_ssa_error_writing_def_file)]
1173pub(crate) struct ErrorWritingDEFFile {
1174 pub error: std::io::Error,
1175}
1176
1177#[derive(Diagnostic)]
1178#[diag(codegen_ssa_error_calling_dlltool)]
1179pub(crate) struct ErrorCallingDllTool<'a> {
1180 pub dlltool_path: Cow<'a, str>,
1181 pub error: std::io::Error,
1182}
1183
1184#[derive(Diagnostic)]
1185#[diag(codegen_ssa_error_creating_remark_dir)]
1186pub(crate) struct ErrorCreatingRemarkDir {
1187 pub error: std::io::Error,
1188}
1189
1190#[derive(Diagnostic)]
1191#[diag(codegen_ssa_compiler_builtins_cannot_call)]
1192pub struct CompilerBuiltinsCannotCall {
1193 pub caller: String,
1194 pub callee: String,
1195 #[primary_span]
1196 pub span: Span,
1197}
1198
1199#[derive(Diagnostic)]
1200#[diag(codegen_ssa_error_creating_import_library)]
1201pub(crate) struct ErrorCreatingImportLibrary<'a> {
1202 pub lib_name: &'a str,
1203 pub error: String,
1204}
1205
1206#[derive(Diagnostic)]
1207#[diag(codegen_ssa_aix_strip_not_used)]
1208pub(crate) struct AixStripNotUsed;
1209
1210#[derive(LintDiagnostic)]
1211#[diag(codegen_ssa_mixed_export_name_and_no_mangle)]
1212pub(crate) struct MixedExportNameAndNoMangle {
1213 #[label]
1214 pub no_mangle: Span,
1215 pub no_mangle_attr: String,
1216 #[note]
1217 pub export_name: Span,
1218 #[suggestion(style = "verbose", code = "", applicability = "machine-applicable")]
1219 pub removal_span: Span,
1220}
1221
1222#[derive(Diagnostic, Debug)]
1223pub(crate) enum XcrunError {
1224 #[diag(codegen_ssa_xcrun_failed_invoking)]
1225 FailedInvoking { sdk_name: &'static str, command_formatted: String, error: std::io::Error },
1226
1227 #[diag(codegen_ssa_xcrun_unsuccessful)]
1228 #[note]
1229 Unsuccessful {
1230 sdk_name: &'static str,
1231 command_formatted: String,
1232 stdout: String,
1233 stderr: String,
1234 },
1235}
1236
1237#[derive(Diagnostic, Debug)]
1238#[diag(codegen_ssa_xcrun_sdk_path_warning)]
1239#[note]
1240pub(crate) struct XcrunSdkPathWarning {
1241 pub sdk_name: &'static str,
1242 pub stderr: String,
1243}
1244
1245#[derive(LintDiagnostic)]
1246#[diag(codegen_ssa_aarch64_softfloat_neon)]
1247pub(crate) struct Aarch64SoftfloatNeon;
1248
1249#[derive(Diagnostic)]
1250#[diag(codegen_ssa_unknown_ctarget_feature_prefix)]
1251#[note]
1252pub(crate) struct UnknownCTargetFeaturePrefix<'a> {
1253 pub feature: &'a str,
1254}
1255
1256#[derive(Subdiagnostic)]
1257pub(crate) enum PossibleFeature<'a> {
1258 #[help(codegen_ssa_possible_feature)]
1259 Some { rust_feature: &'a str },
1260 #[help(codegen_ssa_consider_filing_feature_request)]
1261 None,
1262}
1263
1264#[derive(Diagnostic)]
1265#[diag(codegen_ssa_unknown_ctarget_feature)]
1266#[note]
1267pub(crate) struct UnknownCTargetFeature<'a> {
1268 pub feature: &'a str,
1269 #[subdiagnostic]
1270 pub rust_feature: PossibleFeature<'a>,
1271}
1272
1273#[derive(Diagnostic)]
1274#[diag(codegen_ssa_unstable_ctarget_feature)]
1275#[note]
1276pub(crate) struct UnstableCTargetFeature<'a> {
1277 pub feature: &'a str,
1278}
1279
1280#[derive(Diagnostic)]
1281#[diag(codegen_ssa_forbidden_ctarget_feature)]
1282#[note]
1283#[note(codegen_ssa_forbidden_ctarget_feature_issue)]
1284pub(crate) struct ForbiddenCTargetFeature<'a> {
1285 pub feature: &'a str,
1286 pub enabled: &'a str,
1287 pub reason: &'a str,
1288}
1289
1290pub struct TargetFeatureDisableOrEnable<'a> {
1291 pub features: &'a [&'a str],
1292 pub span: Option<Span>,
1293 pub missing_features: Option<MissingFeatures>,
1294}
1295
1296#[derive(Subdiagnostic)]
1297#[help(codegen_ssa_missing_features)]
1298pub struct MissingFeatures;
1299
1300impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> {
1301 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1302 let mut diag = Diag::new(dcx, level, fluent::codegen_ssa_target_feature_disable_or_enable);
1303 if let Some(span) = self.span {
1304 diag.span(span);
1305 };
1306 if let Some(missing_features) = self.missing_features {
1307 diag.subdiagnostic(missing_features);
1308 }
1309 diag.arg("features", self.features.join(", "));
1310 diag
1311 }
1312}
1313
1314#[derive(Diagnostic)]
1315#[diag(codegen_ssa_no_mangle_nameless)]
1316pub(crate) struct NoMangleNameless {
1317 #[primary_span]
1318 pub span: Span,
1319 pub definition: String,
1320}