]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_resolve/src/errors.rs
Rollup merge of #105853 - jyn514:prepush-windows, r=Mark-Simulacrum
[rust.git] / compiler / rustc_resolve / src / errors.rs
1 use rustc_macros::{Diagnostic, Subdiagnostic};
2 use rustc_span::{
3     symbol::{Ident, Symbol},
4     Span,
5 };
6
7 use crate::{late::PatternSource, Res};
8
9 #[derive(Diagnostic)]
10 #[diag(resolve_parent_module_reset_for_binding, code = "E0637")]
11 pub(crate) struct ParentModuleResetForBinding;
12
13 #[derive(Diagnostic)]
14 #[diag(resolve_ampersand_used_without_explicit_lifetime_name, code = "E0637")]
15 #[note]
16 pub(crate) struct AmpersandUsedWithoutExplicitLifetimeName(#[primary_span] pub(crate) Span);
17
18 #[derive(Diagnostic)]
19 #[diag(resolve_underscore_lifetime_name_cannot_be_used_here, code = "E0637")]
20 #[note]
21 pub(crate) struct UnderscoreLifetimeNameCannotBeUsedHere(#[primary_span] pub(crate) Span);
22
23 #[derive(Diagnostic)]
24 #[diag(resolve_crate_may_not_be_imported)]
25 pub(crate) struct CrateMayNotBeImprted(#[primary_span] pub(crate) Span);
26
27 #[derive(Diagnostic)]
28 #[diag(resolve_crate_root_imports_must_be_named_explicitly)]
29 pub(crate) struct CrateRootNamesMustBeNamedExplicitly(#[primary_span] pub(crate) Span);
30
31 #[derive(Diagnostic)]
32 #[diag(resolve_crate_root_imports_must_be_named_explicitly)]
33 pub(crate) struct ResolutionError(#[primary_span] pub(crate) Span);
34
35 #[derive(Diagnostic)]
36 #[diag(resolve_name_is_already_used_as_generic_parameter, code = "E0403")]
37 pub(crate) struct NameAlreadyUsedInParameterList {
38     #[primary_span]
39     #[label]
40     pub(crate) span: Span,
41     #[label(first_use_of_name)]
42     pub(crate) first_use_span: Span,
43     pub(crate) name: Symbol,
44 }
45
46 #[derive(Diagnostic)]
47 #[diag(resolve_method_not_member_of_trait, code = "E0407")]
48 pub(crate) struct MethodNotMemberOfTrait {
49     #[primary_span]
50     #[label]
51     pub(crate) span: Span,
52     pub(crate) method: Ident,
53     pub(crate) trait_: String,
54     #[subdiagnostic]
55     pub(crate) sub: Option<AssociatedFnWithSimilarNameExists>,
56 }
57
58 #[derive(Subdiagnostic)]
59 #[suggestion(
60     resolve_associated_fn_with_similar_name_exists,
61     code = "{candidate}",
62     applicability = "maybe-incorrect"
63 )]
64 pub(crate) struct AssociatedFnWithSimilarNameExists {
65     #[primary_span]
66     pub(crate) span: Span,
67     pub(crate) candidate: Symbol,
68 }
69
70 #[derive(Diagnostic)]
71 #[diag(resolve_type_not_member_of_trait, code = "E0437")]
72 pub(crate) struct TypeNotMemberOfTrait {
73     #[primary_span]
74     #[label]
75     pub(crate) span: Span,
76     pub(crate) type_: Ident,
77     pub(crate) trait_: String,
78     #[subdiagnostic]
79     pub(crate) sub: Option<AssociatedTypeWithSimilarNameExists>,
80 }
81
82 #[derive(Subdiagnostic)]
83 #[suggestion(
84     resolve_associated_type_with_similar_name_exists,
85     code = "{candidate}",
86     applicability = "maybe-incorrect"
87 )]
88 pub(crate) struct AssociatedTypeWithSimilarNameExists {
89     #[primary_span]
90     pub(crate) span: Span,
91     pub(crate) candidate: Symbol,
92 }
93
94 #[derive(Diagnostic)]
95 #[diag(resolve_const_not_member_of_trait, code = "E0438")]
96 pub(crate) struct ConstNotMemberOfTrait {
97     #[primary_span]
98     #[label]
99     pub(crate) span: Span,
100     pub(crate) const_: Ident,
101     pub(crate) trait_: String,
102     #[subdiagnostic]
103     pub(crate) sub: Option<AssociatedConstWithSimilarNameExists>,
104 }
105
106 #[derive(Subdiagnostic)]
107 #[suggestion(
108     resolve_associated_const_with_similar_name_exists,
109     code = "{candidate}",
110     applicability = "maybe-incorrect"
111 )]
112 pub(crate) struct AssociatedConstWithSimilarNameExists {
113     #[primary_span]
114     pub(crate) span: Span,
115     pub(crate) candidate: Symbol,
116 }
117
118 #[derive(Diagnostic)]
119 #[diag(resolve_variable_bound_with_different_mode, code = "E0409")]
120 pub(crate) struct VariableBoundWithDifferentMode {
121     #[primary_span]
122     #[label]
123     pub(crate) span: Span,
124     #[label(first_binding_span)]
125     pub(crate) first_binding_span: Span,
126     pub(crate) variable_name: Symbol,
127 }
128
129 #[derive(Diagnostic)]
130 #[diag(resolve_ident_bound_more_than_once_in_parameter_list, code = "E0415")]
131 pub(crate) struct IdentifierBoundMoreThanOnceInParameterList {
132     #[primary_span]
133     #[label]
134     pub(crate) span: Span,
135     pub(crate) identifier: Symbol,
136 }
137
138 #[derive(Diagnostic)]
139 #[diag(resolve_ident_bound_more_than_once_in_same_pattern, code = "E0416")]
140 pub(crate) struct IdentifierBoundMoreThanOnceInSamePattern {
141     #[primary_span]
142     #[label]
143     pub(crate) span: Span,
144     pub(crate) identifier: Symbol,
145 }
146
147 #[derive(Diagnostic)]
148 #[diag(resolve_undeclared_label, code = "E0426")]
149 pub(crate) struct UndeclaredLabel {
150     #[primary_span]
151     #[label]
152     pub(crate) span: Span,
153     pub(crate) name: Symbol,
154     #[subdiagnostic]
155     pub(crate) sub_reachable: Option<LabelWithSimilarNameReachable>,
156     #[subdiagnostic]
157     pub(crate) sub_reachable_suggestion: Option<TryUsingSimilarlyNamedLabel>,
158     #[subdiagnostic]
159     pub(crate) sub_unreachable: Option<UnreachableLabelWithSimilarNameExists>,
160 }
161
162 #[derive(Subdiagnostic)]
163 #[label(resolve_label_with_similar_name_reachable)]
164 pub(crate) struct LabelWithSimilarNameReachable(#[primary_span] pub(crate) Span);
165
166 #[derive(Subdiagnostic)]
167 #[suggestion(
168     resolve_try_using_similarly_named_label,
169     code = "{ident_name}",
170     applicability = "maybe-incorrect"
171 )]
172 pub(crate) struct TryUsingSimilarlyNamedLabel {
173     #[primary_span]
174     pub(crate) span: Span,
175     pub(crate) ident_name: Symbol,
176 }
177
178 #[derive(Subdiagnostic)]
179 #[label(resolve_unreachable_label_with_similar_name_exists)]
180 pub(crate) struct UnreachableLabelWithSimilarNameExists {
181     #[primary_span]
182     pub(crate) ident_span: Span,
183 }
184
185 #[derive(Diagnostic)]
186 #[diag(resolve_self_import_can_only_appear_once_in_the_list, code = "E0430")]
187 pub(crate) struct SelfImportCanOnlyAppearOnceInTheList {
188     #[primary_span]
189     #[label]
190     pub(crate) span: Span,
191 }
192
193 #[derive(Diagnostic)]
194 #[diag(resolve_self_import_only_in_import_list_with_non_empty_prefix, code = "E0431")]
195 pub(crate) struct SelfImportOnlyInImportListWithNonEmptyPrefix {
196     #[primary_span]
197     #[label]
198     pub(crate) span: Span,
199 }
200
201 #[derive(Diagnostic)]
202 #[diag(resolve_cannot_capture_dynamic_environment_in_fn_item, code = "E0434")]
203 #[help]
204 pub(crate) struct CannotCaptureDynamicEnvironmentInFnItem {
205     #[primary_span]
206     pub(crate) span: Span,
207 }
208
209 #[derive(Diagnostic)]
210 #[diag(resolve_attempt_to_use_non_constant_value_in_constant, code = "E0435")]
211 pub(crate) struct AttemptToUseNonConstantValueInConstant<'a> {
212     #[primary_span]
213     pub(crate) span: Span,
214     #[subdiagnostic]
215     pub(crate) with: Option<AttemptToUseNonConstantValueInConstantWithSuggestion<'a>>,
216     #[subdiagnostic]
217     pub(crate) with_label: Option<AttemptToUseNonConstantValueInConstantLabelWithSuggestion>,
218     #[subdiagnostic]
219     pub(crate) without: Option<AttemptToUseNonConstantValueInConstantWithoutSuggestion<'a>>,
220 }
221
222 #[derive(Subdiagnostic)]
223 #[suggestion(
224     resolve_attempt_to_use_non_constant_value_in_constant_with_suggestion,
225     code = "{suggestion} {ident}",
226     applicability = "maybe-incorrect"
227 )]
228 pub(crate) struct AttemptToUseNonConstantValueInConstantWithSuggestion<'a> {
229     #[primary_span]
230     pub(crate) span: Span,
231     pub(crate) ident: Ident,
232     pub(crate) suggestion: &'a str,
233     pub(crate) current: &'a str,
234 }
235
236 #[derive(Subdiagnostic)]
237 #[label(resolve_attempt_to_use_non_constant_value_in_constant_label_with_suggestion)]
238 pub(crate) struct AttemptToUseNonConstantValueInConstantLabelWithSuggestion {
239     #[primary_span]
240     pub(crate) span: Span,
241 }
242
243 #[derive(Subdiagnostic)]
244 #[label(resolve_attempt_to_use_non_constant_value_in_constant_without_suggestion)]
245 pub(crate) struct AttemptToUseNonConstantValueInConstantWithoutSuggestion<'a> {
246     #[primary_span]
247     pub(crate) ident_span: Span,
248     pub(crate) suggestion: &'a str,
249 }
250
251 #[derive(Diagnostic)]
252 #[diag(resolve_self_imports_only_allowed_within, code = "E0429")]
253 pub(crate) struct SelfImportsOnlyAllowedWithin {
254     #[primary_span]
255     pub(crate) span: Span,
256     #[subdiagnostic]
257     pub(crate) suggestion: Option<SelfImportsOnlyAllowedWithinSuggestion>,
258     #[subdiagnostic]
259     pub(crate) mpart_suggestion: Option<SelfImportsOnlyAllowedWithinMultipartSuggestion>,
260 }
261
262 #[derive(Subdiagnostic)]
263 #[suggestion(
264     resolve_self_imports_only_allowed_within_suggestion,
265     code = "",
266     applicability = "machine-applicable"
267 )]
268 pub(crate) struct SelfImportsOnlyAllowedWithinSuggestion {
269     #[primary_span]
270     pub(crate) span: Span,
271 }
272
273 #[derive(Subdiagnostic)]
274 #[multipart_suggestion(
275     resolve_self_imports_only_allowed_within_multipart_suggestion,
276     applicability = "machine-applicable"
277 )]
278 pub(crate) struct SelfImportsOnlyAllowedWithinMultipartSuggestion {
279     #[suggestion_part(code = "{{")]
280     pub(crate) multipart_start: Span,
281     #[suggestion_part(code = "}}")]
282     pub(crate) multipart_end: Span,
283 }
284
285 #[derive(Diagnostic)]
286 #[diag(resolve_binding_shadows_something_unacceptable, code = "E0530")]
287 pub(crate) struct BindingShadowsSomethingUnacceptable<'a> {
288     #[primary_span]
289     #[label]
290     pub(crate) span: Span,
291     pub(crate) shadowing_binding: PatternSource,
292     pub(crate) shadowed_binding: Res,
293     pub(crate) article: &'a str,
294     #[subdiagnostic]
295     pub(crate) sub_suggestion: Option<BindingShadowsSomethingUnacceptableSuggestion>,
296     #[label(label_shadowed_binding)]
297     pub(crate) shadowed_binding_span: Span,
298     pub(crate) participle: &'a str,
299     pub(crate) name: Symbol,
300 }
301
302 #[derive(Subdiagnostic)]
303 #[suggestion(
304     resolve_binding_shadows_something_unacceptable_suggestion,
305     code = "{name}(..)",
306     applicability = "unspecified"
307 )]
308 pub(crate) struct BindingShadowsSomethingUnacceptableSuggestion {
309     #[primary_span]
310     pub(crate) span: Span,
311     pub(crate) name: Symbol,
312 }
313
314 #[derive(Diagnostic)]
315 #[diag(resolve_forward_declared_generic_param, code = "E0128")]
316 pub(crate) struct ForwardDeclaredGenericParam {
317     #[primary_span]
318     #[label]
319     pub(crate) span: Span,
320 }
321
322 #[derive(Diagnostic)]
323 #[diag(resolve_param_in_ty_of_const_param, code = "E0770")]
324 pub(crate) struct ParamInTyOfConstParam {
325     #[primary_span]
326     #[label]
327     pub(crate) span: Span,
328     pub(crate) name: Symbol,
329 }
330
331 #[derive(Diagnostic)]
332 #[diag(resolve_self_in_generic_param_default, code = "E0735")]
333 pub(crate) struct SelfInGenericParamDefault {
334     #[primary_span]
335     #[label]
336     pub(crate) span: Span,
337 }
338
339 #[derive(Diagnostic)]
340 #[diag(resolve_param_in_non_trivial_anon_const)]
341 pub(crate) struct ParamInNonTrivialAnonConst {
342     #[primary_span]
343     #[label]
344     pub(crate) span: Span,
345     pub(crate) name: Symbol,
346     #[subdiagnostic]
347     pub(crate) sub_is_type: ParamInNonTrivialAnonConstIsType,
348     #[subdiagnostic]
349     pub(crate) help: Option<ParamInNonTrivialAnonConstHelp>,
350 }
351
352 #[derive(Subdiagnostic)]
353 #[help(resolve_param_in_non_trivial_anon_const_help)]
354 pub(crate) struct ParamInNonTrivialAnonConstHelp;
355
356 #[derive(Subdiagnostic)]
357 pub(crate) enum ParamInNonTrivialAnonConstIsType {
358     #[note(resolve_param_in_non_trivial_anon_const_sub_type)]
359     AType,
360     #[help(resolve_param_in_non_trivial_anon_const_sub_non_type)]
361     NotAType { name: Symbol },
362 }
363
364 #[derive(Diagnostic)]
365 #[diag(resolve_unreachable_label, code = "E0767")]
366 #[note]
367 pub(crate) struct UnreachableLabel {
368     #[primary_span]
369     #[label]
370     pub(crate) span: Span,
371     pub(crate) name: Symbol,
372     #[label(label_definition_span)]
373     pub(crate) definition_span: Span,
374     #[subdiagnostic]
375     pub(crate) sub_suggestion: Option<UnreachableLabelSubSuggestion>,
376     #[subdiagnostic]
377     pub(crate) sub_suggestion_label: Option<UnreachableLabelSubLabel>,
378     #[subdiagnostic]
379     pub(crate) sub_unreachable_label: Option<UnreachableLabelSubLabelUnreachable>,
380 }
381
382 #[derive(Subdiagnostic)]
383 #[suggestion(
384     resolve_unreachable_label_suggestion_use_similarly_named,
385     code = "{ident_name}",
386     applicability = "maybe-incorrect"
387 )]
388 pub(crate) struct UnreachableLabelSubSuggestion {
389     #[primary_span]
390     pub(crate) span: Span,
391     pub(crate) ident_name: Symbol,
392 }
393
394 #[derive(Subdiagnostic)]
395 #[label(resolve_unreachable_label_similar_name_reachable)]
396 pub(crate) struct UnreachableLabelSubLabel {
397     #[primary_span]
398     pub(crate) ident_span: Span,
399 }
400
401 #[derive(Subdiagnostic)]
402 #[label(resolve_unreachable_label_similar_name_unreachable)]
403 pub(crate) struct UnreachableLabelSubLabelUnreachable {
404     #[primary_span]
405     pub(crate) ident_span: Span,
406 }
407
408 #[derive(Diagnostic)]
409 #[diag(resolve_trait_impl_mismatch, code = "{code}")]
410 pub(crate) struct TraitImplMismatch {
411     #[primary_span]
412     #[label]
413     pub(crate) span: Span,
414     pub(crate) name: Symbol,
415     pub(crate) kind: String,
416     #[label(label_trait_item)]
417     pub(crate) trait_item_span: Span,
418     pub(crate) trait_path: String,
419     pub(crate) code: String,
420 }
421
422 #[derive(Diagnostic)]
423 #[diag(resolve_invalid_asm_sym)]
424 #[help]
425 pub(crate) struct InvalidAsmSym {
426     #[primary_span]
427     #[label]
428     pub(crate) span: Span,
429 }
430
431 #[derive(Diagnostic)]
432 #[diag(resolve_trait_impl_duplicate, code = "E0201")]
433 pub(crate) struct TraitImplDuplicate {
434     #[primary_span]
435     #[label]
436     pub(crate) span: Span,
437     #[label(old_span_label)]
438     pub(crate) old_span: Span,
439     #[label(trait_item_span)]
440     pub(crate) trait_item_span: Span,
441     pub(crate) name: Symbol,
442 }
443
444 #[derive(Diagnostic)]
445 #[diag(resolve_relative_2018)]
446 pub(crate) struct Relative2018 {
447     #[primary_span]
448     pub(crate) span: Span,
449     #[suggestion(code = "crate::{path_str}", applicability = "maybe-incorrect")]
450     pub(crate) path_span: Span,
451     pub(crate) path_str: String,
452 }
453
454 #[derive(Diagnostic)]
455 #[diag(resolve_ancestor_only, code = "E0742")]
456 pub(crate) struct AncestorOnly(#[primary_span] pub(crate) Span);
457
458 #[derive(Diagnostic)]
459 #[diag(resolve_expected_found, code = "E0577")]
460 pub(crate) struct ExpectedFound {
461     #[primary_span]
462     #[label]
463     pub(crate) span: Span,
464     pub(crate) res: Res,
465     pub(crate) path_str: String,
466 }
467
468 #[derive(Diagnostic)]
469 #[diag(resolve_indeterminate, code = "E0578")]
470 pub(crate) struct Indeterminate(#[primary_span] pub(crate) Span);
471
472 #[derive(Diagnostic)]
473 #[diag(resolve_module_only)]
474 pub(crate) struct ModuleOnly(#[primary_span] pub(crate) Span);