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