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