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")]
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    #[suggestion(code = "", applicability = "machine-applicable")]
358    pub span: Span,
359    #[label]
360    pub ident: Span,
361}
362
363#[derive(Diagnostic)]
364#[diag(ast_passes_auto_items, code = E0380)]
365pub(crate) struct AutoTraitItems {
366    #[primary_span]
367    pub spans: Vec<Span>,
368    #[suggestion(code = "", applicability = "machine-applicable")]
369    pub total: Span,
370    #[label]
371    pub ident: Span,
372}
373
374#[derive(Diagnostic)]
375#[diag(ast_passes_generic_before_constraints)]
376pub(crate) struct ArgsBeforeConstraint {
377    #[primary_span]
378    pub arg_spans: Vec<Span>,
379    #[label(ast_passes_constraints)]
380    pub constraints: Span,
381    #[label(ast_passes_args)]
382    pub args: Span,
383    #[suggestion(code = "{suggestion}", applicability = "machine-applicable", style = "verbose")]
384    pub data: Span,
385    pub suggestion: String,
386    pub constraint_len: usize,
387    pub args_len: usize,
388    #[subdiagnostic]
389    pub constraint_spans: EmptyLabelManySpans,
390    #[subdiagnostic]
391    pub arg_spans2: EmptyLabelManySpans,
392}
393
394pub(crate) struct EmptyLabelManySpans(pub Vec<Span>);
395
396// The derive for `Vec<Span>` does multiple calls to `span_label`, adding commas between each
397impl Subdiagnostic for EmptyLabelManySpans {
398    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
399        diag.span_labels(self.0, "");
400    }
401}
402
403#[derive(Diagnostic)]
404#[diag(ast_passes_pattern_in_fn_pointer, code = E0561)]
405pub(crate) struct PatternFnPointer {
406    #[primary_span]
407    pub span: Span,
408}
409
410#[derive(Diagnostic)]
411#[diag(ast_passes_trait_object_single_bound, code = E0226)]
412pub(crate) struct TraitObjectBound {
413    #[primary_span]
414    pub span: Span,
415}
416
417#[derive(Diagnostic)]
418#[diag(ast_passes_nested_impl_trait, code = E0666)]
419pub(crate) struct NestedImplTrait {
420    #[primary_span]
421    pub span: Span,
422    #[label(ast_passes_outer)]
423    pub outer: Span,
424    #[label(ast_passes_inner)]
425    pub inner: Span,
426}
427
428#[derive(Diagnostic)]
429#[diag(ast_passes_at_least_one_trait)]
430pub(crate) struct AtLeastOneTrait {
431    #[primary_span]
432    pub span: Span,
433}
434
435#[derive(Diagnostic)]
436#[diag(ast_passes_out_of_order_params)]
437pub(crate) struct OutOfOrderParams<'a> {
438    #[primary_span]
439    pub spans: Vec<Span>,
440    #[suggestion(code = "{ordered_params}", applicability = "machine-applicable")]
441    pub sugg_span: Span,
442    pub param_ord: &'a ParamKindOrd,
443    pub max_param: &'a ParamKindOrd,
444    pub ordered_params: &'a str,
445}
446
447#[derive(Diagnostic)]
448#[diag(ast_passes_obsolete_auto)]
449#[help]
450pub(crate) struct ObsoleteAuto {
451    #[primary_span]
452    pub span: Span,
453}
454
455#[derive(Diagnostic)]
456#[diag(ast_passes_unsafe_negative_impl, code = E0198)]
457pub(crate) struct UnsafeNegativeImpl {
458    #[primary_span]
459    pub span: Span,
460    #[label(ast_passes_negative)]
461    pub negative: Span,
462    #[label(ast_passes_unsafe)]
463    pub r#unsafe: Span,
464}
465
466#[derive(Diagnostic)]
467#[diag(ast_passes_inherent_cannot_be)]
468pub(crate) struct InherentImplCannot<'a> {
469    #[primary_span]
470    pub span: Span,
471    #[label(ast_passes_because)]
472    pub annotation_span: Span,
473    pub annotation: &'a str,
474    #[label(ast_passes_type)]
475    pub self_ty: Span,
476    #[note(ast_passes_only_trait)]
477    pub only_trait: bool,
478}
479
480#[derive(Diagnostic)]
481#[diag(ast_passes_inherent_cannot_be, code = E0197)]
482pub(crate) struct InherentImplCannotUnsafe<'a> {
483    #[primary_span]
484    pub span: Span,
485    #[label(ast_passes_because)]
486    pub annotation_span: Span,
487    pub annotation: &'a str,
488    #[label(ast_passes_type)]
489    pub self_ty: Span,
490}
491
492#[derive(Diagnostic)]
493#[diag(ast_passes_unsafe_item)]
494pub(crate) struct UnsafeItem {
495    #[primary_span]
496    pub span: Span,
497    pub kind: &'static str,
498}
499
500#[derive(Diagnostic)]
501#[diag(ast_passes_missing_unsafe_on_extern)]
502pub(crate) struct MissingUnsafeOnExtern {
503    #[primary_span]
504    pub span: Span,
505}
506
507#[derive(Diagnostic)]
508#[diag(ast_passes_fieldless_union)]
509pub(crate) struct FieldlessUnion {
510    #[primary_span]
511    pub span: Span,
512}
513
514#[derive(Diagnostic)]
515#[diag(ast_passes_where_clause_after_type_alias)]
516#[note]
517pub(crate) struct WhereClauseAfterTypeAlias {
518    #[primary_span]
519    pub span: Span,
520    #[help]
521    pub help: bool,
522}
523
524#[derive(Diagnostic)]
525#[diag(ast_passes_where_clause_before_type_alias)]
526#[note]
527pub(crate) struct WhereClauseBeforeTypeAlias {
528    #[primary_span]
529    pub span: Span,
530    #[subdiagnostic]
531    pub sugg: WhereClauseBeforeTypeAliasSugg,
532}
533
534#[derive(Subdiagnostic)]
535pub(crate) enum WhereClauseBeforeTypeAliasSugg {
536    #[suggestion(ast_passes_remove_suggestion, applicability = "machine-applicable", code = "")]
537    Remove {
538        #[primary_span]
539        span: Span,
540    },
541    #[multipart_suggestion(
542        ast_passes_move_suggestion,
543        applicability = "machine-applicable",
544        style = "verbose"
545    )]
546    Move {
547        #[suggestion_part(code = "")]
548        left: Span,
549        snippet: String,
550        #[suggestion_part(code = "{snippet}")]
551        right: Span,
552    },
553}
554
555#[derive(Diagnostic)]
556#[diag(ast_passes_generic_default_trailing)]
557pub(crate) struct GenericDefaultTrailing {
558    #[primary_span]
559    pub span: Span,
560}
561
562#[derive(Diagnostic)]
563#[diag(ast_passes_nested_lifetimes, code = E0316)]
564pub(crate) struct NestedLifetimes {
565    #[primary_span]
566    pub span: Span,
567}
568
569#[derive(Diagnostic)]
570#[diag(ast_passes_const_bound_trait_object)]
571pub(crate) struct ConstBoundTraitObject {
572    #[primary_span]
573    pub span: Span,
574}
575
576// FIXME(const_trait_impl): Consider making the note/reason the message of the diagnostic.
577// FIXME(const_trait_impl): Provide structured suggestions (e.g., add `const` here).
578#[derive(Diagnostic)]
579#[diag(ast_passes_tilde_const_disallowed)]
580pub(crate) struct TildeConstDisallowed {
581    #[primary_span]
582    pub span: Span,
583    #[subdiagnostic]
584    pub reason: TildeConstReason,
585}
586
587#[derive(Subdiagnostic, Copy, Clone)]
588pub(crate) enum TildeConstReason {
589    #[note(ast_passes_closure)]
590    Closure,
591    #[note(ast_passes_function)]
592    Function {
593        #[primary_span]
594        ident: Span,
595    },
596    #[note(ast_passes_trait)]
597    Trait {
598        #[primary_span]
599        span: Span,
600    },
601    #[note(ast_passes_trait_impl)]
602    TraitImpl {
603        #[primary_span]
604        span: Span,
605    },
606    #[note(ast_passes_impl)]
607    Impl {
608        #[primary_span]
609        span: Span,
610    },
611    #[note(ast_passes_trait_assoc_ty)]
612    TraitAssocTy {
613        #[primary_span]
614        span: Span,
615    },
616    #[note(ast_passes_trait_impl_assoc_ty)]
617    TraitImplAssocTy {
618        #[primary_span]
619        span: Span,
620    },
621    #[note(ast_passes_inherent_assoc_ty)]
622    InherentAssocTy {
623        #[primary_span]
624        span: Span,
625    },
626    #[note(ast_passes_object)]
627    TraitObject,
628    #[note(ast_passes_item)]
629    Item,
630}
631
632#[derive(Diagnostic)]
633#[diag(ast_passes_const_and_coroutine)]
634pub(crate) struct ConstAndCoroutine {
635    #[primary_span]
636    pub spans: Vec<Span>,
637    #[label(ast_passes_const)]
638    pub const_span: Span,
639    #[label(ast_passes_coroutine)]
640    pub coroutine_span: Span,
641    #[label]
642    pub span: Span,
643    pub coroutine_kind: &'static str,
644}
645
646#[derive(Diagnostic)]
647#[diag(ast_passes_const_and_c_variadic)]
648pub(crate) struct ConstAndCVariadic {
649    #[primary_span]
650    pub spans: Vec<Span>,
651    #[label(ast_passes_const)]
652    pub const_span: Span,
653    #[label(ast_passes_variadic)]
654    pub variadic_spans: Vec<Span>,
655}
656
657#[derive(Diagnostic)]
658#[diag(ast_passes_pattern_in_foreign, code = E0130)]
659// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)
660pub(crate) struct PatternInForeign {
661    #[primary_span]
662    #[label]
663    pub span: Span,
664}
665
666#[derive(Diagnostic)]
667#[diag(ast_passes_pattern_in_bodiless, code = E0642)]
668// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)
669pub(crate) struct PatternInBodiless {
670    #[primary_span]
671    #[label]
672    pub span: Span,
673}
674
675#[derive(Diagnostic)]
676#[diag(ast_passes_equality_in_where)]
677#[note]
678pub(crate) struct EqualityInWhere {
679    #[primary_span]
680    #[label]
681    pub span: Span,
682    #[subdiagnostic]
683    pub assoc: Option<AssociatedSuggestion>,
684    #[subdiagnostic]
685    pub assoc2: Option<AssociatedSuggestion2>,
686}
687
688#[derive(Subdiagnostic)]
689#[suggestion(
690    ast_passes_suggestion,
691    code = "{param}: {path}",
692    style = "verbose",
693    applicability = "maybe-incorrect"
694)]
695pub(crate) struct AssociatedSuggestion {
696    #[primary_span]
697    pub span: Span,
698    pub ident: Ident,
699    pub param: Ident,
700    pub path: String,
701}
702
703#[derive(Subdiagnostic)]
704#[multipart_suggestion(ast_passes_suggestion_path, applicability = "maybe-incorrect")]
705pub(crate) struct AssociatedSuggestion2 {
706    #[suggestion_part(code = "{args}")]
707    pub span: Span,
708    pub args: String,
709    #[suggestion_part(code = "")]
710    pub predicate: Span,
711    pub trait_segment: Ident,
712    pub potential_assoc: Ident,
713}
714
715#[derive(Diagnostic)]
716#[diag(ast_passes_feature_on_non_nightly, code = E0554)]
717pub(crate) struct FeatureOnNonNightly {
718    #[primary_span]
719    pub span: Span,
720    pub channel: &'static str,
721    #[subdiagnostic]
722    pub stable_features: Vec<StableFeature>,
723    #[suggestion(code = "", applicability = "machine-applicable")]
724    pub sugg: Option<Span>,
725}
726
727pub(crate) struct StableFeature {
728    pub name: Symbol,
729    pub since: Symbol,
730}
731
732impl Subdiagnostic for StableFeature {
733    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
734        diag.arg("name", self.name);
735        diag.arg("since", self.since);
736        diag.help(fluent::ast_passes_stable_since);
737    }
738}
739
740#[derive(Diagnostic)]
741#[diag(ast_passes_incompatible_features)]
742#[help]
743pub(crate) struct IncompatibleFeatures {
744    #[primary_span]
745    pub spans: Vec<Span>,
746    pub f1: Symbol,
747    pub f2: Symbol,
748}
749
750#[derive(Diagnostic)]
751#[diag(ast_passes_negative_bound_not_supported)]
752pub(crate) struct NegativeBoundUnsupported {
753    #[primary_span]
754    pub span: Span,
755}
756
757#[derive(Diagnostic)]
758#[diag(ast_passes_constraint_on_negative_bound)]
759pub(crate) struct ConstraintOnNegativeBound {
760    #[primary_span]
761    pub span: Span,
762}
763
764#[derive(Diagnostic)]
765#[diag(ast_passes_negative_bound_with_parenthetical_notation)]
766pub(crate) struct NegativeBoundWithParentheticalNotation {
767    #[primary_span]
768    pub span: Span,
769}
770
771#[derive(Diagnostic)]
772#[diag(ast_passes_match_arm_with_no_body)]
773pub(crate) struct MatchArmWithNoBody {
774    #[primary_span]
775    pub span: Span,
776    // We include the braces around `todo!()` so that a comma is optional, and we don't have to have
777    // any logic looking at the arm being replaced if there was a comma already or not for the
778    // resulting code to be correct.
779    #[suggestion(
780        code = " => {{ todo!() }}",
781        applicability = "has-placeholders",
782        style = "verbose"
783    )]
784    pub suggestion: Span,
785}
786
787#[derive(Diagnostic)]
788#[diag(ast_passes_precise_capturing_not_allowed_here)]
789pub(crate) struct PreciseCapturingNotAllowedHere {
790    #[primary_span]
791    pub span: Span,
792    pub loc: &'static str,
793}
794
795#[derive(Diagnostic)]
796#[diag(ast_passes_precise_capturing_duplicated)]
797pub(crate) struct DuplicatePreciseCapturing {
798    #[primary_span]
799    pub bound1: Span,
800    #[label]
801    pub bound2: Span,
802}
803
804#[derive(Diagnostic)]
805#[diag(ast_passes_extern_without_abi)]
806#[help]
807pub(crate) struct MissingAbi {
808    #[primary_span]
809    #[suggestion(code = "extern \"<abi>\"", applicability = "has-placeholders")]
810    pub span: Span,
811}
812
813#[derive(Diagnostic)]
814#[diag(ast_passes_abi_custom_safe_foreign_function)]
815pub(crate) struct AbiCustomSafeForeignFunction {
816    #[primary_span]
817    pub span: Span,
818
819    #[suggestion(
820        ast_passes_suggestion,
821        applicability = "maybe-incorrect",
822        code = "",
823        style = "verbose"
824    )]
825    pub safe_span: Span,
826}
827
828#[derive(Diagnostic)]
829#[diag(ast_passes_abi_custom_safe_function)]
830pub(crate) struct AbiCustomSafeFunction {
831    #[primary_span]
832    pub span: Span,
833    pub abi: ExternAbi,
834
835    #[suggestion(
836        ast_passes_suggestion,
837        applicability = "maybe-incorrect",
838        code = "unsafe ",
839        style = "verbose"
840    )]
841    pub unsafe_span: Span,
842}
843
844#[derive(Diagnostic)]
845#[diag(ast_passes_abi_cannot_be_coroutine)]
846pub(crate) struct AbiCannotBeCoroutine {
847    #[primary_span]
848    pub span: Span,
849    pub abi: ExternAbi,
850
851    #[suggestion(
852        ast_passes_suggestion,
853        applicability = "maybe-incorrect",
854        code = "",
855        style = "verbose"
856    )]
857    pub coroutine_kind_span: Span,
858    pub coroutine_kind_str: &'static str,
859}
860
861#[derive(Diagnostic)]
862#[diag(ast_passes_abi_must_not_have_parameters_or_return_type)]
863#[note]
864pub(crate) struct AbiMustNotHaveParametersOrReturnType {
865    #[primary_span]
866    pub spans: Vec<Span>,
867    pub abi: ExternAbi,
868
869    #[suggestion(
870        ast_passes_suggestion,
871        applicability = "maybe-incorrect",
872        code = "{padding}fn {symbol}()",
873        style = "verbose"
874    )]
875    pub suggestion_span: Span,
876    pub symbol: Symbol,
877    pub padding: &'static str,
878}
879
880#[derive(Diagnostic)]
881#[diag(ast_passes_abi_must_not_have_return_type)]
882#[note]
883pub(crate) struct AbiMustNotHaveReturnType {
884    #[primary_span]
885    #[help]
886    pub span: Span,
887    pub abi: ExternAbi,
888}