]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_llvm/src/errors.rs
Rollup merge of #105642 - uberFoo:master, r=Dylan-DPC
[rust.git] / compiler / rustc_codegen_llvm / src / errors.rs
1 use std::borrow::Cow;
2
3 use rustc_errors::fluent;
4 use rustc_errors::DiagnosticBuilder;
5 use rustc_errors::ErrorGuaranteed;
6 use rustc_errors::Handler;
7 use rustc_errors::IntoDiagnostic;
8 use rustc_macros::{Diagnostic, Subdiagnostic};
9 use rustc_span::Span;
10
11 #[derive(Diagnostic)]
12 #[diag(codegen_llvm_unknown_ctarget_feature_prefix)]
13 #[note]
14 pub(crate) struct UnknownCTargetFeaturePrefix<'a> {
15     pub feature: &'a str,
16 }
17
18 #[derive(Diagnostic)]
19 #[diag(codegen_llvm_unknown_ctarget_feature)]
20 #[note]
21 pub(crate) struct UnknownCTargetFeature<'a> {
22     pub feature: &'a str,
23     #[subdiagnostic]
24     pub rust_feature: PossibleFeature<'a>,
25 }
26
27 #[derive(Subdiagnostic)]
28 pub(crate) enum PossibleFeature<'a> {
29     #[help(possible_feature)]
30     Some { rust_feature: &'a str },
31     #[help(consider_filing_feature_request)]
32     None,
33 }
34
35 #[derive(Diagnostic)]
36 #[diag(codegen_llvm_error_creating_import_library)]
37 pub(crate) struct ErrorCreatingImportLibrary<'a> {
38     pub lib_name: &'a str,
39     pub error: String,
40 }
41
42 #[derive(Diagnostic)]
43 #[diag(codegen_llvm_instrument_coverage_requires_llvm_12)]
44 pub(crate) struct InstrumentCoverageRequiresLLVM12;
45
46 #[derive(Diagnostic)]
47 #[diag(codegen_llvm_symbol_already_defined)]
48 pub(crate) struct SymbolAlreadyDefined<'a> {
49     #[primary_span]
50     pub span: Span,
51     pub symbol_name: &'a str,
52 }
53
54 #[derive(Diagnostic)]
55 #[diag(codegen_llvm_branch_protection_requires_aarch64)]
56 pub(crate) struct BranchProtectionRequiresAArch64;
57
58 #[derive(Diagnostic)]
59 #[diag(codegen_llvm_invalid_minimum_alignment)]
60 pub(crate) struct InvalidMinimumAlignment {
61     pub err: String,
62 }
63
64 #[derive(Diagnostic)]
65 #[diag(codegen_llvm_sanitizer_memtag_requires_mte)]
66 pub(crate) struct SanitizerMemtagRequiresMte;
67
68 #[derive(Diagnostic)]
69 #[diag(codegen_llvm_error_writing_def_file)]
70 pub(crate) struct ErrorWritingDEFFile {
71     pub error: std::io::Error,
72 }
73
74 #[derive(Diagnostic)]
75 #[diag(codegen_llvm_error_calling_dlltool)]
76 pub(crate) struct ErrorCallingDllTool {
77     pub error: std::io::Error,
78 }
79
80 #[derive(Diagnostic)]
81 #[diag(codegen_llvm_dlltool_fail_import_library)]
82 pub(crate) struct DlltoolFailImportLibrary<'a> {
83     pub stdout: Cow<'a, str>,
84     pub stderr: Cow<'a, str>,
85 }
86
87 #[derive(Diagnostic)]
88 #[diag(codegen_llvm_dynamic_linking_with_lto)]
89 #[note]
90 pub(crate) struct DynamicLinkingWithLTO;
91
92 #[derive(Diagnostic)]
93 #[diag(codegen_llvm_fail_parsing_target_machine_config_to_target_machine)]
94 pub(crate) struct FailParsingTargetMachineConfigToTargetMachine {
95     pub error: String,
96 }
97
98 pub(crate) struct TargetFeatureDisableOrEnable<'a> {
99     pub features: &'a [&'a str],
100     pub span: Option<Span>,
101     pub missing_features: Option<MissingFeatures>,
102 }
103
104 #[derive(Subdiagnostic)]
105 #[help(codegen_llvm_missing_features)]
106 pub(crate) struct MissingFeatures;
107
108 impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
109     fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
110         let mut diag = sess.struct_err(fluent::codegen_llvm_target_feature_disable_or_enable);
111         if let Some(span) = self.span {
112             diag.set_span(span);
113         };
114         if let Some(missing_features) = self.missing_features {
115             diag.subdiagnostic(missing_features);
116         }
117         diag.set_arg("features", self.features.join(", "));
118         diag
119     }
120 }