rustc_passes/
errors.rs

1use std::io::Error;
2use std::path::{Path, PathBuf};
3
4use rustc_ast::Label;
5use rustc_errors::codes::*;
6use rustc_errors::{
7    Applicability, Diag, DiagCtxtHandle, DiagSymbolList, Diagnostic, EmissionGuarantee, Level,
8    MultiSpan, SubdiagMessageOp, Subdiagnostic,
9};
10use rustc_hir::{self as hir, ExprKind, Target};
11use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
12use rustc_middle::ty::{MainDefinition, Ty};
13use rustc_span::{DUMMY_SP, Span, Symbol};
14
15use crate::check_attr::ProcMacroKind;
16use crate::fluent_generated as fluent;
17use crate::lang_items::Duplicate;
18
19#[derive(LintDiagnostic)]
20#[diag(passes_incorrect_do_not_recommend_location)]
21pub(crate) struct IncorrectDoNotRecommendLocation;
22
23#[derive(LintDiagnostic)]
24#[diag(passes_incorrect_do_not_recommend_args)]
25pub(crate) struct DoNotRecommendDoesNotExpectArgs;
26
27#[derive(Diagnostic)]
28#[diag(passes_autodiff_attr)]
29pub(crate) struct AutoDiffAttr {
30    #[primary_span]
31    #[label]
32    pub attr_span: Span,
33}
34
35#[derive(LintDiagnostic)]
36#[diag(passes_outer_crate_level_attr)]
37pub(crate) struct OuterCrateLevelAttr;
38
39#[derive(LintDiagnostic)]
40#[diag(passes_inner_crate_level_attr)]
41pub(crate) struct InnerCrateLevelAttr;
42
43#[derive(LintDiagnostic)]
44#[diag(passes_ignored_attr_with_macro)]
45pub(crate) struct IgnoredAttrWithMacro<'a> {
46    pub sym: &'a str,
47}
48
49#[derive(LintDiagnostic)]
50#[diag(passes_ignored_attr)]
51pub(crate) struct IgnoredAttr<'a> {
52    pub sym: &'a str,
53}
54
55#[derive(LintDiagnostic)]
56#[diag(passes_inline_ignored_function_prototype)]
57pub(crate) struct IgnoredInlineAttrFnProto;
58
59#[derive(LintDiagnostic)]
60#[diag(passes_inline_ignored_constants)]
61#[warning]
62#[note]
63pub(crate) struct IgnoredInlineAttrConstants;
64
65#[derive(Diagnostic)]
66#[diag(passes_inline_not_fn_or_closure, code = E0518)]
67pub(crate) struct InlineNotFnOrClosure {
68    #[primary_span]
69    pub attr_span: Span,
70    #[label]
71    pub defn_span: Span,
72}
73
74/// "coverage attribute not allowed here"
75#[derive(Diagnostic)]
76#[diag(passes_coverage_attribute_not_allowed, code = E0788)]
77pub(crate) struct CoverageAttributeNotAllowed {
78    #[primary_span]
79    pub attr_span: Span,
80    /// "not a function, impl block, or module"
81    #[label(passes_not_fn_impl_mod)]
82    pub not_fn_impl_mod: Option<Span>,
83    /// "function has no body"
84    #[label(passes_no_body)]
85    pub no_body: Option<Span>,
86    /// "coverage attribute can be applied to a function (with body), impl block, or module"
87    #[help]
88    pub help: (),
89}
90
91#[derive(Diagnostic)]
92#[diag(passes_optimize_invalid_target)]
93pub(crate) struct OptimizeInvalidTarget {
94    #[primary_span]
95    pub attr_span: Span,
96    #[label]
97    pub defn_span: Span,
98    pub on_crate: bool,
99}
100
101#[derive(Diagnostic)]
102#[diag(passes_should_be_applied_to_fn)]
103pub(crate) struct AttrShouldBeAppliedToFn {
104    #[primary_span]
105    pub attr_span: Span,
106    #[label]
107    pub defn_span: Span,
108    pub on_crate: bool,
109}
110
111#[derive(Diagnostic)]
112#[diag(passes_should_be_applied_to_fn, code = E0739)]
113pub(crate) struct TrackedCallerWrongLocation {
114    #[primary_span]
115    pub attr_span: Span,
116    #[label]
117    pub defn_span: Span,
118    pub on_crate: bool,
119}
120
121#[derive(Diagnostic)]
122#[diag(passes_should_be_applied_to_struct_enum, code = E0701)]
123pub(crate) struct NonExhaustiveWrongLocation {
124    #[primary_span]
125    pub attr_span: Span,
126    #[label]
127    pub defn_span: Span,
128}
129
130#[derive(Diagnostic)]
131#[diag(passes_non_exaustive_with_default_field_values)]
132pub(crate) struct NonExhaustiveWithDefaultFieldValues {
133    #[primary_span]
134    pub attr_span: Span,
135    #[label]
136    pub defn_span: Span,
137}
138
139#[derive(Diagnostic)]
140#[diag(passes_should_be_applied_to_trait)]
141pub(crate) struct AttrShouldBeAppliedToTrait {
142    #[primary_span]
143    pub attr_span: Span,
144    #[label]
145    pub defn_span: Span,
146}
147
148#[derive(LintDiagnostic)]
149#[diag(passes_target_feature_on_statement)]
150pub(crate) struct TargetFeatureOnStatement;
151
152#[derive(Diagnostic)]
153#[diag(passes_should_be_applied_to_static)]
154pub(crate) struct AttrShouldBeAppliedToStatic {
155    #[primary_span]
156    pub attr_span: Span,
157    #[label]
158    pub defn_span: Span,
159}
160
161#[derive(Diagnostic)]
162#[diag(passes_doc_expect_str)]
163pub(crate) struct DocExpectStr<'a> {
164    #[primary_span]
165    pub attr_span: Span,
166    pub attr_name: &'a str,
167}
168
169#[derive(Diagnostic)]
170#[diag(passes_doc_alias_empty)]
171pub(crate) struct DocAliasEmpty<'a> {
172    #[primary_span]
173    pub span: Span,
174    pub attr_str: &'a str,
175}
176
177#[derive(Diagnostic)]
178#[diag(passes_doc_alias_bad_char)]
179pub(crate) struct DocAliasBadChar<'a> {
180    #[primary_span]
181    pub span: Span,
182    pub attr_str: &'a str,
183    pub char_: char,
184}
185
186#[derive(Diagnostic)]
187#[diag(passes_doc_alias_start_end)]
188pub(crate) struct DocAliasStartEnd<'a> {
189    #[primary_span]
190    pub span: Span,
191    pub attr_str: &'a str,
192}
193
194#[derive(Diagnostic)]
195#[diag(passes_doc_alias_bad_location)]
196pub(crate) struct DocAliasBadLocation<'a> {
197    #[primary_span]
198    pub span: Span,
199    pub attr_str: &'a str,
200    pub location: &'a str,
201}
202
203#[derive(Diagnostic)]
204#[diag(passes_doc_alias_not_an_alias)]
205pub(crate) struct DocAliasNotAnAlias<'a> {
206    #[primary_span]
207    pub span: Span,
208    pub attr_str: &'a str,
209}
210
211#[derive(LintDiagnostic)]
212#[diag(passes_doc_alias_duplicated)]
213pub(crate) struct DocAliasDuplicated {
214    #[label]
215    pub first_defn: Span,
216}
217
218#[derive(Diagnostic)]
219#[diag(passes_doc_alias_not_string_literal)]
220pub(crate) struct DocAliasNotStringLiteral {
221    #[primary_span]
222    pub span: Span,
223}
224
225#[derive(Diagnostic)]
226#[diag(passes_doc_alias_malformed)]
227pub(crate) struct DocAliasMalformed {
228    #[primary_span]
229    pub span: Span,
230}
231
232#[derive(Diagnostic)]
233#[diag(passes_doc_keyword_empty_mod)]
234pub(crate) struct DocKeywordEmptyMod {
235    #[primary_span]
236    pub span: Span,
237}
238
239#[derive(Diagnostic)]
240#[diag(passes_doc_keyword_not_keyword)]
241#[help]
242pub(crate) struct DocKeywordNotKeyword {
243    #[primary_span]
244    pub span: Span,
245    pub keyword: Symbol,
246}
247
248#[derive(Diagnostic)]
249#[diag(passes_doc_keyword_not_mod)]
250pub(crate) struct DocKeywordNotMod {
251    #[primary_span]
252    pub span: Span,
253}
254
255#[derive(Diagnostic)]
256#[diag(passes_doc_fake_variadic_not_valid)]
257pub(crate) struct DocFakeVariadicNotValid {
258    #[primary_span]
259    pub span: Span,
260}
261
262#[derive(Diagnostic)]
263#[diag(passes_doc_keyword_only_impl)]
264pub(crate) struct DocKeywordOnlyImpl {
265    #[primary_span]
266    pub span: Span,
267}
268
269#[derive(Diagnostic)]
270#[diag(passes_doc_search_unbox_invalid)]
271pub(crate) struct DocSearchUnboxInvalid {
272    #[primary_span]
273    pub span: Span,
274}
275
276#[derive(Diagnostic)]
277#[diag(passes_doc_inline_conflict)]
278#[help]
279pub(crate) struct DocKeywordConflict {
280    #[primary_span]
281    pub spans: MultiSpan,
282}
283
284#[derive(LintDiagnostic)]
285#[diag(passes_doc_inline_only_use)]
286#[note]
287pub(crate) struct DocInlineOnlyUse {
288    #[label]
289    pub attr_span: Span,
290    #[label(passes_not_a_use_item_label)]
291    pub item_span: Option<Span>,
292}
293
294#[derive(LintDiagnostic)]
295#[diag(passes_doc_masked_only_extern_crate)]
296#[note]
297pub(crate) struct DocMaskedOnlyExternCrate {
298    #[label]
299    pub attr_span: Span,
300    #[label(passes_not_an_extern_crate_label)]
301    pub item_span: Option<Span>,
302}
303
304#[derive(LintDiagnostic)]
305#[diag(passes_doc_masked_not_extern_crate_self)]
306pub(crate) struct DocMaskedNotExternCrateSelf {
307    #[label]
308    pub attr_span: Span,
309    #[label(passes_extern_crate_self_label)]
310    pub item_span: Option<Span>,
311}
312
313#[derive(Diagnostic)]
314#[diag(passes_doc_attr_not_crate_level)]
315pub(crate) struct DocAttrNotCrateLevel<'a> {
316    #[primary_span]
317    pub span: Span,
318    pub attr_name: &'a str,
319}
320
321#[derive(LintDiagnostic)]
322#[diag(passes_doc_test_unknown)]
323pub(crate) struct DocTestUnknown {
324    pub path: String,
325}
326
327#[derive(LintDiagnostic)]
328#[diag(passes_doc_test_literal)]
329pub(crate) struct DocTestLiteral;
330
331#[derive(LintDiagnostic)]
332#[diag(passes_doc_test_takes_list)]
333pub(crate) struct DocTestTakesList;
334
335#[derive(LintDiagnostic)]
336#[diag(passes_doc_cfg_hide_takes_list)]
337pub(crate) struct DocCfgHideTakesList;
338
339#[derive(LintDiagnostic)]
340#[diag(passes_doc_test_unknown_any)]
341pub(crate) struct DocTestUnknownAny {
342    pub path: String,
343}
344
345#[derive(LintDiagnostic)]
346#[diag(passes_doc_test_unknown_spotlight)]
347#[note]
348#[note(passes_no_op_note)]
349pub(crate) struct DocTestUnknownSpotlight {
350    pub path: String,
351    #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")]
352    pub span: Span,
353}
354
355#[derive(LintDiagnostic)]
356#[diag(passes_doc_test_unknown_passes)]
357#[note]
358#[help]
359#[note(passes_no_op_note)]
360pub(crate) struct DocTestUnknownPasses {
361    pub path: String,
362    #[label]
363    pub span: Span,
364}
365
366#[derive(LintDiagnostic)]
367#[diag(passes_doc_test_unknown_plugins)]
368#[note]
369#[note(passes_no_op_note)]
370pub(crate) struct DocTestUnknownPlugins {
371    pub path: String,
372    #[label]
373    pub span: Span,
374}
375
376#[derive(LintDiagnostic)]
377#[diag(passes_doc_test_unknown_include)]
378pub(crate) struct DocTestUnknownInclude {
379    pub path: String,
380    pub value: String,
381    pub inner: &'static str,
382    #[suggestion(code = "#{inner}[doc = include_str!(\"{value}\")]")]
383    pub sugg: (Span, Applicability),
384}
385
386#[derive(LintDiagnostic)]
387#[diag(passes_doc_invalid)]
388pub(crate) struct DocInvalid;
389
390#[derive(Diagnostic)]
391#[diag(passes_pass_by_value)]
392pub(crate) struct PassByValue {
393    #[primary_span]
394    pub attr_span: Span,
395    #[label]
396    pub span: Span,
397}
398
399#[derive(Diagnostic)]
400#[diag(passes_allow_incoherent_impl)]
401pub(crate) struct AllowIncoherentImpl {
402    #[primary_span]
403    pub attr_span: Span,
404    #[label]
405    pub span: Span,
406}
407
408#[derive(Diagnostic)]
409#[diag(passes_has_incoherent_inherent_impl)]
410pub(crate) struct HasIncoherentInherentImpl {
411    #[primary_span]
412    pub attr_span: Span,
413    #[label]
414    pub span: Span,
415}
416
417#[derive(Diagnostic)]
418#[diag(passes_both_ffi_const_and_pure, code = E0757)]
419pub(crate) struct BothFfiConstAndPure {
420    #[primary_span]
421    pub attr_span: Span,
422}
423
424#[derive(Diagnostic)]
425#[diag(passes_ffi_pure_invalid_target, code = E0755)]
426pub(crate) struct FfiPureInvalidTarget {
427    #[primary_span]
428    pub attr_span: Span,
429}
430
431#[derive(Diagnostic)]
432#[diag(passes_ffi_const_invalid_target, code = E0756)]
433pub(crate) struct FfiConstInvalidTarget {
434    #[primary_span]
435    pub attr_span: Span,
436}
437
438#[derive(LintDiagnostic)]
439#[diag(passes_must_use_no_effect)]
440pub(crate) struct MustUseNoEffect {
441    pub article: &'static str,
442    pub target: rustc_hir::Target,
443}
444
445#[derive(Diagnostic)]
446#[diag(passes_must_not_suspend)]
447pub(crate) struct MustNotSuspend {
448    #[primary_span]
449    pub attr_span: Span,
450    #[label]
451    pub span: Span,
452}
453
454#[derive(LintDiagnostic)]
455#[diag(passes_cold)]
456#[warning]
457pub(crate) struct Cold {
458    #[label]
459    pub span: Span,
460    pub on_crate: bool,
461}
462
463#[derive(LintDiagnostic)]
464#[diag(passes_link)]
465#[warning]
466pub(crate) struct Link {
467    #[label]
468    pub span: Option<Span>,
469}
470
471#[derive(LintDiagnostic)]
472#[diag(passes_link_name)]
473#[warning]
474pub(crate) struct LinkName<'a> {
475    #[help]
476    pub attr_span: Option<Span>,
477    #[label]
478    pub span: Span,
479    pub value: &'a str,
480}
481
482#[derive(Diagnostic)]
483#[diag(passes_no_link)]
484pub(crate) struct NoLink {
485    #[primary_span]
486    pub attr_span: Span,
487    #[label]
488    pub span: Span,
489}
490
491#[derive(Diagnostic)]
492#[diag(passes_export_name)]
493pub(crate) struct ExportName {
494    #[primary_span]
495    pub attr_span: Span,
496    #[label]
497    pub span: Span,
498}
499
500#[derive(Diagnostic)]
501#[diag(passes_rustc_layout_scalar_valid_range_not_struct)]
502pub(crate) struct RustcLayoutScalarValidRangeNotStruct {
503    #[primary_span]
504    pub attr_span: Span,
505    #[label]
506    pub span: Span,
507}
508
509#[derive(Diagnostic)]
510#[diag(passes_rustc_layout_scalar_valid_range_arg)]
511pub(crate) struct RustcLayoutScalarValidRangeArg {
512    #[primary_span]
513    pub attr_span: Span,
514}
515
516#[derive(Diagnostic)]
517#[diag(passes_rustc_legacy_const_generics_only)]
518pub(crate) struct RustcLegacyConstGenericsOnly {
519    #[primary_span]
520    pub attr_span: Span,
521    #[label]
522    pub param_span: Span,
523}
524
525#[derive(Diagnostic)]
526#[diag(passes_rustc_legacy_const_generics_index)]
527pub(crate) struct RustcLegacyConstGenericsIndex {
528    #[primary_span]
529    pub attr_span: Span,
530    #[label]
531    pub generics_span: Span,
532}
533
534#[derive(Diagnostic)]
535#[diag(passes_rustc_legacy_const_generics_index_exceed)]
536pub(crate) struct RustcLegacyConstGenericsIndexExceed {
537    #[primary_span]
538    #[label]
539    pub span: Span,
540    pub arg_count: usize,
541}
542
543#[derive(Diagnostic)]
544#[diag(passes_rustc_legacy_const_generics_index_negative)]
545pub(crate) struct RustcLegacyConstGenericsIndexNegative {
546    #[primary_span]
547    pub invalid_args: Vec<Span>,
548}
549
550#[derive(Diagnostic)]
551#[diag(passes_rustc_dirty_clean)]
552pub(crate) struct RustcDirtyClean {
553    #[primary_span]
554    pub span: Span,
555}
556
557#[derive(LintDiagnostic)]
558#[diag(passes_link_section)]
559#[warning]
560pub(crate) struct LinkSection {
561    #[label]
562    pub span: Span,
563}
564
565#[derive(LintDiagnostic)]
566#[diag(passes_no_mangle_foreign)]
567#[warning]
568#[note]
569pub(crate) struct NoMangleForeign {
570    #[label]
571    pub span: Span,
572    #[suggestion(code = "", applicability = "machine-applicable")]
573    pub attr_span: Span,
574    pub foreign_item_kind: &'static str,
575}
576
577#[derive(LintDiagnostic)]
578#[diag(passes_no_mangle)]
579#[warning]
580pub(crate) struct NoMangle {
581    #[label]
582    pub span: Span,
583}
584
585#[derive(Diagnostic)]
586#[diag(passes_repr_ident, code = E0565)]
587pub(crate) struct ReprIdent {
588    #[primary_span]
589    pub span: Span,
590}
591
592#[derive(Diagnostic)]
593#[diag(passes_repr_conflicting, code = E0566)]
594pub(crate) struct ReprConflicting {
595    #[primary_span]
596    pub hint_spans: Vec<Span>,
597}
598
599#[derive(Diagnostic)]
600#[diag(passes_repr_align_greater_than_target_max, code = E0589)]
601#[note]
602pub(crate) struct InvalidReprAlignForTarget {
603    #[primary_span]
604    pub span: Span,
605    pub size: u64,
606}
607
608#[derive(LintDiagnostic)]
609#[diag(passes_repr_conflicting, code = E0566)]
610pub(crate) struct ReprConflictingLint;
611
612#[derive(Diagnostic)]
613#[diag(passes_used_static)]
614pub(crate) struct UsedStatic {
615    #[primary_span]
616    pub attr_span: Span,
617    #[label]
618    pub span: Span,
619    pub target: &'static str,
620}
621
622#[derive(Diagnostic)]
623#[diag(passes_used_compiler_linker)]
624pub(crate) struct UsedCompilerLinker {
625    #[primary_span]
626    pub spans: Vec<Span>,
627}
628
629#[derive(Diagnostic)]
630#[diag(passes_allow_internal_unstable)]
631pub(crate) struct AllowInternalUnstable {
632    #[primary_span]
633    pub attr_span: Span,
634    #[label]
635    pub span: Span,
636}
637
638#[derive(Diagnostic)]
639#[diag(passes_debug_visualizer_placement)]
640pub(crate) struct DebugVisualizerPlacement {
641    #[primary_span]
642    pub span: Span,
643}
644
645#[derive(Diagnostic)]
646#[diag(passes_debug_visualizer_invalid)]
647#[note(passes_note_1)]
648#[note(passes_note_2)]
649#[note(passes_note_3)]
650pub(crate) struct DebugVisualizerInvalid {
651    #[primary_span]
652    pub span: Span,
653}
654
655#[derive(Diagnostic)]
656#[diag(passes_debug_visualizer_unreadable)]
657pub(crate) struct DebugVisualizerUnreadable<'a> {
658    #[primary_span]
659    pub span: Span,
660    pub file: &'a Path,
661    pub error: Error,
662}
663
664#[derive(Diagnostic)]
665#[diag(passes_rustc_allow_const_fn_unstable)]
666pub(crate) struct RustcAllowConstFnUnstable {
667    #[primary_span]
668    pub attr_span: Span,
669    #[label]
670    pub span: Span,
671}
672
673#[derive(Diagnostic)]
674#[diag(passes_rustc_std_internal_symbol)]
675pub(crate) struct RustcStdInternalSymbol {
676    #[primary_span]
677    pub attr_span: Span,
678    #[label]
679    pub span: Span,
680}
681
682#[derive(Diagnostic)]
683#[diag(passes_rustc_pub_transparent)]
684pub(crate) struct RustcPubTransparent {
685    #[primary_span]
686    pub attr_span: Span,
687    #[label]
688    pub span: Span,
689}
690
691#[derive(Diagnostic)]
692#[diag(passes_rustc_force_inline)]
693pub(crate) struct RustcForceInline {
694    #[primary_span]
695    pub attr_span: Span,
696    #[label]
697    pub span: Span,
698}
699
700#[derive(Diagnostic)]
701#[diag(passes_rustc_force_inline_coro)]
702pub(crate) struct RustcForceInlineCoro {
703    #[primary_span]
704    pub attr_span: Span,
705    #[label]
706    pub span: Span,
707}
708
709#[derive(Diagnostic)]
710#[diag(passes_link_ordinal)]
711pub(crate) struct LinkOrdinal {
712    #[primary_span]
713    pub attr_span: Span,
714}
715
716#[derive(Diagnostic)]
717#[diag(passes_confusables)]
718pub(crate) struct Confusables {
719    #[primary_span]
720    pub attr_span: Span,
721}
722
723#[derive(Diagnostic)]
724#[diag(passes_coroutine_on_non_closure)]
725pub(crate) struct CoroutineOnNonClosure {
726    #[primary_span]
727    pub span: Span,
728}
729
730#[derive(Diagnostic)]
731#[diag(passes_linkage)]
732pub(crate) struct Linkage {
733    #[primary_span]
734    pub attr_span: Span,
735    #[label]
736    pub span: Span,
737}
738
739#[derive(Diagnostic)]
740#[diag(passes_empty_confusables)]
741pub(crate) struct EmptyConfusables {
742    #[primary_span]
743    pub span: Span,
744}
745
746#[derive(Diagnostic)]
747#[diag(passes_incorrect_meta_item, code = E0539)]
748pub(crate) struct IncorrectMetaItem {
749    #[primary_span]
750    pub span: Span,
751    #[subdiagnostic]
752    pub suggestion: IncorrectMetaItemSuggestion,
753}
754
755#[derive(Subdiagnostic)]
756#[multipart_suggestion(passes_incorrect_meta_item_suggestion, applicability = "maybe-incorrect")]
757pub(crate) struct IncorrectMetaItemSuggestion {
758    #[suggestion_part(code = "\"")]
759    pub lo: Span,
760    #[suggestion_part(code = "\"")]
761    pub hi: Span,
762}
763
764#[derive(Diagnostic)]
765#[diag(passes_stability_promotable)]
766pub(crate) struct StabilityPromotable {
767    #[primary_span]
768    pub attr_span: Span,
769}
770
771#[derive(LintDiagnostic)]
772#[diag(passes_deprecated)]
773pub(crate) struct Deprecated;
774
775#[derive(LintDiagnostic)]
776#[diag(passes_macro_use)]
777pub(crate) struct MacroUse {
778    pub name: Symbol,
779}
780
781#[derive(LintDiagnostic)]
782pub(crate) enum MacroExport {
783    #[diag(passes_macro_export)]
784    Normal,
785
786    #[diag(passes_macro_export_on_decl_macro)]
787    #[note]
788    OnDeclMacro,
789
790    #[diag(passes_invalid_macro_export_arguments)]
791    UnknownItem { name: Symbol },
792
793    #[diag(passes_invalid_macro_export_arguments_too_many_items)]
794    TooManyItems,
795}
796
797#[derive(Subdiagnostic)]
798pub(crate) enum UnusedNote {
799    #[note(passes_unused_empty_lints_note)]
800    EmptyList { name: Symbol },
801    #[note(passes_unused_no_lints_note)]
802    NoLints { name: Symbol },
803    #[note(passes_unused_default_method_body_const_note)]
804    DefaultMethodBodyConst,
805    #[note(passes_unused_linker_warnings_note)]
806    LinkerWarningsBinaryCrateOnly,
807}
808
809#[derive(LintDiagnostic)]
810#[diag(passes_unused)]
811pub(crate) struct Unused {
812    #[suggestion(code = "", applicability = "machine-applicable")]
813    pub attr_span: Span,
814    #[subdiagnostic]
815    pub note: UnusedNote,
816}
817
818#[derive(Diagnostic)]
819#[diag(passes_non_exported_macro_invalid_attrs, code = E0518)]
820pub(crate) struct NonExportedMacroInvalidAttrs {
821    #[primary_span]
822    #[label]
823    pub attr_span: Span,
824}
825
826#[derive(Diagnostic)]
827#[diag(passes_may_dangle)]
828pub(crate) struct InvalidMayDangle {
829    #[primary_span]
830    pub attr_span: Span,
831}
832
833#[derive(LintDiagnostic)]
834#[diag(passes_unused_duplicate)]
835pub(crate) struct UnusedDuplicate {
836    #[suggestion(code = "", applicability = "machine-applicable")]
837    pub this: Span,
838    #[note]
839    pub other: Span,
840    #[warning]
841    pub warning: bool,
842}
843
844#[derive(Diagnostic)]
845#[diag(passes_unused_multiple)]
846pub(crate) struct UnusedMultiple {
847    #[primary_span]
848    #[suggestion(code = "", applicability = "machine-applicable")]
849    pub this: Span,
850    #[note]
851    pub other: Span,
852    pub name: Symbol,
853}
854
855#[derive(Diagnostic)]
856#[diag(passes_rustc_lint_opt_ty)]
857pub(crate) struct RustcLintOptTy {
858    #[primary_span]
859    pub attr_span: Span,
860    #[label]
861    pub span: Span,
862}
863
864#[derive(Diagnostic)]
865#[diag(passes_rustc_lint_opt_deny_field_access)]
866pub(crate) struct RustcLintOptDenyFieldAccess {
867    #[primary_span]
868    pub attr_span: Span,
869    #[label]
870    pub span: Span,
871}
872
873#[derive(Diagnostic)]
874#[diag(passes_collapse_debuginfo)]
875pub(crate) struct CollapseDebuginfo {
876    #[primary_span]
877    pub attr_span: Span,
878    #[label]
879    pub defn_span: Span,
880}
881
882#[derive(LintDiagnostic)]
883#[diag(passes_deprecated_annotation_has_no_effect)]
884pub(crate) struct DeprecatedAnnotationHasNoEffect {
885    #[suggestion(applicability = "machine-applicable", code = "")]
886    pub span: Span,
887}
888
889#[derive(Diagnostic)]
890#[diag(passes_unknown_external_lang_item, code = E0264)]
891pub(crate) struct UnknownExternLangItem {
892    #[primary_span]
893    pub span: Span,
894    pub lang_item: Symbol,
895}
896
897#[derive(Diagnostic)]
898#[diag(passes_missing_panic_handler)]
899pub(crate) struct MissingPanicHandler;
900
901#[derive(Diagnostic)]
902#[diag(passes_panic_unwind_without_std)]
903#[help]
904#[note]
905pub(crate) struct PanicUnwindWithoutStd;
906
907#[derive(Diagnostic)]
908#[diag(passes_missing_lang_item)]
909#[note]
910#[help]
911pub(crate) struct MissingLangItem {
912    pub name: Symbol,
913}
914
915#[derive(Diagnostic)]
916#[diag(passes_lang_item_fn_with_track_caller)]
917pub(crate) struct LangItemWithTrackCaller {
918    #[primary_span]
919    pub attr_span: Span,
920    pub name: Symbol,
921    #[label]
922    pub sig_span: Span,
923}
924
925#[derive(Diagnostic)]
926#[diag(passes_lang_item_fn_with_target_feature)]
927pub(crate) struct LangItemWithTargetFeature {
928    #[primary_span]
929    pub attr_span: Span,
930    pub name: Symbol,
931    #[label]
932    pub sig_span: Span,
933}
934
935#[derive(Diagnostic)]
936#[diag(passes_lang_item_on_incorrect_target, code = E0718)]
937pub(crate) struct LangItemOnIncorrectTarget {
938    #[primary_span]
939    #[label]
940    pub span: Span,
941    pub name: Symbol,
942    pub expected_target: Target,
943    pub actual_target: Target,
944}
945
946#[derive(Diagnostic)]
947#[diag(passes_unknown_lang_item, code = E0522)]
948pub(crate) struct UnknownLangItem {
949    #[primary_span]
950    #[label]
951    pub span: Span,
952    pub name: Symbol,
953}
954
955pub(crate) struct InvalidAttrAtCrateLevel {
956    pub span: Span,
957    pub sugg_span: Option<Span>,
958    pub name: Symbol,
959    pub item: Option<ItemFollowingInnerAttr>,
960}
961
962#[derive(Clone, Copy)]
963pub(crate) struct ItemFollowingInnerAttr {
964    pub span: Span,
965    pub kind: &'static str,
966}
967
968impl<G: EmissionGuarantee> Diagnostic<'_, G> for InvalidAttrAtCrateLevel {
969    #[track_caller]
970    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
971        let mut diag = Diag::new(dcx, level, fluent::passes_invalid_attr_at_crate_level);
972        diag.span(self.span);
973        diag.arg("name", self.name);
974        // Only emit an error with a suggestion if we can create a string out
975        // of the attribute span
976        if let Some(span) = self.sugg_span {
977            diag.span_suggestion_verbose(
978                span,
979                fluent::passes_suggestion,
980                String::new(),
981                Applicability::MachineApplicable,
982            );
983        }
984        if let Some(item) = self.item {
985            diag.arg("kind", item.kind);
986            diag.span_label(item.span, fluent::passes_invalid_attr_at_crate_level_item);
987        }
988        diag
989    }
990}
991
992#[derive(Diagnostic)]
993#[diag(passes_duplicate_diagnostic_item_in_crate)]
994pub(crate) struct DuplicateDiagnosticItemInCrate {
995    #[primary_span]
996    pub duplicate_span: Option<Span>,
997    #[note(passes_diagnostic_item_first_defined)]
998    pub orig_span: Option<Span>,
999    #[note]
1000    pub different_crates: bool,
1001    pub crate_name: Symbol,
1002    pub orig_crate_name: Symbol,
1003    pub name: Symbol,
1004}
1005
1006#[derive(Diagnostic)]
1007#[diag(passes_layout_abi)]
1008pub(crate) struct LayoutAbi {
1009    #[primary_span]
1010    pub span: Span,
1011    pub abi: String,
1012}
1013
1014#[derive(Diagnostic)]
1015#[diag(passes_layout_align)]
1016pub(crate) struct LayoutAlign {
1017    #[primary_span]
1018    pub span: Span,
1019    pub align: String,
1020}
1021
1022#[derive(Diagnostic)]
1023#[diag(passes_layout_size)]
1024pub(crate) struct LayoutSize {
1025    #[primary_span]
1026    pub span: Span,
1027    pub size: String,
1028}
1029
1030#[derive(Diagnostic)]
1031#[diag(passes_layout_homogeneous_aggregate)]
1032pub(crate) struct LayoutHomogeneousAggregate {
1033    #[primary_span]
1034    pub span: Span,
1035    pub homogeneous_aggregate: String,
1036}
1037
1038#[derive(Diagnostic)]
1039#[diag(passes_layout_of)]
1040pub(crate) struct LayoutOf {
1041    #[primary_span]
1042    pub span: Span,
1043    pub normalized_ty: String,
1044    pub ty_layout: String,
1045}
1046
1047#[derive(Diagnostic)]
1048#[diag(passes_layout_invalid_attribute)]
1049pub(crate) struct LayoutInvalidAttribute {
1050    #[primary_span]
1051    pub span: Span,
1052}
1053
1054#[derive(Diagnostic)]
1055#[diag(passes_abi_of)]
1056pub(crate) struct AbiOf {
1057    #[primary_span]
1058    pub span: Span,
1059    pub fn_name: Symbol,
1060    pub fn_abi: String,
1061}
1062
1063#[derive(Diagnostic)]
1064#[diag(passes_abi_ne)]
1065pub(crate) struct AbiNe {
1066    #[primary_span]
1067    pub span: Span,
1068    pub left: String,
1069    pub right: String,
1070}
1071
1072#[derive(Diagnostic)]
1073#[diag(passes_abi_invalid_attribute)]
1074pub(crate) struct AbiInvalidAttribute {
1075    #[primary_span]
1076    pub span: Span,
1077}
1078
1079#[derive(Diagnostic)]
1080#[diag(passes_unrecognized_field)]
1081pub(crate) struct UnrecognizedField {
1082    #[primary_span]
1083    pub span: Span,
1084    pub name: Symbol,
1085}
1086
1087#[derive(Diagnostic)]
1088#[diag(passes_feature_stable_twice, code = E0711)]
1089pub(crate) struct FeatureStableTwice {
1090    #[primary_span]
1091    pub span: Span,
1092    pub feature: Symbol,
1093    pub since: Symbol,
1094    pub prev_since: Symbol,
1095}
1096
1097#[derive(Diagnostic)]
1098#[diag(passes_feature_previously_declared, code = E0711)]
1099pub(crate) struct FeaturePreviouslyDeclared<'a> {
1100    #[primary_span]
1101    pub span: Span,
1102    pub feature: Symbol,
1103    pub declared: &'a str,
1104    pub prev_declared: &'a str,
1105}
1106
1107pub(crate) struct BreakNonLoop<'a> {
1108    pub span: Span,
1109    pub head: Option<Span>,
1110    pub kind: &'a str,
1111    pub suggestion: String,
1112    pub loop_label: Option<Label>,
1113    pub break_label: Option<Label>,
1114    pub break_expr_kind: &'a ExprKind<'a>,
1115    pub break_expr_span: Span,
1116}
1117
1118impl<'a, G: EmissionGuarantee> Diagnostic<'_, G> for BreakNonLoop<'a> {
1119    #[track_caller]
1120    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1121        let mut diag = Diag::new(dcx, level, fluent::passes_break_non_loop);
1122        diag.span(self.span);
1123        diag.code(E0571);
1124        diag.arg("kind", self.kind);
1125        diag.span_label(self.span, fluent::passes_label);
1126        if let Some(head) = self.head {
1127            diag.span_label(head, fluent::passes_label2);
1128        }
1129        diag.span_suggestion(
1130            self.span,
1131            fluent::passes_suggestion,
1132            self.suggestion,
1133            Applicability::MaybeIncorrect,
1134        );
1135        if let (Some(label), None) = (self.loop_label, self.break_label) {
1136            match self.break_expr_kind {
1137                ExprKind::Path(hir::QPath::Resolved(
1138                    None,
1139                    hir::Path { segments: [segment], res: hir::def::Res::Err, .. },
1140                )) if label.ident.to_string() == format!("'{}", segment.ident) => {
1141                    // This error is redundant, we will have already emitted a
1142                    // suggestion to use the label when `segment` wasn't found
1143                    // (hence the `Res::Err` check).
1144                    diag.downgrade_to_delayed_bug();
1145                }
1146                _ => {
1147                    diag.span_suggestion(
1148                        self.break_expr_span,
1149                        fluent::passes_break_expr_suggestion,
1150                        label.ident,
1151                        Applicability::MaybeIncorrect,
1152                    );
1153                }
1154            }
1155        }
1156        diag
1157    }
1158}
1159
1160#[derive(Diagnostic)]
1161#[diag(passes_continue_labeled_block, code = E0696)]
1162pub(crate) struct ContinueLabeledBlock {
1163    #[primary_span]
1164    #[label]
1165    pub span: Span,
1166    #[label(passes_block_label)]
1167    pub block_span: Span,
1168}
1169
1170#[derive(Diagnostic)]
1171#[diag(passes_break_inside_closure, code = E0267)]
1172pub(crate) struct BreakInsideClosure<'a> {
1173    #[primary_span]
1174    #[label]
1175    pub span: Span,
1176    #[label(passes_closure_label)]
1177    pub closure_span: Span,
1178    pub name: &'a str,
1179}
1180
1181#[derive(Diagnostic)]
1182#[diag(passes_break_inside_coroutine, code = E0267)]
1183pub(crate) struct BreakInsideCoroutine<'a> {
1184    #[primary_span]
1185    #[label]
1186    pub span: Span,
1187    #[label(passes_coroutine_label)]
1188    pub coroutine_span: Span,
1189    pub name: &'a str,
1190    pub kind: &'a str,
1191    pub source: &'a str,
1192}
1193
1194#[derive(Diagnostic)]
1195#[diag(passes_outside_loop, code = E0268)]
1196pub(crate) struct OutsideLoop<'a> {
1197    #[primary_span]
1198    #[label]
1199    pub spans: Vec<Span>,
1200    pub name: &'a str,
1201    pub is_break: bool,
1202    #[subdiagnostic]
1203    pub suggestion: Option<OutsideLoopSuggestion>,
1204}
1205#[derive(Subdiagnostic)]
1206#[multipart_suggestion(passes_outside_loop_suggestion, applicability = "maybe-incorrect")]
1207pub(crate) struct OutsideLoopSuggestion {
1208    #[suggestion_part(code = "'block: ")]
1209    pub block_span: Span,
1210    #[suggestion_part(code = " 'block")]
1211    pub break_spans: Vec<Span>,
1212}
1213
1214#[derive(Diagnostic)]
1215#[diag(passes_unlabeled_in_labeled_block, code = E0695)]
1216pub(crate) struct UnlabeledInLabeledBlock<'a> {
1217    #[primary_span]
1218    #[label]
1219    pub span: Span,
1220    pub cf_type: &'a str,
1221}
1222
1223#[derive(Diagnostic)]
1224#[diag(passes_unlabeled_cf_in_while_condition, code = E0590)]
1225pub(crate) struct UnlabeledCfInWhileCondition<'a> {
1226    #[primary_span]
1227    #[label]
1228    pub span: Span,
1229    pub cf_type: &'a str,
1230}
1231
1232#[derive(LintDiagnostic)]
1233#[diag(passes_undefined_naked_function_abi)]
1234pub(crate) struct UndefinedNakedFunctionAbi;
1235
1236#[derive(Diagnostic)]
1237#[diag(passes_no_patterns)]
1238pub(crate) struct NoPatterns {
1239    #[primary_span]
1240    pub span: Span,
1241}
1242
1243#[derive(Diagnostic)]
1244#[diag(passes_params_not_allowed)]
1245#[help]
1246pub(crate) struct ParamsNotAllowed {
1247    #[primary_span]
1248    pub span: Span,
1249}
1250
1251pub(crate) struct NakedFunctionsAsmBlock {
1252    pub span: Span,
1253    pub multiple_asms: Vec<Span>,
1254    pub non_asms: Vec<Span>,
1255}
1256
1257impl<G: EmissionGuarantee> Diagnostic<'_, G> for NakedFunctionsAsmBlock {
1258    #[track_caller]
1259    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1260        let mut diag = Diag::new(dcx, level, fluent::passes_naked_functions_asm_block);
1261        diag.span(self.span);
1262        diag.code(E0787);
1263        for span in self.multiple_asms.iter() {
1264            diag.span_label(*span, fluent::passes_label_multiple_asm);
1265        }
1266        for span in self.non_asms.iter() {
1267            diag.span_label(*span, fluent::passes_label_non_asm);
1268        }
1269        diag
1270    }
1271}
1272
1273#[derive(Diagnostic)]
1274#[diag(passes_naked_functions_must_naked_asm, code = E0787)]
1275pub(crate) struct NakedFunctionsMustNakedAsm {
1276    #[primary_span]
1277    #[label]
1278    pub span: Span,
1279}
1280
1281#[derive(Diagnostic)]
1282#[diag(passes_naked_functions_incompatible_attribute, code = E0736)]
1283pub(crate) struct NakedFunctionIncompatibleAttribute {
1284    #[primary_span]
1285    #[label]
1286    pub span: Span,
1287    #[label(passes_naked_attribute)]
1288    pub naked_span: Span,
1289    pub attr: Symbol,
1290}
1291
1292#[derive(Diagnostic)]
1293#[diag(passes_naked_asm_outside_naked_fn)]
1294pub(crate) struct NakedAsmOutsideNakedFn {
1295    #[primary_span]
1296    pub span: Span,
1297}
1298
1299#[derive(Diagnostic)]
1300#[diag(passes_attr_only_in_functions)]
1301pub(crate) struct AttrOnlyInFunctions {
1302    #[primary_span]
1303    pub span: Span,
1304    pub attr: Symbol,
1305}
1306
1307#[derive(Diagnostic)]
1308#[diag(passes_multiple_rustc_main, code = E0137)]
1309pub(crate) struct MultipleRustcMain {
1310    #[primary_span]
1311    pub span: Span,
1312    #[label(passes_first)]
1313    pub first: Span,
1314    #[label(passes_additional)]
1315    pub additional: Span,
1316}
1317
1318#[derive(Diagnostic)]
1319#[diag(passes_extern_main)]
1320pub(crate) struct ExternMain {
1321    #[primary_span]
1322    pub span: Span,
1323}
1324
1325pub(crate) struct NoMainErr {
1326    pub sp: Span,
1327    pub crate_name: Symbol,
1328    pub has_filename: bool,
1329    pub filename: PathBuf,
1330    pub file_empty: bool,
1331    pub non_main_fns: Vec<Span>,
1332    pub main_def_opt: Option<MainDefinition>,
1333    pub add_teach_note: bool,
1334}
1335
1336impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NoMainErr {
1337    #[track_caller]
1338    fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
1339        let mut diag = Diag::new(dcx, level, fluent::passes_no_main_function);
1340        diag.span(DUMMY_SP);
1341        diag.code(E0601);
1342        diag.arg("crate_name", self.crate_name);
1343        diag.arg("filename", self.filename);
1344        diag.arg("has_filename", self.has_filename);
1345        let note = if !self.non_main_fns.is_empty() {
1346            for &span in &self.non_main_fns {
1347                diag.span_note(span, fluent::passes_here_is_main);
1348            }
1349            diag.note(fluent::passes_one_or_more_possible_main);
1350            diag.help(fluent::passes_consider_moving_main);
1351            // There were some functions named `main` though. Try to give the user a hint.
1352            fluent::passes_main_must_be_defined_at_crate
1353        } else if self.has_filename {
1354            fluent::passes_consider_adding_main_to_file
1355        } else {
1356            fluent::passes_consider_adding_main_at_crate
1357        };
1358        if self.file_empty {
1359            diag.note(note);
1360        } else {
1361            diag.span(self.sp.shrink_to_hi());
1362            diag.span_label(self.sp.shrink_to_hi(), note);
1363        }
1364
1365        if let Some(main_def) = self.main_def_opt
1366            && main_def.opt_fn_def_id().is_none()
1367        {
1368            // There is something at `crate::main`, but it is not a function definition.
1369            diag.span_label(main_def.span, fluent::passes_non_function_main);
1370        }
1371
1372        if self.add_teach_note {
1373            diag.note(fluent::passes_teach_note);
1374        }
1375        diag
1376    }
1377}
1378
1379pub(crate) struct DuplicateLangItem {
1380    pub local_span: Option<Span>,
1381    pub lang_item_name: Symbol,
1382    pub crate_name: Symbol,
1383    pub dependency_of: Symbol,
1384    pub is_local: bool,
1385    pub path: String,
1386    pub first_defined_span: Option<Span>,
1387    pub orig_crate_name: Symbol,
1388    pub orig_dependency_of: Symbol,
1389    pub orig_is_local: bool,
1390    pub orig_path: String,
1391    pub(crate) duplicate: Duplicate,
1392}
1393
1394impl<G: EmissionGuarantee> Diagnostic<'_, G> for DuplicateLangItem {
1395    #[track_caller]
1396    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1397        let mut diag = Diag::new(
1398            dcx,
1399            level,
1400            match self.duplicate {
1401                Duplicate::Plain => fluent::passes_duplicate_lang_item,
1402                Duplicate::Crate => fluent::passes_duplicate_lang_item_crate,
1403                Duplicate::CrateDepends => fluent::passes_duplicate_lang_item_crate_depends,
1404            },
1405        );
1406        diag.code(E0152);
1407        diag.arg("lang_item_name", self.lang_item_name);
1408        diag.arg("crate_name", self.crate_name);
1409        diag.arg("dependency_of", self.dependency_of);
1410        diag.arg("path", self.path);
1411        diag.arg("orig_crate_name", self.orig_crate_name);
1412        diag.arg("orig_dependency_of", self.orig_dependency_of);
1413        diag.arg("orig_path", self.orig_path);
1414        if let Some(span) = self.local_span {
1415            diag.span(span);
1416        }
1417        if let Some(span) = self.first_defined_span {
1418            diag.span_note(span, fluent::passes_first_defined_span);
1419        } else {
1420            if self.orig_dependency_of.is_empty() {
1421                diag.note(fluent::passes_first_defined_crate);
1422            } else {
1423                diag.note(fluent::passes_first_defined_crate_depends);
1424            }
1425
1426            if self.orig_is_local {
1427                diag.note(fluent::passes_first_definition_local);
1428            } else {
1429                diag.note(fluent::passes_first_definition_path);
1430            }
1431
1432            if self.is_local {
1433                diag.note(fluent::passes_second_definition_local);
1434            } else {
1435                diag.note(fluent::passes_second_definition_path);
1436            }
1437        }
1438        diag
1439    }
1440}
1441
1442#[derive(Diagnostic)]
1443#[diag(passes_incorrect_target, code = E0718)]
1444pub(crate) struct IncorrectTarget<'a> {
1445    #[primary_span]
1446    pub span: Span,
1447    #[label]
1448    pub generics_span: Span,
1449    pub name: &'a str, // cannot be symbol because it renders e.g. `r#fn` instead of `fn`
1450    pub kind: &'static str,
1451    pub num: usize,
1452    pub actual_num: usize,
1453    pub at_least: bool,
1454}
1455
1456#[derive(LintDiagnostic)]
1457#[diag(passes_useless_assignment)]
1458pub(crate) struct UselessAssignment<'a> {
1459    pub is_field_assign: bool,
1460    pub ty: Ty<'a>,
1461}
1462
1463#[derive(LintDiagnostic)]
1464#[diag(passes_only_has_effect_on)]
1465pub(crate) struct OnlyHasEffectOn {
1466    pub attr_name: Symbol,
1467    pub target_name: String,
1468}
1469
1470#[derive(Diagnostic)]
1471#[diag(passes_object_lifetime_err)]
1472pub(crate) struct ObjectLifetimeErr {
1473    #[primary_span]
1474    pub span: Span,
1475    pub repr: String,
1476}
1477
1478#[derive(Diagnostic)]
1479#[diag(passes_unrecognized_repr_hint, code = E0552)]
1480#[help]
1481pub(crate) struct UnrecognizedReprHint {
1482    #[primary_span]
1483    pub span: Span,
1484}
1485
1486#[derive(Diagnostic)]
1487pub(crate) enum AttrApplication {
1488    #[diag(passes_attr_application_enum, code = E0517)]
1489    Enum {
1490        #[primary_span]
1491        hint_span: Span,
1492        #[label]
1493        span: Span,
1494    },
1495    #[diag(passes_attr_application_struct, code = E0517)]
1496    Struct {
1497        #[primary_span]
1498        hint_span: Span,
1499        #[label]
1500        span: Span,
1501    },
1502    #[diag(passes_attr_application_struct_union, code = E0517)]
1503    StructUnion {
1504        #[primary_span]
1505        hint_span: Span,
1506        #[label]
1507        span: Span,
1508    },
1509    #[diag(passes_attr_application_struct_enum_union, code = E0517)]
1510    StructEnumUnion {
1511        #[primary_span]
1512        hint_span: Span,
1513        #[label]
1514        span: Span,
1515    },
1516    #[diag(passes_attr_application_struct_enum_function_method_union, code = E0517)]
1517    StructEnumFunctionMethodUnion {
1518        #[primary_span]
1519        hint_span: Span,
1520        #[label]
1521        span: Span,
1522    },
1523}
1524
1525#[derive(Diagnostic)]
1526#[diag(passes_transparent_incompatible, code = E0692)]
1527pub(crate) struct TransparentIncompatible {
1528    #[primary_span]
1529    pub hint_spans: Vec<Span>,
1530    pub target: String,
1531}
1532
1533#[derive(Diagnostic)]
1534#[diag(passes_deprecated_attribute, code = E0549)]
1535pub(crate) struct DeprecatedAttribute {
1536    #[primary_span]
1537    pub span: Span,
1538}
1539
1540#[derive(Diagnostic)]
1541#[diag(passes_useless_stability)]
1542pub(crate) struct UselessStability {
1543    #[primary_span]
1544    #[label]
1545    pub span: Span,
1546    #[label(passes_item)]
1547    pub item_sp: Span,
1548}
1549
1550#[derive(Diagnostic)]
1551#[diag(passes_cannot_stabilize_deprecated)]
1552pub(crate) struct CannotStabilizeDeprecated {
1553    #[primary_span]
1554    #[label]
1555    pub span: Span,
1556    #[label(passes_item)]
1557    pub item_sp: Span,
1558}
1559
1560#[derive(Diagnostic)]
1561#[diag(passes_unstable_attr_for_already_stable_feature)]
1562pub(crate) struct UnstableAttrForAlreadyStableFeature {
1563    #[primary_span]
1564    #[label]
1565    #[help]
1566    pub span: Span,
1567    #[label(passes_item)]
1568    pub item_sp: Span,
1569}
1570
1571#[derive(Diagnostic)]
1572#[diag(passes_missing_stability_attr)]
1573pub(crate) struct MissingStabilityAttr<'a> {
1574    #[primary_span]
1575    pub span: Span,
1576    pub descr: &'a str,
1577}
1578
1579#[derive(Diagnostic)]
1580#[diag(passes_missing_const_stab_attr)]
1581pub(crate) struct MissingConstStabAttr<'a> {
1582    #[primary_span]
1583    pub span: Span,
1584    pub descr: &'a str,
1585}
1586
1587#[derive(Diagnostic)]
1588#[diag(passes_trait_impl_const_stable)]
1589#[note]
1590pub(crate) struct TraitImplConstStable {
1591    #[primary_span]
1592    pub span: Span,
1593}
1594
1595#[derive(Diagnostic)]
1596#[diag(passes_unknown_feature, code = E0635)]
1597pub(crate) struct UnknownFeature {
1598    #[primary_span]
1599    pub span: Span,
1600    pub feature: Symbol,
1601}
1602
1603#[derive(Diagnostic)]
1604#[diag(passes_implied_feature_not_exist)]
1605pub(crate) struct ImpliedFeatureNotExist {
1606    #[primary_span]
1607    pub span: Span,
1608    pub feature: Symbol,
1609    pub implied_by: Symbol,
1610}
1611
1612#[derive(Diagnostic)]
1613#[diag(passes_duplicate_feature_err, code = E0636)]
1614pub(crate) struct DuplicateFeatureErr {
1615    #[primary_span]
1616    pub span: Span,
1617    pub feature: Symbol,
1618}
1619
1620#[derive(Diagnostic)]
1621#[diag(passes_missing_const_err)]
1622pub(crate) struct MissingConstErr {
1623    #[primary_span]
1624    #[help]
1625    pub fn_sig_span: Span,
1626}
1627
1628#[derive(Diagnostic)]
1629#[diag(passes_const_stable_not_stable)]
1630pub(crate) struct ConstStableNotStable {
1631    #[primary_span]
1632    pub fn_sig_span: Span,
1633    #[label]
1634    pub const_span: Span,
1635}
1636
1637#[derive(LintDiagnostic)]
1638pub(crate) enum MultipleDeadCodes<'tcx> {
1639    #[diag(passes_dead_codes)]
1640    DeadCodes {
1641        multiple: bool,
1642        num: usize,
1643        descr: &'tcx str,
1644        participle: &'tcx str,
1645        name_list: DiagSymbolList,
1646        #[subdiagnostic]
1647        parent_info: Option<ParentInfo<'tcx>>,
1648        #[subdiagnostic]
1649        ignored_derived_impls: Option<IgnoredDerivedImpls>,
1650    },
1651    #[diag(passes_dead_codes)]
1652    UnusedTupleStructFields {
1653        multiple: bool,
1654        num: usize,
1655        descr: &'tcx str,
1656        participle: &'tcx str,
1657        name_list: DiagSymbolList,
1658        #[subdiagnostic]
1659        change_fields_suggestion: ChangeFields,
1660        #[subdiagnostic]
1661        parent_info: Option<ParentInfo<'tcx>>,
1662        #[subdiagnostic]
1663        ignored_derived_impls: Option<IgnoredDerivedImpls>,
1664    },
1665}
1666
1667#[derive(Subdiagnostic)]
1668#[label(passes_parent_info)]
1669pub(crate) struct ParentInfo<'tcx> {
1670    pub num: usize,
1671    pub descr: &'tcx str,
1672    pub parent_descr: &'tcx str,
1673    #[primary_span]
1674    pub span: Span,
1675}
1676
1677#[derive(Subdiagnostic)]
1678#[note(passes_ignored_derived_impls)]
1679pub(crate) struct IgnoredDerivedImpls {
1680    pub name: Symbol,
1681    pub trait_list: DiagSymbolList,
1682    pub trait_list_len: usize,
1683}
1684
1685#[derive(Subdiagnostic)]
1686pub(crate) enum ChangeFields {
1687    #[multipart_suggestion(
1688        passes_change_fields_to_be_of_unit_type,
1689        applicability = "has-placeholders"
1690    )]
1691    ChangeToUnitTypeOrRemove {
1692        num: usize,
1693        #[suggestion_part(code = "()")]
1694        spans: Vec<Span>,
1695    },
1696    #[help(passes_remove_fields)]
1697    Remove { num: usize },
1698}
1699
1700#[derive(Diagnostic)]
1701#[diag(passes_proc_macro_bad_sig)]
1702pub(crate) struct ProcMacroBadSig {
1703    #[primary_span]
1704    pub span: Span,
1705    pub kind: ProcMacroKind,
1706}
1707
1708#[derive(LintDiagnostic)]
1709#[diag(passes_unreachable_due_to_uninhabited)]
1710pub(crate) struct UnreachableDueToUninhabited<'desc, 'tcx> {
1711    pub descr: &'desc str,
1712    #[label]
1713    pub expr: Span,
1714    #[label(passes_label_orig)]
1715    #[note]
1716    pub orig: Span,
1717    pub ty: Ty<'tcx>,
1718}
1719
1720#[derive(LintDiagnostic)]
1721#[diag(passes_unused_var_maybe_capture_ref)]
1722#[help]
1723pub(crate) struct UnusedVarMaybeCaptureRef {
1724    pub name: String,
1725}
1726
1727#[derive(LintDiagnostic)]
1728#[diag(passes_unused_capture_maybe_capture_ref)]
1729#[help]
1730pub(crate) struct UnusedCaptureMaybeCaptureRef {
1731    pub name: String,
1732}
1733
1734#[derive(LintDiagnostic)]
1735#[diag(passes_unused_var_remove_field)]
1736pub(crate) struct UnusedVarRemoveField {
1737    pub name: String,
1738    #[subdiagnostic]
1739    pub sugg: UnusedVarRemoveFieldSugg,
1740}
1741
1742#[derive(Subdiagnostic)]
1743#[multipart_suggestion(
1744    passes_unused_var_remove_field_suggestion,
1745    applicability = "machine-applicable"
1746)]
1747pub(crate) struct UnusedVarRemoveFieldSugg {
1748    #[suggestion_part(code = "")]
1749    pub spans: Vec<Span>,
1750}
1751
1752#[derive(LintDiagnostic)]
1753#[diag(passes_unused_var_assigned_only)]
1754#[note]
1755pub(crate) struct UnusedVarAssignedOnly {
1756    pub name: String,
1757}
1758
1759#[derive(LintDiagnostic)]
1760#[diag(passes_unnecessary_stable_feature)]
1761pub(crate) struct UnnecessaryStableFeature {
1762    pub feature: Symbol,
1763    pub since: Symbol,
1764}
1765
1766#[derive(LintDiagnostic)]
1767#[diag(passes_unnecessary_partial_stable_feature)]
1768pub(crate) struct UnnecessaryPartialStableFeature {
1769    #[suggestion(code = "{implies}", applicability = "maybe-incorrect")]
1770    pub span: Span,
1771    #[suggestion(passes_suggestion_remove, code = "", applicability = "maybe-incorrect")]
1772    pub line: Span,
1773    pub feature: Symbol,
1774    pub since: Symbol,
1775    pub implies: Symbol,
1776}
1777
1778#[derive(LintDiagnostic)]
1779#[diag(passes_ineffective_unstable_impl)]
1780#[note]
1781pub(crate) struct IneffectiveUnstableImpl;
1782
1783#[derive(LintDiagnostic)]
1784#[diag(passes_unused_assign)]
1785pub(crate) struct UnusedAssign {
1786    pub name: String,
1787    #[subdiagnostic]
1788    pub suggestion: Option<UnusedAssignSuggestion>,
1789    #[help]
1790    pub help: bool,
1791}
1792
1793#[derive(Subdiagnostic)]
1794#[multipart_suggestion(passes_unused_assign_suggestion, applicability = "maybe-incorrect")]
1795pub(crate) struct UnusedAssignSuggestion {
1796    pub pre: &'static str,
1797    #[suggestion_part(code = "{pre}mut ")]
1798    pub ty_span: Option<Span>,
1799    #[suggestion_part(code = "")]
1800    pub ty_ref_span: Span,
1801    #[suggestion_part(code = "*")]
1802    pub ident_span: Span,
1803    #[suggestion_part(code = "")]
1804    pub expr_ref_span: Span,
1805}
1806
1807#[derive(LintDiagnostic)]
1808#[diag(passes_unused_assign_passed)]
1809#[help]
1810pub(crate) struct UnusedAssignPassed {
1811    pub name: String,
1812}
1813
1814#[derive(LintDiagnostic)]
1815#[diag(passes_unused_variable_try_prefix)]
1816pub(crate) struct UnusedVariableTryPrefix {
1817    #[label]
1818    pub label: Option<Span>,
1819    #[subdiagnostic]
1820    pub string_interp: Vec<UnusedVariableStringInterp>,
1821    #[subdiagnostic]
1822    pub sugg: UnusedVariableSugg,
1823    pub name: String,
1824}
1825
1826#[derive(Subdiagnostic)]
1827pub(crate) enum UnusedVariableSugg {
1828    #[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")]
1829    TryPrefixSugg {
1830        #[suggestion_part(code = "_{name}")]
1831        spans: Vec<Span>,
1832        name: String,
1833    },
1834    #[help(passes_unused_variable_args_in_macro)]
1835    NoSugg {
1836        #[primary_span]
1837        span: Span,
1838        name: String,
1839    },
1840}
1841
1842pub(crate) struct UnusedVariableStringInterp {
1843    pub lit: Span,
1844    pub lo: Span,
1845    pub hi: Span,
1846}
1847
1848impl Subdiagnostic for UnusedVariableStringInterp {
1849    fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
1850        self,
1851        diag: &mut Diag<'_, G>,
1852        _f: &F,
1853    ) {
1854        diag.span_label(self.lit, crate::fluent_generated::passes_maybe_string_interpolation);
1855        diag.multipart_suggestion(
1856            crate::fluent_generated::passes_string_interpolation_only_works,
1857            vec![(self.lo, String::from("format!(")), (self.hi, String::from(")"))],
1858            Applicability::MachineApplicable,
1859        );
1860    }
1861}
1862
1863#[derive(LintDiagnostic)]
1864#[diag(passes_unused_variable_try_ignore)]
1865pub(crate) struct UnusedVarTryIgnore {
1866    #[subdiagnostic]
1867    pub sugg: UnusedVarTryIgnoreSugg,
1868}
1869
1870#[derive(Subdiagnostic)]
1871#[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")]
1872pub(crate) struct UnusedVarTryIgnoreSugg {
1873    #[suggestion_part(code = "{name}: _")]
1874    pub shorthands: Vec<Span>,
1875    #[suggestion_part(code = "_")]
1876    pub non_shorthands: Vec<Span>,
1877    pub name: String,
1878}
1879
1880#[derive(LintDiagnostic)]
1881#[diag(passes_attr_crate_level)]
1882#[note]
1883pub(crate) struct AttrCrateLevelOnly {
1884    #[subdiagnostic]
1885    pub sugg: Option<AttrCrateLevelOnlySugg>,
1886}
1887
1888#[derive(Subdiagnostic)]
1889#[suggestion(passes_suggestion, applicability = "maybe-incorrect", code = "!", style = "verbose")]
1890pub(crate) struct AttrCrateLevelOnlySugg {
1891    #[primary_span]
1892    pub attr: Span,
1893}
1894
1895#[derive(Diagnostic)]
1896#[diag(passes_no_sanitize)]
1897pub(crate) struct NoSanitize<'a> {
1898    #[primary_span]
1899    pub attr_span: Span,
1900    #[label]
1901    pub defn_span: Span,
1902    pub accepted_kind: &'a str,
1903    pub attr_str: &'a str,
1904}