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