rustc_ast_passes/
errors.rs

1//! Errors emitted by ast_passes.
2
3use rustc_abi::ExternAbi;
4use rustc_ast::ParamKindOrd;
5use rustc_errors::codes::*;
6use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic};
7use rustc_macros::{Diagnostic, Subdiagnostic};
8use rustc_span::{Ident, Span, Symbol};
9
10use crate::fluent_generated as fluent;
11
12#[derive(Diagnostic)]
13#[diag(ast_passes_visibility_not_permitted, code = E0449)]
14pub(crate) struct VisibilityNotPermitted {
15    #[primary_span]
16    pub span: Span,
17    #[subdiagnostic]
18    pub note: VisibilityNotPermittedNote,
19    #[suggestion(
20        ast_passes_remove_qualifier_sugg,
21        code = "",
22        applicability = "machine-applicable"
23    )]
24    pub remove_qualifier_sugg: Span,
25}
26
27#[derive(Subdiagnostic)]
28pub(crate) enum VisibilityNotPermittedNote {
29    #[note(ast_passes_enum_variant)]
30    EnumVariant,
31    #[note(ast_passes_trait_impl)]
32    TraitImpl,
33    #[note(ast_passes_individual_impl_items)]
34    IndividualImplItems,
35    #[note(ast_passes_individual_foreign_items)]
36    IndividualForeignItems,
37}
38
39#[derive(Diagnostic)]
40#[diag(ast_passes_trait_fn_const, code = E0379)]
41pub(crate) struct TraitFnConst {
42    #[primary_span]
43    #[label]
44    pub span: Span,
45    pub in_impl: bool,
46    #[label(ast_passes_const_context_label)]
47    pub const_context_label: Option<Span>,
48    #[suggestion(ast_passes_remove_const_sugg, code = "")]
49    pub remove_const_sugg: (Span, Applicability),
50    pub requires_multiple_changes: bool,
51    #[suggestion(
52        ast_passes_make_impl_const_sugg,
53        code = "const ",
54        applicability = "maybe-incorrect"
55    )]
56    pub make_impl_const_sugg: Option<Span>,
57    #[suggestion(
58        ast_passes_make_trait_const_sugg,
59        code = "#[const_trait]\n",
60        applicability = "maybe-incorrect"
61    )]
62    pub make_trait_const_sugg: Option<Span>,
63}
64
65#[derive(Diagnostic)]
66#[diag(ast_passes_forbidden_bound)]
67pub(crate) struct ForbiddenBound {
68    #[primary_span]
69    pub spans: Vec<Span>,
70}
71
72#[derive(Diagnostic)]
73#[diag(ast_passes_forbidden_const_param)]
74pub(crate) struct ForbiddenConstParam {
75    #[primary_span]
76    pub const_param_spans: Vec<Span>,
77}
78
79#[derive(Diagnostic)]
80#[diag(ast_passes_fn_param_too_many)]
81pub(crate) struct FnParamTooMany {
82    #[primary_span]
83    pub span: Span,
84    pub max_num_args: usize,
85}
86
87#[derive(Diagnostic)]
88#[diag(ast_passes_fn_param_c_var_args_not_last)]
89pub(crate) struct FnParamCVarArgsNotLast {
90    #[primary_span]
91    pub span: Span,
92}
93
94#[derive(Diagnostic)]
95#[diag(ast_passes_fn_param_doc_comment)]
96pub(crate) struct FnParamDocComment {
97    #[primary_span]
98    #[label]
99    pub span: Span,
100}
101
102#[derive(Diagnostic)]
103#[diag(ast_passes_fn_param_forbidden_attr)]
104pub(crate) struct FnParamForbiddenAttr {
105    #[primary_span]
106    pub span: Span,
107}
108
109#[derive(Diagnostic)]
110#[diag(ast_passes_fn_param_forbidden_self)]
111#[note]
112pub(crate) struct FnParamForbiddenSelf {
113    #[primary_span]
114    #[label]
115    pub span: Span,
116}
117
118#[derive(Diagnostic)]
119#[diag(ast_passes_forbidden_default)]
120pub(crate) struct ForbiddenDefault {
121    #[primary_span]
122    pub span: Span,
123    #[label]
124    pub def_span: Span,
125}
126
127#[derive(Diagnostic)]
128#[diag(ast_passes_assoc_const_without_body)]
129pub(crate) struct AssocConstWithoutBody {
130    #[primary_span]
131    pub span: Span,
132    #[suggestion(code = " = <expr>;", applicability = "has-placeholders")]
133    pub replace_span: Span,
134}
135
136#[derive(Diagnostic)]
137#[diag(ast_passes_assoc_fn_without_body)]
138pub(crate) struct AssocFnWithoutBody {
139    #[primary_span]
140    pub span: Span,
141    #[suggestion(code = " {{ <body> }}", applicability = "has-placeholders")]
142    pub replace_span: Span,
143}
144
145#[derive(Diagnostic)]
146#[diag(ast_passes_assoc_type_without_body)]
147pub(crate) struct AssocTypeWithoutBody {
148    #[primary_span]
149    pub span: Span,
150    #[suggestion(code = " = <type>;", applicability = "has-placeholders")]
151    pub replace_span: Span,
152}
153
154#[derive(Diagnostic)]
155#[diag(ast_passes_const_without_body)]
156pub(crate) struct ConstWithoutBody {
157    #[primary_span]
158    pub span: Span,
159    #[suggestion(code = " = <expr>;", applicability = "has-placeholders")]
160    pub replace_span: Span,
161}
162
163#[derive(Diagnostic)]
164#[diag(ast_passes_static_without_body)]
165pub(crate) struct StaticWithoutBody {
166    #[primary_span]
167    pub span: Span,
168    #[suggestion(code = " = <expr>;", applicability = "has-placeholders")]
169    pub replace_span: Span,
170}
171
172#[derive(Diagnostic)]
173#[diag(ast_passes_ty_alias_without_body)]
174pub(crate) struct TyAliasWithoutBody {
175    #[primary_span]
176    pub span: Span,
177    #[suggestion(code = " = <type>;", applicability = "has-placeholders")]
178    pub replace_span: Span,
179}
180
181#[derive(Diagnostic)]
182#[diag(ast_passes_fn_without_body)]
183pub(crate) struct FnWithoutBody {
184    #[primary_span]
185    pub span: Span,
186    #[suggestion(code = " {{ <body> }}", applicability = "has-placeholders")]
187    pub replace_span: Span,
188    #[subdiagnostic]
189    pub extern_block_suggestion: Option<ExternBlockSuggestion>,
190}
191
192#[derive(Subdiagnostic)]
193pub(crate) enum ExternBlockSuggestion {
194    #[multipart_suggestion(ast_passes_extern_block_suggestion, applicability = "maybe-incorrect")]
195    Implicit {
196        #[suggestion_part(code = "extern {{")]
197        start_span: Span,
198        #[suggestion_part(code = " }}")]
199        end_span: Span,
200    },
201    #[multipart_suggestion(ast_passes_extern_block_suggestion, applicability = "maybe-incorrect")]
202    Explicit {
203        #[suggestion_part(code = "extern \"{abi}\" {{")]
204        start_span: Span,
205        #[suggestion_part(code = " }}")]
206        end_span: Span,
207        abi: Symbol,
208    },
209}
210
211#[derive(Diagnostic)]
212#[diag(ast_passes_extern_invalid_safety)]
213pub(crate) struct InvalidSafetyOnExtern {
214    #[primary_span]
215    pub item_span: Span,
216    #[suggestion(code = "unsafe ", applicability = "machine-applicable", style = "verbose")]
217    pub block: Option<Span>,
218}
219
220#[derive(Diagnostic)]
221#[diag(ast_passes_item_invalid_safety)]
222pub(crate) struct InvalidSafetyOnItem {
223    #[primary_span]
224    pub span: Span,
225}
226
227#[derive(Diagnostic)]
228#[diag(ast_passes_fn_ptr_invalid_safety)]
229pub(crate) struct InvalidSafetyOnFnPtr {
230    #[primary_span]
231    pub span: Span,
232}
233
234#[derive(Diagnostic)]
235#[diag(ast_passes_unsafe_static)]
236pub(crate) struct UnsafeStatic {
237    #[primary_span]
238    pub span: Span,
239}
240
241#[derive(Diagnostic)]
242#[diag(ast_passes_bound_in_context)]
243pub(crate) struct BoundInContext<'a> {
244    #[primary_span]
245    pub span: Span,
246    pub ctx: &'a str,
247}
248
249#[derive(Diagnostic)]
250#[diag(ast_passes_extern_types_cannot)]
251#[note(ast_passes_extern_keyword_link)]
252pub(crate) struct ExternTypesCannotHave<'a> {
253    #[primary_span]
254    #[suggestion(code = "", applicability = "maybe-incorrect")]
255    pub span: Span,
256    pub descr: &'a str,
257    pub remove_descr: &'a str,
258    #[label]
259    pub block_span: Span,
260}
261
262#[derive(Diagnostic)]
263#[diag(ast_passes_body_in_extern)]
264#[note(ast_passes_extern_keyword_link)]
265pub(crate) struct BodyInExtern<'a> {
266    #[primary_span]
267    #[label(ast_passes_cannot_have)]
268    pub span: Span,
269    #[label(ast_passes_invalid)]
270    pub body: Span,
271    #[label(ast_passes_existing)]
272    pub block: Span,
273    pub kind: &'a str,
274}
275
276#[derive(Diagnostic)]
277#[diag(ast_passes_fn_body_extern)]
278#[help]
279#[note(ast_passes_extern_keyword_link)]
280pub(crate) struct FnBodyInExtern {
281    #[primary_span]
282    #[label(ast_passes_cannot_have)]
283    pub span: Span,
284    #[suggestion(code = ";", applicability = "maybe-incorrect")]
285    pub body: Span,
286    #[label]
287    pub block: Span,
288}
289
290#[derive(Diagnostic)]
291#[diag(ast_passes_extern_fn_qualifiers)]
292pub(crate) struct FnQualifierInExtern {
293    #[primary_span]
294    #[suggestion(code = "", applicability = "maybe-incorrect")]
295    pub span: Span,
296    #[label]
297    pub block: Span,
298    pub kw: &'static str,
299}
300
301#[derive(Diagnostic)]
302#[diag(ast_passes_extern_item_ascii)]
303#[note]
304pub(crate) struct ExternItemAscii {
305    #[primary_span]
306    pub span: Span,
307    #[label]
308    pub block: Span,
309}
310
311#[derive(Diagnostic)]
312#[diag(ast_passes_bad_c_variadic)]
313pub(crate) struct BadCVariadic {
314    #[primary_span]
315    pub span: Vec<Span>,
316}
317
318#[derive(Diagnostic)]
319#[diag(ast_passes_item_underscore)]
320pub(crate) struct ItemUnderscore<'a> {
321    #[primary_span]
322    #[label]
323    pub span: Span,
324    pub kind: &'a str,
325}
326
327#[derive(Diagnostic)]
328#[diag(ast_passes_nomangle_ascii, code = E0754)]
329pub(crate) struct NoMangleAscii {
330    #[primary_span]
331    pub span: Span,
332}
333
334#[derive(Diagnostic)]
335#[diag(ast_passes_module_nonascii, code = E0754)]
336#[help]
337pub(crate) struct ModuleNonAscii {
338    #[primary_span]
339    pub span: Span,
340    pub name: Symbol,
341}
342
343#[derive(Diagnostic)]
344#[diag(ast_passes_auto_generic, code = E0567)]
345pub(crate) struct AutoTraitGeneric {
346    #[primary_span]
347    #[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
348    pub span: Span,
349    #[label]
350    pub ident: Span,
351}
352
353#[derive(Diagnostic)]
354#[diag(ast_passes_auto_super_lifetime, code = E0568)]
355pub(crate) struct AutoTraitBounds {
356    #[primary_span]
357    pub span: Vec<Span>,
358    #[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
359    pub removal: Span,
360    #[label]
361    pub ident: Span,
362}
363
364#[derive(Diagnostic)]
365#[diag(ast_passes_auto_items, code = E0380)]
366pub(crate) struct AutoTraitItems {
367    #[primary_span]
368    pub spans: Vec<Span>,
369    #[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
370    pub total: Span,
371    #[label]
372    pub ident: Span,
373}
374
375#[derive(Diagnostic)]
376#[diag(ast_passes_generic_before_constraints)]
377pub(crate) struct ArgsBeforeConstraint {
378    #[primary_span]
379    pub arg_spans: Vec<Span>,
380    #[label(ast_passes_constraints)]
381    pub constraints: Span,
382    #[label(ast_passes_args)]
383    pub args: Span,
384    #[suggestion(code = "{suggestion}", applicability = "machine-applicable", style = "verbose")]
385    pub data: Span,
386    pub suggestion: String,
387    pub constraint_len: usize,
388    pub args_len: usize,
389    #[subdiagnostic]
390    pub constraint_spans: EmptyLabelManySpans,
391    #[subdiagnostic]
392    pub arg_spans2: EmptyLabelManySpans,
393}
394
395pub(crate) struct EmptyLabelManySpans(pub Vec<Span>);
396
397// The derive for `Vec<Span>` does multiple calls to `span_label`, adding commas between each
398impl Subdiagnostic for EmptyLabelManySpans {
399    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
400        diag.span_labels(self.0, "");
401    }
402}
403
404#[derive(Diagnostic)]
405#[diag(ast_passes_pattern_in_fn_pointer, code = E0561)]
406pub(crate) struct PatternFnPointer {
407    #[primary_span]
408    pub span: Span,
409}
410
411#[derive(Diagnostic)]
412#[diag(ast_passes_trait_object_single_bound, code = E0226)]
413pub(crate) struct TraitObjectBound {
414    #[primary_span]
415    pub span: Span,
416}
417
418#[derive(Diagnostic)]
419#[diag(ast_passes_nested_impl_trait, code = E0666)]
420pub(crate) struct NestedImplTrait {
421    #[primary_span]
422    pub span: Span,
423    #[label(ast_passes_outer)]
424    pub outer: Span,
425    #[label(ast_passes_inner)]
426    pub inner: Span,
427}
428
429#[derive(Diagnostic)]
430#[diag(ast_passes_at_least_one_trait)]
431pub(crate) struct AtLeastOneTrait {
432    #[primary_span]
433    pub span: Span,
434}
435
436#[derive(Diagnostic)]
437#[diag(ast_passes_out_of_order_params)]
438pub(crate) struct OutOfOrderParams<'a> {
439    #[primary_span]
440    pub spans: Vec<Span>,
441    #[suggestion(code = "{ordered_params}", applicability = "machine-applicable")]
442    pub sugg_span: Span,
443    pub param_ord: &'a ParamKindOrd,
444    pub max_param: &'a ParamKindOrd,
445    pub ordered_params: &'a str,
446}
447
448#[derive(Diagnostic)]
449#[diag(ast_passes_obsolete_auto)]
450#[help]
451pub(crate) struct ObsoleteAuto {
452    #[primary_span]
453    pub span: Span,
454}
455
456#[derive(Diagnostic)]
457#[diag(ast_passes_unsafe_negative_impl, code = E0198)]
458pub(crate) struct UnsafeNegativeImpl {
459    #[primary_span]
460    pub span: Span,
461    #[label(ast_passes_negative)]
462    pub negative: Span,
463    #[label(ast_passes_unsafe)]
464    pub r#unsafe: Span,
465}
466
467#[derive(Diagnostic)]
468#[diag(ast_passes_unsafe_item)]
469pub(crate) struct UnsafeItem {
470    #[primary_span]
471    pub span: Span,
472    pub kind: &'static str,
473}
474
475#[derive(Diagnostic)]
476#[diag(ast_passes_missing_unsafe_on_extern)]
477pub(crate) struct MissingUnsafeOnExtern {
478    #[primary_span]
479    pub span: Span,
480}
481
482#[derive(Diagnostic)]
483#[diag(ast_passes_fieldless_union)]
484pub(crate) struct FieldlessUnion {
485    #[primary_span]
486    pub span: Span,
487}
488
489#[derive(Diagnostic)]
490#[diag(ast_passes_where_clause_after_type_alias)]
491#[note]
492pub(crate) struct WhereClauseAfterTypeAlias {
493    #[primary_span]
494    pub span: Span,
495    #[help]
496    pub help: bool,
497}
498
499#[derive(Diagnostic)]
500#[diag(ast_passes_where_clause_before_type_alias)]
501#[note]
502pub(crate) struct WhereClauseBeforeTypeAlias {
503    #[primary_span]
504    pub span: Span,
505    #[subdiagnostic]
506    pub sugg: WhereClauseBeforeTypeAliasSugg,
507}
508
509#[derive(Subdiagnostic)]
510pub(crate) enum WhereClauseBeforeTypeAliasSugg {
511    #[suggestion(ast_passes_remove_suggestion, applicability = "machine-applicable", code = "")]
512    Remove {
513        #[primary_span]
514        span: Span,
515    },
516    #[multipart_suggestion(
517        ast_passes_move_suggestion,
518        applicability = "machine-applicable",
519        style = "verbose"
520    )]
521    Move {
522        #[suggestion_part(code = "")]
523        left: Span,
524        snippet: String,
525        #[suggestion_part(code = "{snippet}")]
526        right: Span,
527    },
528}
529
530#[derive(Diagnostic)]
531#[diag(ast_passes_generic_default_trailing)]
532pub(crate) struct GenericDefaultTrailing {
533    #[primary_span]
534    pub span: Span,
535}
536
537#[derive(Diagnostic)]
538#[diag(ast_passes_nested_lifetimes, code = E0316)]
539pub(crate) struct NestedLifetimes {
540    #[primary_span]
541    pub span: Span,
542}
543
544#[derive(Diagnostic)]
545#[diag(ast_passes_const_bound_trait_object)]
546pub(crate) struct ConstBoundTraitObject {
547    #[primary_span]
548    pub span: Span,
549}
550
551// FIXME(const_trait_impl): Consider making the note/reason the message of the diagnostic.
552// FIXME(const_trait_impl): Provide structured suggestions (e.g., add `const` here).
553#[derive(Diagnostic)]
554#[diag(ast_passes_tilde_const_disallowed)]
555pub(crate) struct TildeConstDisallowed {
556    #[primary_span]
557    pub span: Span,
558    #[subdiagnostic]
559    pub reason: TildeConstReason,
560}
561
562#[derive(Subdiagnostic, Copy, Clone)]
563pub(crate) enum TildeConstReason {
564    #[note(ast_passes_closure)]
565    Closure,
566    #[note(ast_passes_function)]
567    Function {
568        #[primary_span]
569        ident: Span,
570    },
571    #[note(ast_passes_trait)]
572    Trait {
573        #[primary_span]
574        span: Span,
575    },
576    #[note(ast_passes_trait_impl)]
577    TraitImpl {
578        #[primary_span]
579        span: Span,
580    },
581    #[note(ast_passes_impl)]
582    Impl {
583        #[primary_span]
584        span: Span,
585    },
586    #[note(ast_passes_trait_assoc_ty)]
587    TraitAssocTy {
588        #[primary_span]
589        span: Span,
590    },
591    #[note(ast_passes_trait_impl_assoc_ty)]
592    TraitImplAssocTy {
593        #[primary_span]
594        span: Span,
595    },
596    #[note(ast_passes_inherent_assoc_ty)]
597    InherentAssocTy {
598        #[primary_span]
599        span: Span,
600    },
601    #[note(ast_passes_struct)]
602    Struct {
603        #[primary_span]
604        span: Span,
605    },
606    #[note(ast_passes_enum)]
607    Enum {
608        #[primary_span]
609        span: Span,
610    },
611    #[note(ast_passes_union)]
612    Union {
613        #[primary_span]
614        span: Span,
615    },
616    #[note(ast_passes_anon_const)]
617    AnonConst {
618        #[primary_span]
619        span: Span,
620    },
621    #[note(ast_passes_object)]
622    TraitObject,
623    #[note(ast_passes_item)]
624    Item,
625}
626
627#[derive(Diagnostic)]
628#[diag(ast_passes_const_and_coroutine)]
629pub(crate) struct ConstAndCoroutine {
630    #[primary_span]
631    pub spans: Vec<Span>,
632    #[label(ast_passes_const)]
633    pub const_span: Span,
634    #[label(ast_passes_coroutine)]
635    pub coroutine_span: Span,
636    #[label]
637    pub span: Span,
638    pub coroutine_kind: &'static str,
639}
640
641#[derive(Diagnostic)]
642#[diag(ast_passes_const_and_c_variadic)]
643pub(crate) struct ConstAndCVariadic {
644    #[primary_span]
645    pub spans: Vec<Span>,
646    #[label(ast_passes_const)]
647    pub const_span: Span,
648    #[label(ast_passes_variadic)]
649    pub variadic_spans: Vec<Span>,
650}
651
652#[derive(Diagnostic)]
653#[diag(ast_passes_pattern_in_foreign, code = E0130)]
654// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)
655pub(crate) struct PatternInForeign {
656    #[primary_span]
657    #[label]
658    pub span: Span,
659}
660
661#[derive(Diagnostic)]
662#[diag(ast_passes_pattern_in_bodiless, code = E0642)]
663// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)
664pub(crate) struct PatternInBodiless {
665    #[primary_span]
666    #[label]
667    pub span: Span,
668}
669
670#[derive(Diagnostic)]
671#[diag(ast_passes_equality_in_where)]
672#[note]
673pub(crate) struct EqualityInWhere {
674    #[primary_span]
675    #[label]
676    pub span: Span,
677    #[subdiagnostic]
678    pub assoc: Option<AssociatedSuggestion>,
679    #[subdiagnostic]
680    pub assoc2: Option<AssociatedSuggestion2>,
681}
682
683#[derive(Subdiagnostic)]
684#[suggestion(
685    ast_passes_suggestion,
686    code = "{param}: {path}",
687    style = "verbose",
688    applicability = "maybe-incorrect"
689)]
690pub(crate) struct AssociatedSuggestion {
691    #[primary_span]
692    pub span: Span,
693    pub ident: Ident,
694    pub param: Ident,
695    pub path: String,
696}
697
698#[derive(Subdiagnostic)]
699#[multipart_suggestion(ast_passes_suggestion_path, applicability = "maybe-incorrect")]
700pub(crate) struct AssociatedSuggestion2 {
701    #[suggestion_part(code = "{args}")]
702    pub span: Span,
703    pub args: String,
704    #[suggestion_part(code = "")]
705    pub predicate: Span,
706    pub trait_segment: Ident,
707    pub potential_assoc: Ident,
708}
709
710#[derive(Diagnostic)]
711#[diag(ast_passes_feature_on_non_nightly, code = E0554)]
712pub(crate) struct FeatureOnNonNightly {
713    #[primary_span]
714    pub span: Span,
715    pub channel: &'static str,
716    #[subdiagnostic]
717    pub stable_features: Vec<StableFeature>,
718    #[suggestion(code = "", applicability = "machine-applicable")]
719    pub sugg: Option<Span>,
720}
721
722pub(crate) struct StableFeature {
723    pub name: Symbol,
724    pub since: Symbol,
725}
726
727impl Subdiagnostic for StableFeature {
728    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
729        diag.arg("name", self.name);
730        diag.arg("since", self.since);
731        diag.help(fluent::ast_passes_stable_since);
732    }
733}
734
735#[derive(Diagnostic)]
736#[diag(ast_passes_incompatible_features)]
737#[help]
738pub(crate) struct IncompatibleFeatures {
739    #[primary_span]
740    pub spans: Vec<Span>,
741    pub f1: Symbol,
742    pub f2: Symbol,
743}
744
745#[derive(Diagnostic)]
746#[diag(ast_passes_negative_bound_not_supported)]
747pub(crate) struct NegativeBoundUnsupported {
748    #[primary_span]
749    pub span: Span,
750}
751
752#[derive(Diagnostic)]
753#[diag(ast_passes_constraint_on_negative_bound)]
754pub(crate) struct ConstraintOnNegativeBound {
755    #[primary_span]
756    pub span: Span,
757}
758
759#[derive(Diagnostic)]
760#[diag(ast_passes_negative_bound_with_parenthetical_notation)]
761pub(crate) struct NegativeBoundWithParentheticalNotation {
762    #[primary_span]
763    pub span: Span,
764}
765
766#[derive(Diagnostic)]
767#[diag(ast_passes_match_arm_with_no_body)]
768pub(crate) struct MatchArmWithNoBody {
769    #[primary_span]
770    pub span: Span,
771    // We include the braces around `todo!()` so that a comma is optional, and we don't have to have
772    // any logic looking at the arm being replaced if there was a comma already or not for the
773    // resulting code to be correct.
774    #[suggestion(
775        code = " => {{ todo!() }}",
776        applicability = "has-placeholders",
777        style = "verbose"
778    )]
779    pub suggestion: Span,
780}
781
782#[derive(Diagnostic)]
783#[diag(ast_passes_precise_capturing_not_allowed_here)]
784pub(crate) struct PreciseCapturingNotAllowedHere {
785    #[primary_span]
786    pub span: Span,
787    pub loc: &'static str,
788}
789
790#[derive(Diagnostic)]
791#[diag(ast_passes_precise_capturing_duplicated)]
792pub(crate) struct DuplicatePreciseCapturing {
793    #[primary_span]
794    pub bound1: Span,
795    #[label]
796    pub bound2: Span,
797}
798
799#[derive(Diagnostic)]
800#[diag(ast_passes_extern_without_abi)]
801#[help]
802pub(crate) struct MissingAbi {
803    #[primary_span]
804    #[suggestion(code = "extern \"<abi>\"", applicability = "has-placeholders")]
805    pub span: Span,
806}
807
808#[derive(Diagnostic)]
809#[diag(ast_passes_abi_custom_safe_foreign_function)]
810pub(crate) struct AbiCustomSafeForeignFunction {
811    #[primary_span]
812    pub span: Span,
813
814    #[suggestion(
815        ast_passes_suggestion,
816        applicability = "maybe-incorrect",
817        code = "",
818        style = "verbose"
819    )]
820    pub safe_span: Span,
821}
822
823#[derive(Diagnostic)]
824#[diag(ast_passes_abi_custom_safe_function)]
825pub(crate) struct AbiCustomSafeFunction {
826    #[primary_span]
827    pub span: Span,
828    pub abi: ExternAbi,
829
830    #[suggestion(
831        ast_passes_suggestion,
832        applicability = "maybe-incorrect",
833        code = "unsafe ",
834        style = "verbose"
835    )]
836    pub unsafe_span: Span,
837}
838
839#[derive(Diagnostic)]
840#[diag(ast_passes_abi_cannot_be_coroutine)]
841pub(crate) struct AbiCannotBeCoroutine {
842    #[primary_span]
843    pub span: Span,
844    pub abi: ExternAbi,
845
846    #[suggestion(
847        ast_passes_suggestion,
848        applicability = "maybe-incorrect",
849        code = "",
850        style = "verbose"
851    )]
852    pub coroutine_kind_span: Span,
853    pub coroutine_kind_str: &'static str,
854}
855
856#[derive(Diagnostic)]
857#[diag(ast_passes_abi_must_not_have_parameters_or_return_type)]
858#[note]
859pub(crate) struct AbiMustNotHaveParametersOrReturnType {
860    #[primary_span]
861    pub spans: Vec<Span>,
862    pub abi: ExternAbi,
863
864    #[suggestion(
865        ast_passes_suggestion,
866        applicability = "maybe-incorrect",
867        code = "{padding}fn {symbol}()",
868        style = "verbose"
869    )]
870    pub suggestion_span: Span,
871    pub symbol: Symbol,
872    pub padding: &'static str,
873}
874
875#[derive(Diagnostic)]
876#[diag(ast_passes_abi_must_not_have_return_type)]
877#[note]
878pub(crate) struct AbiMustNotHaveReturnType {
879    #[primary_span]
880    #[help]
881    pub span: Span,
882    pub abi: ExternAbi,
883}