]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_llvm/src/errors.rs
Rollup merge of #104965 - zacklukem:p-option-as_ref-docs, r=scottmcm
[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_invalid_minimum_alignment)]
56 pub(crate) struct InvalidMinimumAlignment {
57     pub err: String,
58 }
59
60 #[derive(Diagnostic)]
61 #[diag(codegen_llvm_sanitizer_memtag_requires_mte)]
62 pub(crate) struct SanitizerMemtagRequiresMte;
63
64 #[derive(Diagnostic)]
65 #[diag(codegen_llvm_error_writing_def_file)]
66 pub(crate) struct ErrorWritingDEFFile {
67     pub error: std::io::Error,
68 }
69
70 #[derive(Diagnostic)]
71 #[diag(codegen_llvm_error_calling_dlltool)]
72 pub(crate) struct ErrorCallingDllTool {
73     pub error: std::io::Error,
74 }
75
76 #[derive(Diagnostic)]
77 #[diag(codegen_llvm_dlltool_fail_import_library)]
78 pub(crate) struct DlltoolFailImportLibrary<'a> {
79     pub stdout: Cow<'a, str>,
80     pub stderr: Cow<'a, str>,
81 }
82
83 #[derive(Diagnostic)]
84 #[diag(codegen_llvm_dynamic_linking_with_lto)]
85 #[note]
86 pub(crate) struct DynamicLinkingWithLTO;
87
88 #[derive(Diagnostic)]
89 #[diag(codegen_llvm_fail_parsing_target_machine_config_to_target_machine)]
90 pub(crate) struct FailParsingTargetMachineConfigToTargetMachine {
91     pub error: String,
92 }
93
94 pub(crate) struct TargetFeatureDisableOrEnable<'a> {
95     pub features: &'a [&'a str],
96     pub span: Option<Span>,
97     pub missing_features: Option<MissingFeatures>,
98 }
99
100 #[derive(Subdiagnostic)]
101 #[help(codegen_llvm_missing_features)]
102 pub(crate) struct MissingFeatures;
103
104 impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
105     fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
106         let mut diag = sess.struct_err(fluent::codegen_llvm_target_feature_disable_or_enable);
107         if let Some(span) = self.span {
108             diag.set_span(span);
109         };
110         if let Some(missing_features) = self.missing_features {
111             diag.subdiagnostic(missing_features);
112         }
113         diag.set_arg("features", self.features.join(", "));
114         diag
115     }
116 }