]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_llvm/src/errors.rs
Merge commit '1480cea393d0cee195e59949eabdfbcf1230f7f9' into clippyup
[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_symbol_already_defined)]
44 pub(crate) struct SymbolAlreadyDefined<'a> {
45     #[primary_span]
46     pub span: Span,
47     pub symbol_name: &'a str,
48 }
49
50 #[derive(Diagnostic)]
51 #[diag(codegen_llvm_invalid_minimum_alignment)]
52 pub(crate) struct InvalidMinimumAlignment {
53     pub err: String,
54 }
55
56 #[derive(Diagnostic)]
57 #[diag(codegen_llvm_sanitizer_memtag_requires_mte)]
58 pub(crate) struct SanitizerMemtagRequiresMte;
59
60 #[derive(Diagnostic)]
61 #[diag(codegen_llvm_error_writing_def_file)]
62 pub(crate) struct ErrorWritingDEFFile {
63     pub error: std::io::Error,
64 }
65
66 #[derive(Diagnostic)]
67 #[diag(codegen_llvm_error_calling_dlltool)]
68 pub(crate) struct ErrorCallingDllTool {
69     pub error: std::io::Error,
70 }
71
72 #[derive(Diagnostic)]
73 #[diag(codegen_llvm_dlltool_fail_import_library)]
74 pub(crate) struct DlltoolFailImportLibrary<'a> {
75     pub stdout: Cow<'a, str>,
76     pub stderr: Cow<'a, str>,
77 }
78
79 #[derive(Diagnostic)]
80 #[diag(codegen_llvm_dynamic_linking_with_lto)]
81 #[note]
82 pub(crate) struct DynamicLinkingWithLTO;
83
84 #[derive(Diagnostic)]
85 #[diag(codegen_llvm_fail_parsing_target_machine_config_to_target_machine)]
86 pub(crate) struct FailParsingTargetMachineConfigToTargetMachine {
87     pub error: String,
88 }
89
90 pub(crate) struct TargetFeatureDisableOrEnable<'a> {
91     pub features: &'a [&'a str],
92     pub span: Option<Span>,
93     pub missing_features: Option<MissingFeatures>,
94 }
95
96 #[derive(Subdiagnostic)]
97 #[help(codegen_llvm_missing_features)]
98 pub(crate) struct MissingFeatures;
99
100 impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
101     fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
102         let mut diag = sess.struct_err(fluent::codegen_llvm_target_feature_disable_or_enable);
103         if let Some(span) = self.span {
104             diag.set_span(span);
105         };
106         if let Some(missing_features) = self.missing_features {
107             diag.subdiagnostic(missing_features);
108         }
109         diag.set_arg("features", self.features.join(", "));
110         diag
111     }
112 }