]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_session/src/errors.rs
Rollup merge of #102736 - GuillaumeGomez:search-input-color, r=notriddle
[rust.git] / compiler / rustc_session / src / errors.rs
1 use std::num::NonZeroU32;
2
3 use crate::cgu_reuse_tracker::CguReuse;
4 use rustc_errors::{
5     fluent, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, MultiSpan,
6 };
7 use rustc_macros::Diagnostic;
8 use rustc_span::{Span, Symbol};
9 use rustc_target::abi::TargetDataLayoutErrors;
10 use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple};
11
12 #[derive(Diagnostic)]
13 #[diag(session::incorrect_cgu_reuse_type)]
14 pub struct IncorrectCguReuseType<'a> {
15     #[primary_span]
16     pub span: Span,
17     pub cgu_user_name: &'a str,
18     pub actual_reuse: CguReuse,
19     pub expected_reuse: CguReuse,
20     pub at_least: u8,
21 }
22
23 #[derive(Diagnostic)]
24 #[diag(session::cgu_not_recorded)]
25 pub struct CguNotRecorded<'a> {
26     pub cgu_user_name: &'a str,
27     pub cgu_name: &'a str,
28 }
29
30 #[derive(Diagnostic)]
31 #[diag(session::feature_gate_error, code = "E0658")]
32 pub struct FeatureGateError<'a> {
33     #[primary_span]
34     pub span: MultiSpan,
35     pub explain: &'a str,
36 }
37
38 #[derive(Subdiagnostic)]
39 #[note(session::feature_diagnostic_for_issue)]
40 pub struct FeatureDiagnosticForIssue {
41     pub n: NonZeroU32,
42 }
43
44 #[derive(Subdiagnostic)]
45 #[help(session::feature_diagnostic_help)]
46 pub struct FeatureDiagnosticHelp {
47     pub feature: Symbol,
48 }
49
50 pub struct TargetDataLayoutErrorsWrapper<'a>(pub TargetDataLayoutErrors<'a>);
51
52 impl IntoDiagnostic<'_, !> for TargetDataLayoutErrorsWrapper<'_> {
53     fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> {
54         let mut diag;
55         match self.0 {
56             TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => {
57                 diag = handler.struct_fatal(fluent::session::target_invalid_address_space);
58                 diag.set_arg("addr_space", addr_space);
59                 diag.set_arg("cause", cause);
60                 diag.set_arg("err", err);
61                 diag
62             }
63             TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => {
64                 diag = handler.struct_fatal(fluent::session::target_invalid_bits);
65                 diag.set_arg("kind", kind);
66                 diag.set_arg("bit", bit);
67                 diag.set_arg("cause", cause);
68                 diag.set_arg("err", err);
69                 diag
70             }
71             TargetDataLayoutErrors::MissingAlignment { cause } => {
72                 diag = handler.struct_fatal(fluent::session::target_missing_alignment);
73                 diag.set_arg("cause", cause);
74                 diag
75             }
76             TargetDataLayoutErrors::InvalidAlignment { cause, err } => {
77                 diag = handler.struct_fatal(fluent::session::target_invalid_alignment);
78                 diag.set_arg("cause", cause);
79                 diag.set_arg("err", err);
80                 diag
81             }
82             TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => {
83                 diag = handler.struct_fatal(fluent::session::target_inconsistent_architecture);
84                 diag.set_arg("dl", dl);
85                 diag.set_arg("target", target);
86                 diag
87             }
88             TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => {
89                 diag = handler.struct_fatal(fluent::session::target_inconsistent_pointer_width);
90                 diag.set_arg("pointer_size", pointer_size);
91                 diag.set_arg("target", target);
92                 diag
93             }
94             TargetDataLayoutErrors::InvalidBitsSize { err } => {
95                 diag = handler.struct_fatal(fluent::session::target_invalid_bits_size);
96                 diag.set_arg("err", err);
97                 diag
98             }
99         }
100     }
101 }
102
103 #[derive(Diagnostic)]
104 #[diag(session::not_circumvent_feature)]
105 pub struct NotCircumventFeature;
106
107 #[derive(Diagnostic)]
108 #[diag(session::linker_plugin_lto_windows_not_supported)]
109 pub struct LinkerPluginToWindowsNotSupported;
110
111 #[derive(Diagnostic)]
112 #[diag(session::profile_use_file_does_not_exist)]
113 pub struct ProfileUseFileDoesNotExist<'a> {
114     pub path: &'a std::path::Path,
115 }
116
117 #[derive(Diagnostic)]
118 #[diag(session::profile_sample_use_file_does_not_exist)]
119 pub struct ProfileSampleUseFileDoesNotExist<'a> {
120     pub path: &'a std::path::Path,
121 }
122
123 #[derive(Diagnostic)]
124 #[diag(session::target_requires_unwind_tables)]
125 pub struct TargetRequiresUnwindTables;
126
127 #[derive(Diagnostic)]
128 #[diag(session::sanitizer_not_supported)]
129 pub struct SanitizerNotSupported {
130     pub us: String,
131 }
132
133 #[derive(Diagnostic)]
134 #[diag(session::sanitizers_not_supported)]
135 pub struct SanitizersNotSupported {
136     pub us: String,
137 }
138
139 #[derive(Diagnostic)]
140 #[diag(session::cannot_mix_and_match_sanitizers)]
141 pub struct CannotMixAndMatchSanitizers {
142     pub first: String,
143     pub second: String,
144 }
145
146 #[derive(Diagnostic)]
147 #[diag(session::cannot_enable_crt_static_linux)]
148 pub struct CannotEnableCrtStaticLinux;
149
150 #[derive(Diagnostic)]
151 #[diag(session::sanitizer_cfi_enabled)]
152 pub struct SanitizerCfiEnabled;
153
154 #[derive(Diagnostic)]
155 #[diag(session::unstable_virtual_function_elimination)]
156 pub struct UnstableVirtualFunctionElimination;
157
158 #[derive(Diagnostic)]
159 #[diag(session::unsupported_dwarf_version)]
160 pub struct UnsupportedDwarfVersion {
161     pub dwarf_version: u32,
162 }
163
164 #[derive(Diagnostic)]
165 #[diag(session::target_stack_protector_not_supported)]
166 pub struct StackProtectorNotSupportedForTarget<'a> {
167     pub stack_protector: StackProtector,
168     pub target_triple: &'a TargetTriple,
169 }
170
171 #[derive(Diagnostic)]
172 #[diag(session::split_debuginfo_unstable_platform)]
173 pub struct SplitDebugInfoUnstablePlatform {
174     pub debuginfo: SplitDebuginfo,
175 }
176
177 #[derive(Diagnostic)]
178 #[diag(session::file_is_not_writeable)]
179 pub struct FileIsNotWriteable<'a> {
180     pub file: &'a std::path::Path,
181 }
182
183 #[derive(Diagnostic)]
184 #[diag(session::crate_name_does_not_match)]
185 pub struct CrateNameDoesNotMatch<'a> {
186     #[primary_span]
187     pub span: Span,
188     pub s: &'a str,
189     pub name: Symbol,
190 }
191
192 #[derive(Diagnostic)]
193 #[diag(session::crate_name_invalid)]
194 pub struct CrateNameInvalid<'a> {
195     pub s: &'a str,
196 }
197
198 #[derive(Diagnostic)]
199 #[diag(session::crate_name_empty)]
200 pub struct CrateNameEmpty {
201     #[primary_span]
202     pub span: Option<Span>,
203 }
204
205 pub struct InvalidCharacterInCrateName<'a> {
206     pub span: Option<Span>,
207     pub character: char,
208     pub crate_name: &'a str,
209 }
210
211 impl IntoDiagnostic<'_> for InvalidCharacterInCrateName<'_> {
212     fn into_diagnostic(self, sess: &Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
213         let mut diag = sess.struct_err(fluent::session::invalid_character_in_create_name);
214         if let Some(sp) = self.span {
215             diag.set_span(sp);
216         }
217         diag.set_arg("character", self.character);
218         diag.set_arg("crate_name", self.crate_name);
219         diag
220     }
221 }
222
223 #[derive(Subdiagnostic)]
224 #[multipart_suggestion(session::expr_parentheses_needed, applicability = "machine-applicable")]
225 pub struct ExprParenthesesNeeded {
226     #[suggestion_part(code = "(")]
227     pub left: Span,
228     #[suggestion_part(code = ")")]
229     pub right: Span,
230 }
231
232 impl ExprParenthesesNeeded {
233     pub fn surrounding(s: Span) -> Self {
234         ExprParenthesesNeeded { left: s.shrink_to_lo(), right: s.shrink_to_hi() }
235     }
236 }