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