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