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_c_variadic_not_supported)]
738pub(crate) struct CVariadicNotSupported<'a> {
739    #[primary_span]
740    pub variadic_span: Span,
741    pub target: &'a str,
742}
743
744#[derive(Diagnostic)]
745#[diag(ast_passes_pattern_in_foreign, code = E0130)]
746// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)
747pub(crate) struct PatternInForeign {
748    #[primary_span]
749    #[label]
750    pub span: Span,
751}
752
753#[derive(Diagnostic)]
754#[diag(ast_passes_pattern_in_bodiless, code = E0642)]
755// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)
756pub(crate) struct PatternInBodiless {
757    #[primary_span]
758    #[label]
759    pub span: Span,
760}
761
762#[derive(Diagnostic)]
763#[diag(ast_passes_equality_in_where)]
764#[note]
765pub(crate) struct EqualityInWhere {
766    #[primary_span]
767    #[label]
768    pub span: Span,
769    #[subdiagnostic]
770    pub assoc: Option<AssociatedSuggestion>,
771    #[subdiagnostic]
772    pub assoc2: Option<AssociatedSuggestion2>,
773}
774
775#[derive(Subdiagnostic)]
776#[suggestion(
777    ast_passes_suggestion,
778    code = "{param}: {path}",
779    style = "verbose",
780    applicability = "maybe-incorrect"
781)]
782pub(crate) struct AssociatedSuggestion {
783    #[primary_span]
784    pub span: Span,
785    pub ident: Ident,
786    pub param: Ident,
787    pub path: String,
788}
789
790#[derive(Subdiagnostic)]
791#[multipart_suggestion(ast_passes_suggestion_path, applicability = "maybe-incorrect")]
792pub(crate) struct AssociatedSuggestion2 {
793    #[suggestion_part(code = "{args}")]
794    pub span: Span,
795    pub args: String,
796    #[suggestion_part(code = "")]
797    pub predicate: Span,
798    pub trait_segment: Ident,
799    pub potential_assoc: Ident,
800}
801
802#[derive(Diagnostic)]
803#[diag(ast_passes_feature_on_non_nightly, code = E0554)]
804pub(crate) struct FeatureOnNonNightly {
805    #[primary_span]
806    pub span: Span,
807    pub channel: &'static str,
808    #[subdiagnostic]
809    pub stable_features: Vec<StableFeature>,
810    #[suggestion(code = "", applicability = "machine-applicable")]
811    pub sugg: Option<Span>,
812}
813
814pub(crate) struct StableFeature {
815    pub name: Symbol,
816    pub since: Symbol,
817}
818
819impl Subdiagnostic for StableFeature {
820    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
821        diag.arg("name", self.name);
822        diag.arg("since", self.since);
823        diag.help(fluent::ast_passes_stable_since);
824    }
825}
826
827#[derive(Diagnostic)]
828#[diag(ast_passes_incompatible_features)]
829#[help]
830pub(crate) struct IncompatibleFeatures {
831    #[primary_span]
832    pub spans: Vec<Span>,
833    pub f1: Symbol,
834    pub f2: Symbol,
835}
836
837#[derive(Diagnostic)]
838#[diag(ast_passes_negative_bound_not_supported)]
839pub(crate) struct NegativeBoundUnsupported {
840    #[primary_span]
841    pub span: Span,
842}
843
844#[derive(Diagnostic)]
845#[diag(ast_passes_constraint_on_negative_bound)]
846pub(crate) struct ConstraintOnNegativeBound {
847    #[primary_span]
848    pub span: Span,
849}
850
851#[derive(Diagnostic)]
852#[diag(ast_passes_negative_bound_with_parenthetical_notation)]
853pub(crate) struct NegativeBoundWithParentheticalNotation {
854    #[primary_span]
855    pub span: Span,
856}
857
858#[derive(Diagnostic)]
859#[diag(ast_passes_match_arm_with_no_body)]
860pub(crate) struct MatchArmWithNoBody {
861    #[primary_span]
862    pub span: Span,
863    // We include the braces around `todo!()` so that a comma is optional, and we don't have to have
864    // any logic looking at the arm being replaced if there was a comma already or not for the
865    // resulting code to be correct.
866    #[suggestion(
867        code = " => {{ todo!() }}",
868        applicability = "has-placeholders",
869        style = "verbose"
870    )]
871    pub suggestion: Span,
872}
873
874#[derive(Diagnostic)]
875#[diag(ast_passes_precise_capturing_not_allowed_here)]
876pub(crate) struct PreciseCapturingNotAllowedHere {
877    #[primary_span]
878    pub span: Span,
879    pub loc: &'static str,
880}
881
882#[derive(Diagnostic)]
883#[diag(ast_passes_precise_capturing_duplicated)]
884pub(crate) struct DuplicatePreciseCapturing {
885    #[primary_span]
886    pub bound1: Span,
887    #[label]
888    pub bound2: Span,
889}
890
891#[derive(Diagnostic)]
892#[diag(ast_passes_extern_without_abi)]
893#[help]
894pub(crate) struct MissingAbi {
895    #[primary_span]
896    #[suggestion(code = "extern \"<abi>\"", applicability = "has-placeholders")]
897    pub span: Span,
898}
899
900#[derive(LintDiagnostic)]
901#[diag(ast_passes_extern_without_abi_sugg)]
902pub(crate) struct MissingAbiSugg {
903    #[suggestion(code = "extern {default_abi}", applicability = "machine-applicable")]
904    pub span: Span,
905    pub default_abi: ExternAbi,
906}
907
908#[derive(Diagnostic)]
909#[diag(ast_passes_abi_custom_safe_foreign_function)]
910pub(crate) struct AbiCustomSafeForeignFunction {
911    #[primary_span]
912    pub span: Span,
913
914    #[suggestion(
915        ast_passes_suggestion,
916        applicability = "maybe-incorrect",
917        code = "",
918        style = "verbose"
919    )]
920    pub safe_span: Span,
921}
922
923#[derive(Diagnostic)]
924#[diag(ast_passes_abi_custom_safe_function)]
925pub(crate) struct AbiCustomSafeFunction {
926    #[primary_span]
927    pub span: Span,
928    pub abi: ExternAbi,
929
930    #[suggestion(
931        ast_passes_suggestion,
932        applicability = "maybe-incorrect",
933        code = "unsafe ",
934        style = "verbose"
935    )]
936    pub unsafe_span: Span,
937}
938
939#[derive(Diagnostic)]
940#[diag(ast_passes_abi_cannot_be_coroutine)]
941pub(crate) struct AbiCannotBeCoroutine {
942    #[primary_span]
943    pub span: Span,
944    pub abi: ExternAbi,
945
946    #[suggestion(
947        ast_passes_suggestion,
948        applicability = "maybe-incorrect",
949        code = "",
950        style = "verbose"
951    )]
952    pub coroutine_kind_span: Span,
953    pub coroutine_kind_str: &'static str,
954}
955
956#[derive(Diagnostic)]
957#[diag(ast_passes_abi_must_not_have_parameters_or_return_type)]
958#[note]
959pub(crate) struct AbiMustNotHaveParametersOrReturnType {
960    #[primary_span]
961    pub spans: Vec<Span>,
962    pub abi: ExternAbi,
963
964    #[suggestion(
965        ast_passes_suggestion,
966        applicability = "maybe-incorrect",
967        code = "{padding}fn {symbol}()",
968        style = "verbose"
969    )]
970    pub suggestion_span: Span,
971    pub symbol: Symbol,
972    pub padding: &'static str,
973}
974
975#[derive(Diagnostic)]
976#[diag(ast_passes_abi_must_not_have_return_type)]
977#[note]
978pub(crate) struct AbiMustNotHaveReturnType {
979    #[primary_span]
980    #[help]
981    pub span: Span,
982    pub abi: ExternAbi,
983}
984
985#[derive(Diagnostic)]
986#[diag(ast_passes_abi_x86_interrupt)]
987#[note]
988pub(crate) struct AbiX86Interrupt {
989    #[primary_span]
990    pub spans: Vec<Span>,
991    pub param_count: usize,
992}