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_conflicting, code = E0566)]
587pub(crate) struct ReprConflicting {
588    #[primary_span]
589    pub hint_spans: Vec<Span>,
590}
591
592#[derive(Diagnostic)]
593#[diag(passes_repr_align_greater_than_target_max, code = E0589)]
594#[note]
595pub(crate) struct InvalidReprAlignForTarget {
596    #[primary_span]
597    pub span: Span,
598    pub size: u64,
599}
600
601#[derive(LintDiagnostic)]
602#[diag(passes_repr_conflicting, code = E0566)]
603pub(crate) struct ReprConflictingLint;
604
605#[derive(Diagnostic)]
606#[diag(passes_used_static)]
607pub(crate) struct UsedStatic {
608    #[primary_span]
609    pub attr_span: Span,
610    #[label]
611    pub span: Span,
612    pub target: &'static str,
613}
614
615#[derive(Diagnostic)]
616#[diag(passes_used_compiler_linker)]
617pub(crate) struct UsedCompilerLinker {
618    #[primary_span]
619    pub spans: Vec<Span>,
620}
621
622#[derive(Diagnostic)]
623#[diag(passes_allow_internal_unstable)]
624pub(crate) struct AllowInternalUnstable {
625    #[primary_span]
626    pub attr_span: Span,
627    #[label]
628    pub span: Span,
629}
630
631#[derive(Diagnostic)]
632#[diag(passes_debug_visualizer_placement)]
633pub(crate) struct DebugVisualizerPlacement {
634    #[primary_span]
635    pub span: Span,
636}
637
638#[derive(Diagnostic)]
639#[diag(passes_debug_visualizer_invalid)]
640#[note(passes_note_1)]
641#[note(passes_note_2)]
642#[note(passes_note_3)]
643pub(crate) struct DebugVisualizerInvalid {
644    #[primary_span]
645    pub span: Span,
646}
647
648#[derive(Diagnostic)]
649#[diag(passes_debug_visualizer_unreadable)]
650pub(crate) struct DebugVisualizerUnreadable<'a> {
651    #[primary_span]
652    pub span: Span,
653    pub file: &'a Path,
654    pub error: Error,
655}
656
657#[derive(Diagnostic)]
658#[diag(passes_rustc_allow_const_fn_unstable)]
659pub(crate) struct RustcAllowConstFnUnstable {
660    #[primary_span]
661    pub attr_span: Span,
662    #[label]
663    pub span: Span,
664}
665
666#[derive(Diagnostic)]
667#[diag(passes_rustc_std_internal_symbol)]
668pub(crate) struct RustcStdInternalSymbol {
669    #[primary_span]
670    pub attr_span: Span,
671    #[label]
672    pub span: Span,
673}
674
675#[derive(Diagnostic)]
676#[diag(passes_rustc_pub_transparent)]
677pub(crate) struct RustcPubTransparent {
678    #[primary_span]
679    pub attr_span: Span,
680    #[label]
681    pub span: Span,
682}
683
684#[derive(Diagnostic)]
685#[diag(passes_rustc_force_inline)]
686pub(crate) struct RustcForceInline {
687    #[primary_span]
688    pub attr_span: Span,
689    #[label]
690    pub span: Span,
691}
692
693#[derive(Diagnostic)]
694#[diag(passes_rustc_force_inline_coro)]
695pub(crate) struct RustcForceInlineCoro {
696    #[primary_span]
697    pub attr_span: Span,
698    #[label]
699    pub span: Span,
700}
701
702#[derive(Diagnostic)]
703#[diag(passes_link_ordinal)]
704pub(crate) struct LinkOrdinal {
705    #[primary_span]
706    pub attr_span: Span,
707}
708
709#[derive(Diagnostic)]
710#[diag(passes_confusables)]
711pub(crate) struct Confusables {
712    #[primary_span]
713    pub attr_span: Span,
714}
715
716#[derive(Diagnostic)]
717#[diag(passes_coroutine_on_non_closure)]
718pub(crate) struct CoroutineOnNonClosure {
719    #[primary_span]
720    pub span: Span,
721}
722
723#[derive(Diagnostic)]
724#[diag(passes_linkage)]
725pub(crate) struct Linkage {
726    #[primary_span]
727    pub attr_span: Span,
728    #[label]
729    pub span: Span,
730}
731
732#[derive(Diagnostic)]
733#[diag(passes_stability_promotable)]
734pub(crate) struct StabilityPromotable {
735    #[primary_span]
736    pub attr_span: Span,
737}
738
739#[derive(LintDiagnostic)]
740#[diag(passes_deprecated)]
741pub(crate) struct Deprecated;
742
743#[derive(LintDiagnostic)]
744#[diag(passes_macro_use)]
745pub(crate) struct MacroUse {
746    pub name: Symbol,
747}
748
749#[derive(LintDiagnostic)]
750pub(crate) enum MacroExport {
751    #[diag(passes_macro_export)]
752    Normal,
753
754    #[diag(passes_macro_export_on_decl_macro)]
755    #[note]
756    OnDeclMacro,
757
758    #[diag(passes_invalid_macro_export_arguments)]
759    UnknownItem { name: Symbol },
760
761    #[diag(passes_invalid_macro_export_arguments_too_many_items)]
762    TooManyItems,
763}
764
765#[derive(Subdiagnostic)]
766pub(crate) enum UnusedNote {
767    #[note(passes_unused_empty_lints_note)]
768    EmptyList { name: Symbol },
769    #[note(passes_unused_no_lints_note)]
770    NoLints { name: Symbol },
771    #[note(passes_unused_default_method_body_const_note)]
772    DefaultMethodBodyConst,
773    #[note(passes_unused_linker_warnings_note)]
774    LinkerWarningsBinaryCrateOnly,
775}
776
777#[derive(LintDiagnostic)]
778#[diag(passes_unused)]
779pub(crate) struct Unused {
780    #[suggestion(code = "", applicability = "machine-applicable")]
781    pub attr_span: Span,
782    #[subdiagnostic]
783    pub note: UnusedNote,
784}
785
786#[derive(Diagnostic)]
787#[diag(passes_non_exported_macro_invalid_attrs, code = E0518)]
788pub(crate) struct NonExportedMacroInvalidAttrs {
789    #[primary_span]
790    #[label]
791    pub attr_span: Span,
792}
793
794#[derive(Diagnostic)]
795#[diag(passes_may_dangle)]
796pub(crate) struct InvalidMayDangle {
797    #[primary_span]
798    pub attr_span: Span,
799}
800
801#[derive(LintDiagnostic)]
802#[diag(passes_unused_duplicate)]
803pub(crate) struct UnusedDuplicate {
804    #[suggestion(code = "", applicability = "machine-applicable")]
805    pub this: Span,
806    #[note]
807    pub other: Span,
808    #[warning]
809    pub warning: bool,
810}
811
812#[derive(Diagnostic)]
813#[diag(passes_unused_multiple)]
814pub(crate) struct UnusedMultiple {
815    #[primary_span]
816    #[suggestion(code = "", applicability = "machine-applicable")]
817    pub this: Span,
818    #[note]
819    pub other: Span,
820    pub name: Symbol,
821}
822
823#[derive(Diagnostic)]
824#[diag(passes_rustc_lint_opt_ty)]
825pub(crate) struct RustcLintOptTy {
826    #[primary_span]
827    pub attr_span: Span,
828    #[label]
829    pub span: Span,
830}
831
832#[derive(Diagnostic)]
833#[diag(passes_rustc_lint_opt_deny_field_access)]
834pub(crate) struct RustcLintOptDenyFieldAccess {
835    #[primary_span]
836    pub attr_span: Span,
837    #[label]
838    pub span: Span,
839}
840
841#[derive(Diagnostic)]
842#[diag(passes_collapse_debuginfo)]
843pub(crate) struct CollapseDebuginfo {
844    #[primary_span]
845    pub attr_span: Span,
846    #[label]
847    pub defn_span: Span,
848}
849
850#[derive(LintDiagnostic)]
851#[diag(passes_deprecated_annotation_has_no_effect)]
852pub(crate) struct DeprecatedAnnotationHasNoEffect {
853    #[suggestion(applicability = "machine-applicable", code = "")]
854    pub span: Span,
855}
856
857#[derive(Diagnostic)]
858#[diag(passes_unknown_external_lang_item, code = E0264)]
859pub(crate) struct UnknownExternLangItem {
860    #[primary_span]
861    pub span: Span,
862    pub lang_item: Symbol,
863}
864
865#[derive(Diagnostic)]
866#[diag(passes_missing_panic_handler)]
867pub(crate) struct MissingPanicHandler;
868
869#[derive(Diagnostic)]
870#[diag(passes_panic_unwind_without_std)]
871#[help]
872#[note]
873pub(crate) struct PanicUnwindWithoutStd;
874
875#[derive(Diagnostic)]
876#[diag(passes_missing_lang_item)]
877#[note]
878#[help]
879pub(crate) struct MissingLangItem {
880    pub name: Symbol,
881}
882
883#[derive(Diagnostic)]
884#[diag(passes_lang_item_fn_with_track_caller)]
885pub(crate) struct LangItemWithTrackCaller {
886    #[primary_span]
887    pub attr_span: Span,
888    pub name: Symbol,
889    #[label]
890    pub sig_span: Span,
891}
892
893#[derive(Diagnostic)]
894#[diag(passes_lang_item_fn_with_target_feature)]
895pub(crate) struct LangItemWithTargetFeature {
896    #[primary_span]
897    pub attr_span: Span,
898    pub name: Symbol,
899    #[label]
900    pub sig_span: Span,
901}
902
903#[derive(Diagnostic)]
904#[diag(passes_lang_item_on_incorrect_target, code = E0718)]
905pub(crate) struct LangItemOnIncorrectTarget {
906    #[primary_span]
907    #[label]
908    pub span: Span,
909    pub name: Symbol,
910    pub expected_target: Target,
911    pub actual_target: Target,
912}
913
914#[derive(Diagnostic)]
915#[diag(passes_unknown_lang_item, code = E0522)]
916pub(crate) struct UnknownLangItem {
917    #[primary_span]
918    #[label]
919    pub span: Span,
920    pub name: Symbol,
921}
922
923pub(crate) struct InvalidAttrAtCrateLevel {
924    pub span: Span,
925    pub sugg_span: Option<Span>,
926    pub name: Symbol,
927    pub item: Option<ItemFollowingInnerAttr>,
928}
929
930#[derive(Clone, Copy)]
931pub(crate) struct ItemFollowingInnerAttr {
932    pub span: Span,
933    pub kind: &'static str,
934}
935
936impl<G: EmissionGuarantee> Diagnostic<'_, G> for InvalidAttrAtCrateLevel {
937    #[track_caller]
938    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
939        let mut diag = Diag::new(dcx, level, fluent::passes_invalid_attr_at_crate_level);
940        diag.span(self.span);
941        diag.arg("name", self.name);
942        // Only emit an error with a suggestion if we can create a string out
943        // of the attribute span
944        if let Some(span) = self.sugg_span {
945            diag.span_suggestion_verbose(
946                span,
947                fluent::passes_suggestion,
948                String::new(),
949                Applicability::MachineApplicable,
950            );
951        }
952        if let Some(item) = self.item {
953            diag.arg("kind", item.kind);
954            diag.span_label(item.span, fluent::passes_invalid_attr_at_crate_level_item);
955        }
956        diag
957    }
958}
959
960#[derive(Diagnostic)]
961#[diag(passes_duplicate_diagnostic_item_in_crate)]
962pub(crate) struct DuplicateDiagnosticItemInCrate {
963    #[primary_span]
964    pub duplicate_span: Option<Span>,
965    #[note(passes_diagnostic_item_first_defined)]
966    pub orig_span: Option<Span>,
967    #[note]
968    pub different_crates: bool,
969    pub crate_name: Symbol,
970    pub orig_crate_name: Symbol,
971    pub name: Symbol,
972}
973
974#[derive(Diagnostic)]
975#[diag(passes_layout_abi)]
976pub(crate) struct LayoutAbi {
977    #[primary_span]
978    pub span: Span,
979    pub abi: String,
980}
981
982#[derive(Diagnostic)]
983#[diag(passes_layout_align)]
984pub(crate) struct LayoutAlign {
985    #[primary_span]
986    pub span: Span,
987    pub align: String,
988}
989
990#[derive(Diagnostic)]
991#[diag(passes_layout_size)]
992pub(crate) struct LayoutSize {
993    #[primary_span]
994    pub span: Span,
995    pub size: String,
996}
997
998#[derive(Diagnostic)]
999#[diag(passes_layout_homogeneous_aggregate)]
1000pub(crate) struct LayoutHomogeneousAggregate {
1001    #[primary_span]
1002    pub span: Span,
1003    pub homogeneous_aggregate: String,
1004}
1005
1006#[derive(Diagnostic)]
1007#[diag(passes_layout_of)]
1008pub(crate) struct LayoutOf<'tcx> {
1009    #[primary_span]
1010    pub span: Span,
1011    pub normalized_ty: Ty<'tcx>,
1012    pub ty_layout: String,
1013}
1014
1015#[derive(Diagnostic)]
1016#[diag(passes_layout_invalid_attribute)]
1017pub(crate) struct LayoutInvalidAttribute {
1018    #[primary_span]
1019    pub span: Span,
1020}
1021
1022#[derive(Diagnostic)]
1023#[diag(passes_abi_of)]
1024pub(crate) struct AbiOf {
1025    #[primary_span]
1026    pub span: Span,
1027    pub fn_name: Symbol,
1028    pub fn_abi: String,
1029}
1030
1031#[derive(Diagnostic)]
1032#[diag(passes_abi_ne)]
1033pub(crate) struct AbiNe {
1034    #[primary_span]
1035    pub span: Span,
1036    pub left: String,
1037    pub right: String,
1038}
1039
1040#[derive(Diagnostic)]
1041#[diag(passes_abi_invalid_attribute)]
1042pub(crate) struct AbiInvalidAttribute {
1043    #[primary_span]
1044    pub span: Span,
1045}
1046
1047#[derive(Diagnostic)]
1048#[diag(passes_unrecognized_field)]
1049pub(crate) struct UnrecognizedField {
1050    #[primary_span]
1051    pub span: Span,
1052    pub name: Symbol,
1053}
1054
1055#[derive(Diagnostic)]
1056#[diag(passes_feature_stable_twice, code = E0711)]
1057pub(crate) struct FeatureStableTwice {
1058    #[primary_span]
1059    pub span: Span,
1060    pub feature: Symbol,
1061    pub since: Symbol,
1062    pub prev_since: Symbol,
1063}
1064
1065#[derive(Diagnostic)]
1066#[diag(passes_feature_previously_declared, code = E0711)]
1067pub(crate) struct FeaturePreviouslyDeclared<'a> {
1068    #[primary_span]
1069    pub span: Span,
1070    pub feature: Symbol,
1071    pub declared: &'a str,
1072    pub prev_declared: &'a str,
1073}
1074
1075pub(crate) struct BreakNonLoop<'a> {
1076    pub span: Span,
1077    pub head: Option<Span>,
1078    pub kind: &'a str,
1079    pub suggestion: String,
1080    pub loop_label: Option<Label>,
1081    pub break_label: Option<Label>,
1082    pub break_expr_kind: &'a ExprKind<'a>,
1083    pub break_expr_span: Span,
1084}
1085
1086impl<'a, G: EmissionGuarantee> Diagnostic<'_, G> for BreakNonLoop<'a> {
1087    #[track_caller]
1088    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1089        let mut diag = Diag::new(dcx, level, fluent::passes_break_non_loop);
1090        diag.span(self.span);
1091        diag.code(E0571);
1092        diag.arg("kind", self.kind);
1093        diag.span_label(self.span, fluent::passes_label);
1094        if let Some(head) = self.head {
1095            diag.span_label(head, fluent::passes_label2);
1096        }
1097        diag.span_suggestion(
1098            self.span,
1099            fluent::passes_suggestion,
1100            self.suggestion,
1101            Applicability::MaybeIncorrect,
1102        );
1103        if let (Some(label), None) = (self.loop_label, self.break_label) {
1104            match self.break_expr_kind {
1105                ExprKind::Path(hir::QPath::Resolved(
1106                    None,
1107                    hir::Path { segments: [segment], res: hir::def::Res::Err, .. },
1108                )) if label.ident.to_string() == format!("'{}", segment.ident) => {
1109                    // This error is redundant, we will have already emitted a
1110                    // suggestion to use the label when `segment` wasn't found
1111                    // (hence the `Res::Err` check).
1112                    diag.downgrade_to_delayed_bug();
1113                }
1114                _ => {
1115                    diag.span_suggestion(
1116                        self.break_expr_span,
1117                        fluent::passes_break_expr_suggestion,
1118                        label.ident,
1119                        Applicability::MaybeIncorrect,
1120                    );
1121                }
1122            }
1123        }
1124        diag
1125    }
1126}
1127
1128#[derive(Diagnostic)]
1129#[diag(passes_continue_labeled_block, code = E0696)]
1130pub(crate) struct ContinueLabeledBlock {
1131    #[primary_span]
1132    #[label]
1133    pub span: Span,
1134    #[label(passes_block_label)]
1135    pub block_span: Span,
1136}
1137
1138#[derive(Diagnostic)]
1139#[diag(passes_break_inside_closure, code = E0267)]
1140pub(crate) struct BreakInsideClosure<'a> {
1141    #[primary_span]
1142    #[label]
1143    pub span: Span,
1144    #[label(passes_closure_label)]
1145    pub closure_span: Span,
1146    pub name: &'a str,
1147}
1148
1149#[derive(Diagnostic)]
1150#[diag(passes_break_inside_coroutine, code = E0267)]
1151pub(crate) struct BreakInsideCoroutine<'a> {
1152    #[primary_span]
1153    #[label]
1154    pub span: Span,
1155    #[label(passes_coroutine_label)]
1156    pub coroutine_span: Span,
1157    pub name: &'a str,
1158    pub kind: &'a str,
1159    pub source: &'a str,
1160}
1161
1162#[derive(Diagnostic)]
1163#[diag(passes_outside_loop, code = E0268)]
1164pub(crate) struct OutsideLoop<'a> {
1165    #[primary_span]
1166    #[label]
1167    pub spans: Vec<Span>,
1168    pub name: &'a str,
1169    pub is_break: bool,
1170    #[subdiagnostic]
1171    pub suggestion: Option<OutsideLoopSuggestion>,
1172}
1173#[derive(Subdiagnostic)]
1174#[multipart_suggestion(passes_outside_loop_suggestion, applicability = "maybe-incorrect")]
1175pub(crate) struct OutsideLoopSuggestion {
1176    #[suggestion_part(code = "'block: ")]
1177    pub block_span: Span,
1178    #[suggestion_part(code = " 'block")]
1179    pub break_spans: Vec<Span>,
1180}
1181
1182#[derive(Diagnostic)]
1183#[diag(passes_unlabeled_in_labeled_block, code = E0695)]
1184pub(crate) struct UnlabeledInLabeledBlock<'a> {
1185    #[primary_span]
1186    #[label]
1187    pub span: Span,
1188    pub cf_type: &'a str,
1189}
1190
1191#[derive(Diagnostic)]
1192#[diag(passes_unlabeled_cf_in_while_condition, code = E0590)]
1193pub(crate) struct UnlabeledCfInWhileCondition<'a> {
1194    #[primary_span]
1195    #[label]
1196    pub span: Span,
1197    pub cf_type: &'a str,
1198}
1199
1200#[derive(LintDiagnostic)]
1201#[diag(passes_undefined_naked_function_abi)]
1202pub(crate) struct UndefinedNakedFunctionAbi;
1203
1204#[derive(Diagnostic)]
1205#[diag(passes_no_patterns)]
1206pub(crate) struct NoPatterns {
1207    #[primary_span]
1208    pub span: Span,
1209}
1210
1211#[derive(Diagnostic)]
1212#[diag(passes_params_not_allowed)]
1213#[help]
1214pub(crate) struct ParamsNotAllowed {
1215    #[primary_span]
1216    pub span: Span,
1217}
1218
1219pub(crate) struct NakedFunctionsAsmBlock {
1220    pub span: Span,
1221    pub multiple_asms: Vec<Span>,
1222    pub non_asms: Vec<Span>,
1223}
1224
1225impl<G: EmissionGuarantee> Diagnostic<'_, G> for NakedFunctionsAsmBlock {
1226    #[track_caller]
1227    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1228        let mut diag = Diag::new(dcx, level, fluent::passes_naked_functions_asm_block);
1229        diag.span(self.span);
1230        diag.code(E0787);
1231        for span in self.multiple_asms.iter() {
1232            diag.span_label(*span, fluent::passes_label_multiple_asm);
1233        }
1234        for span in self.non_asms.iter() {
1235            diag.span_label(*span, fluent::passes_label_non_asm);
1236        }
1237        diag
1238    }
1239}
1240
1241#[derive(Diagnostic)]
1242#[diag(passes_naked_functions_must_naked_asm, code = E0787)]
1243pub(crate) struct NakedFunctionsMustNakedAsm {
1244    #[primary_span]
1245    #[label]
1246    pub span: Span,
1247}
1248
1249#[derive(Diagnostic)]
1250#[diag(passes_naked_functions_incompatible_attribute, code = E0736)]
1251pub(crate) struct NakedFunctionIncompatibleAttribute {
1252    #[primary_span]
1253    #[label]
1254    pub span: Span,
1255    #[label(passes_naked_attribute)]
1256    pub naked_span: Span,
1257    pub attr: Symbol,
1258}
1259
1260#[derive(Diagnostic)]
1261#[diag(passes_naked_asm_outside_naked_fn)]
1262pub(crate) struct NakedAsmOutsideNakedFn {
1263    #[primary_span]
1264    pub span: Span,
1265}
1266
1267#[derive(Diagnostic)]
1268#[diag(passes_attr_only_in_functions)]
1269pub(crate) struct AttrOnlyInFunctions {
1270    #[primary_span]
1271    pub span: Span,
1272    pub attr: Symbol,
1273}
1274
1275#[derive(Diagnostic)]
1276#[diag(passes_multiple_rustc_main, code = E0137)]
1277pub(crate) struct MultipleRustcMain {
1278    #[primary_span]
1279    pub span: Span,
1280    #[label(passes_first)]
1281    pub first: Span,
1282    #[label(passes_additional)]
1283    pub additional: Span,
1284}
1285
1286#[derive(Diagnostic)]
1287#[diag(passes_extern_main)]
1288pub(crate) struct ExternMain {
1289    #[primary_span]
1290    pub span: Span,
1291}
1292
1293pub(crate) struct NoMainErr {
1294    pub sp: Span,
1295    pub crate_name: Symbol,
1296    pub has_filename: bool,
1297    pub filename: PathBuf,
1298    pub file_empty: bool,
1299    pub non_main_fns: Vec<Span>,
1300    pub main_def_opt: Option<MainDefinition>,
1301    pub add_teach_note: bool,
1302}
1303
1304impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NoMainErr {
1305    #[track_caller]
1306    fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
1307        let mut diag = Diag::new(dcx, level, fluent::passes_no_main_function);
1308        diag.span(DUMMY_SP);
1309        diag.code(E0601);
1310        diag.arg("crate_name", self.crate_name);
1311        diag.arg("filename", self.filename);
1312        diag.arg("has_filename", self.has_filename);
1313        let note = if !self.non_main_fns.is_empty() {
1314            for &span in &self.non_main_fns {
1315                diag.span_note(span, fluent::passes_here_is_main);
1316            }
1317            diag.note(fluent::passes_one_or_more_possible_main);
1318            diag.help(fluent::passes_consider_moving_main);
1319            // There were some functions named `main` though. Try to give the user a hint.
1320            fluent::passes_main_must_be_defined_at_crate
1321        } else if self.has_filename {
1322            fluent::passes_consider_adding_main_to_file
1323        } else {
1324            fluent::passes_consider_adding_main_at_crate
1325        };
1326        if self.file_empty {
1327            diag.note(note);
1328        } else {
1329            diag.span(self.sp.shrink_to_hi());
1330            diag.span_label(self.sp.shrink_to_hi(), note);
1331        }
1332
1333        if let Some(main_def) = self.main_def_opt
1334            && main_def.opt_fn_def_id().is_none()
1335        {
1336            // There is something at `crate::main`, but it is not a function definition.
1337            diag.span_label(main_def.span, fluent::passes_non_function_main);
1338        }
1339
1340        if self.add_teach_note {
1341            diag.note(fluent::passes_teach_note);
1342        }
1343        diag
1344    }
1345}
1346
1347pub(crate) struct DuplicateLangItem {
1348    pub local_span: Option<Span>,
1349    pub lang_item_name: Symbol,
1350    pub crate_name: Symbol,
1351    pub dependency_of: Symbol,
1352    pub is_local: bool,
1353    pub path: String,
1354    pub first_defined_span: Option<Span>,
1355    pub orig_crate_name: Symbol,
1356    pub orig_dependency_of: Symbol,
1357    pub orig_is_local: bool,
1358    pub orig_path: String,
1359    pub(crate) duplicate: Duplicate,
1360}
1361
1362impl<G: EmissionGuarantee> Diagnostic<'_, G> for DuplicateLangItem {
1363    #[track_caller]
1364    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1365        let mut diag = Diag::new(
1366            dcx,
1367            level,
1368            match self.duplicate {
1369                Duplicate::Plain => fluent::passes_duplicate_lang_item,
1370                Duplicate::Crate => fluent::passes_duplicate_lang_item_crate,
1371                Duplicate::CrateDepends => fluent::passes_duplicate_lang_item_crate_depends,
1372            },
1373        );
1374        diag.code(E0152);
1375        diag.arg("lang_item_name", self.lang_item_name);
1376        diag.arg("crate_name", self.crate_name);
1377        diag.arg("dependency_of", self.dependency_of);
1378        diag.arg("path", self.path);
1379        diag.arg("orig_crate_name", self.orig_crate_name);
1380        diag.arg("orig_dependency_of", self.orig_dependency_of);
1381        diag.arg("orig_path", self.orig_path);
1382        if let Some(span) = self.local_span {
1383            diag.span(span);
1384        }
1385        if let Some(span) = self.first_defined_span {
1386            diag.span_note(span, fluent::passes_first_defined_span);
1387        } else {
1388            if self.orig_dependency_of.is_empty() {
1389                diag.note(fluent::passes_first_defined_crate);
1390            } else {
1391                diag.note(fluent::passes_first_defined_crate_depends);
1392            }
1393
1394            if self.orig_is_local {
1395                diag.note(fluent::passes_first_definition_local);
1396            } else {
1397                diag.note(fluent::passes_first_definition_path);
1398            }
1399
1400            if self.is_local {
1401                diag.note(fluent::passes_second_definition_local);
1402            } else {
1403                diag.note(fluent::passes_second_definition_path);
1404            }
1405        }
1406        diag
1407    }
1408}
1409
1410#[derive(Diagnostic)]
1411#[diag(passes_incorrect_target, code = E0718)]
1412pub(crate) struct IncorrectTarget<'a> {
1413    #[primary_span]
1414    pub span: Span,
1415    #[label]
1416    pub generics_span: Span,
1417    pub name: &'a str, // cannot be symbol because it renders e.g. `r#fn` instead of `fn`
1418    pub kind: &'static str,
1419    pub num: usize,
1420    pub actual_num: usize,
1421    pub at_least: bool,
1422}
1423
1424#[derive(LintDiagnostic)]
1425#[diag(passes_useless_assignment)]
1426pub(crate) struct UselessAssignment<'a> {
1427    pub is_field_assign: bool,
1428    pub ty: Ty<'a>,
1429}
1430
1431#[derive(LintDiagnostic)]
1432#[diag(passes_only_has_effect_on)]
1433pub(crate) struct OnlyHasEffectOn {
1434    pub attr_name: Symbol,
1435    pub target_name: String,
1436}
1437
1438#[derive(Diagnostic)]
1439#[diag(passes_object_lifetime_err)]
1440pub(crate) struct ObjectLifetimeErr {
1441    #[primary_span]
1442    pub span: Span,
1443    pub repr: String,
1444}
1445
1446#[derive(Diagnostic)]
1447pub(crate) enum AttrApplication {
1448    #[diag(passes_attr_application_enum, code = E0517)]
1449    Enum {
1450        #[primary_span]
1451        hint_span: Span,
1452        #[label]
1453        span: Span,
1454    },
1455    #[diag(passes_attr_application_struct, code = E0517)]
1456    Struct {
1457        #[primary_span]
1458        hint_span: Span,
1459        #[label]
1460        span: Span,
1461    },
1462    #[diag(passes_attr_application_struct_union, code = E0517)]
1463    StructUnion {
1464        #[primary_span]
1465        hint_span: Span,
1466        #[label]
1467        span: Span,
1468    },
1469    #[diag(passes_attr_application_struct_enum_union, code = E0517)]
1470    StructEnumUnion {
1471        #[primary_span]
1472        hint_span: Span,
1473        #[label]
1474        span: Span,
1475    },
1476    #[diag(passes_attr_application_struct_enum_function_method_union, code = E0517)]
1477    StructEnumFunctionMethodUnion {
1478        #[primary_span]
1479        hint_span: Span,
1480        #[label]
1481        span: Span,
1482    },
1483}
1484
1485#[derive(Diagnostic)]
1486#[diag(passes_transparent_incompatible, code = E0692)]
1487pub(crate) struct TransparentIncompatible {
1488    #[primary_span]
1489    pub hint_spans: Vec<Span>,
1490    pub target: String,
1491}
1492
1493#[derive(Diagnostic)]
1494#[diag(passes_deprecated_attribute, code = E0549)]
1495pub(crate) struct DeprecatedAttribute {
1496    #[primary_span]
1497    pub span: Span,
1498}
1499
1500#[derive(Diagnostic)]
1501#[diag(passes_useless_stability)]
1502pub(crate) struct UselessStability {
1503    #[primary_span]
1504    #[label]
1505    pub span: Span,
1506    #[label(passes_item)]
1507    pub item_sp: Span,
1508}
1509
1510#[derive(Diagnostic)]
1511#[diag(passes_cannot_stabilize_deprecated)]
1512pub(crate) struct CannotStabilizeDeprecated {
1513    #[primary_span]
1514    #[label]
1515    pub span: Span,
1516    #[label(passes_item)]
1517    pub item_sp: Span,
1518}
1519
1520#[derive(Diagnostic)]
1521#[diag(passes_unstable_attr_for_already_stable_feature)]
1522pub(crate) struct UnstableAttrForAlreadyStableFeature {
1523    #[primary_span]
1524    #[label]
1525    #[help]
1526    pub span: Span,
1527    #[label(passes_item)]
1528    pub item_sp: Span,
1529}
1530
1531#[derive(Diagnostic)]
1532#[diag(passes_missing_stability_attr)]
1533pub(crate) struct MissingStabilityAttr<'a> {
1534    #[primary_span]
1535    pub span: Span,
1536    pub descr: &'a str,
1537}
1538
1539#[derive(Diagnostic)]
1540#[diag(passes_missing_const_stab_attr)]
1541pub(crate) struct MissingConstStabAttr<'a> {
1542    #[primary_span]
1543    pub span: Span,
1544    pub descr: &'a str,
1545}
1546
1547#[derive(Diagnostic)]
1548#[diag(passes_trait_impl_const_stable)]
1549#[note]
1550pub(crate) struct TraitImplConstStable {
1551    #[primary_span]
1552    pub span: Span,
1553}
1554
1555#[derive(Diagnostic)]
1556#[diag(passes_trait_impl_const_stability_mismatch)]
1557pub(crate) struct TraitImplConstStabilityMismatch {
1558    #[primary_span]
1559    pub span: Span,
1560    #[subdiagnostic]
1561    pub impl_stability: ImplConstStability,
1562    #[subdiagnostic]
1563    pub trait_stability: TraitConstStability,
1564}
1565
1566#[derive(Subdiagnostic)]
1567pub(crate) enum TraitConstStability {
1568    #[note(passes_trait_impl_const_stability_mismatch_trait_stable)]
1569    Stable {
1570        #[primary_span]
1571        span: Span,
1572    },
1573    #[note(passes_trait_impl_const_stability_mismatch_trait_unstable)]
1574    Unstable {
1575        #[primary_span]
1576        span: Span,
1577    },
1578}
1579
1580#[derive(Subdiagnostic)]
1581pub(crate) enum ImplConstStability {
1582    #[note(passes_trait_impl_const_stability_mismatch_impl_stable)]
1583    Stable {
1584        #[primary_span]
1585        span: Span,
1586    },
1587    #[note(passes_trait_impl_const_stability_mismatch_impl_unstable)]
1588    Unstable {
1589        #[primary_span]
1590        span: Span,
1591    },
1592}
1593
1594#[derive(Diagnostic)]
1595#[diag(passes_unknown_feature, code = E0635)]
1596pub(crate) struct UnknownFeature {
1597    #[primary_span]
1598    pub span: Span,
1599    pub feature: Symbol,
1600}
1601
1602#[derive(Diagnostic)]
1603#[diag(passes_implied_feature_not_exist)]
1604pub(crate) struct ImpliedFeatureNotExist {
1605    #[primary_span]
1606    pub span: Span,
1607    pub feature: Symbol,
1608    pub implied_by: Symbol,
1609}
1610
1611#[derive(Diagnostic)]
1612#[diag(passes_duplicate_feature_err, code = E0636)]
1613pub(crate) struct DuplicateFeatureErr {
1614    #[primary_span]
1615    pub span: Span,
1616    pub feature: Symbol,
1617}
1618
1619#[derive(Diagnostic)]
1620#[diag(passes_missing_const_err)]
1621pub(crate) struct MissingConstErr {
1622    #[primary_span]
1623    #[help]
1624    pub fn_sig_span: Span,
1625}
1626
1627#[derive(Diagnostic)]
1628#[diag(passes_const_stable_not_stable)]
1629pub(crate) struct ConstStableNotStable {
1630    #[primary_span]
1631    pub fn_sig_span: Span,
1632    #[label]
1633    pub const_span: Span,
1634}
1635
1636#[derive(LintDiagnostic)]
1637pub(crate) enum MultipleDeadCodes<'tcx> {
1638    #[diag(passes_dead_codes)]
1639    DeadCodes {
1640        multiple: bool,
1641        num: usize,
1642        descr: &'tcx str,
1643        participle: &'tcx str,
1644        name_list: DiagSymbolList,
1645        #[subdiagnostic]
1646        parent_info: Option<ParentInfo<'tcx>>,
1647        #[subdiagnostic]
1648        ignored_derived_impls: Option<IgnoredDerivedImpls>,
1649    },
1650    #[diag(passes_dead_codes)]
1651    UnusedTupleStructFields {
1652        multiple: bool,
1653        num: usize,
1654        descr: &'tcx str,
1655        participle: &'tcx str,
1656        name_list: DiagSymbolList,
1657        #[subdiagnostic]
1658        change_fields_suggestion: ChangeFields,
1659        #[subdiagnostic]
1660        parent_info: Option<ParentInfo<'tcx>>,
1661        #[subdiagnostic]
1662        ignored_derived_impls: Option<IgnoredDerivedImpls>,
1663    },
1664}
1665
1666#[derive(Subdiagnostic)]
1667#[label(passes_parent_info)]
1668pub(crate) struct ParentInfo<'tcx> {
1669    pub num: usize,
1670    pub descr: &'tcx str,
1671    pub parent_descr: &'tcx str,
1672    #[primary_span]
1673    pub span: Span,
1674}
1675
1676#[derive(Subdiagnostic)]
1677#[note(passes_ignored_derived_impls)]
1678pub(crate) struct IgnoredDerivedImpls {
1679    pub name: Symbol,
1680    pub trait_list: DiagSymbolList,
1681    pub trait_list_len: usize,
1682}
1683
1684#[derive(Subdiagnostic)]
1685pub(crate) enum ChangeFields {
1686    #[multipart_suggestion(
1687        passes_change_fields_to_be_of_unit_type,
1688        applicability = "has-placeholders"
1689    )]
1690    ChangeToUnitTypeOrRemove {
1691        num: usize,
1692        #[suggestion_part(code = "()")]
1693        spans: Vec<Span>,
1694    },
1695    #[help(passes_remove_fields)]
1696    Remove { num: usize },
1697}
1698
1699#[derive(Diagnostic)]
1700#[diag(passes_proc_macro_bad_sig)]
1701pub(crate) struct ProcMacroBadSig {
1702    #[primary_span]
1703    pub span: Span,
1704    pub kind: ProcMacroKind,
1705}
1706
1707#[derive(LintDiagnostic)]
1708#[diag(passes_unreachable_due_to_uninhabited)]
1709pub(crate) struct UnreachableDueToUninhabited<'desc, 'tcx> {
1710    pub descr: &'desc str,
1711    #[label]
1712    pub expr: Span,
1713    #[label(passes_label_orig)]
1714    #[note]
1715    pub orig: Span,
1716    pub ty: Ty<'tcx>,
1717}
1718
1719#[derive(LintDiagnostic)]
1720#[diag(passes_unused_var_maybe_capture_ref)]
1721#[help]
1722pub(crate) struct UnusedVarMaybeCaptureRef {
1723    pub name: String,
1724}
1725
1726#[derive(LintDiagnostic)]
1727#[diag(passes_unused_capture_maybe_capture_ref)]
1728#[help]
1729pub(crate) struct UnusedCaptureMaybeCaptureRef {
1730    pub name: String,
1731}
1732
1733#[derive(LintDiagnostic)]
1734#[diag(passes_unused_var_remove_field)]
1735pub(crate) struct UnusedVarRemoveField {
1736    pub name: String,
1737    #[subdiagnostic]
1738    pub sugg: UnusedVarRemoveFieldSugg,
1739}
1740
1741#[derive(Subdiagnostic)]
1742#[multipart_suggestion(
1743    passes_unused_var_remove_field_suggestion,
1744    applicability = "machine-applicable"
1745)]
1746pub(crate) struct UnusedVarRemoveFieldSugg {
1747    #[suggestion_part(code = "")]
1748    pub spans: Vec<Span>,
1749}
1750
1751#[derive(LintDiagnostic)]
1752#[diag(passes_unused_var_assigned_only)]
1753#[note]
1754pub(crate) struct UnusedVarAssignedOnly {
1755    pub name: String,
1756}
1757
1758#[derive(LintDiagnostic)]
1759#[diag(passes_unnecessary_stable_feature)]
1760pub(crate) struct UnnecessaryStableFeature {
1761    pub feature: Symbol,
1762    pub since: Symbol,
1763}
1764
1765#[derive(LintDiagnostic)]
1766#[diag(passes_unnecessary_partial_stable_feature)]
1767pub(crate) struct UnnecessaryPartialStableFeature {
1768    #[suggestion(code = "{implies}", applicability = "maybe-incorrect")]
1769    pub span: Span,
1770    #[suggestion(passes_suggestion_remove, code = "", applicability = "maybe-incorrect")]
1771    pub line: Span,
1772    pub feature: Symbol,
1773    pub since: Symbol,
1774    pub implies: Symbol,
1775}
1776
1777#[derive(LintDiagnostic)]
1778#[diag(passes_ineffective_unstable_impl)]
1779#[note]
1780pub(crate) struct IneffectiveUnstableImpl;
1781
1782#[derive(LintDiagnostic)]
1783#[diag(passes_unused_assign)]
1784pub(crate) struct UnusedAssign {
1785    pub name: String,
1786    #[subdiagnostic]
1787    pub suggestion: Option<UnusedAssignSuggestion>,
1788    #[help]
1789    pub help: bool,
1790}
1791
1792#[derive(Subdiagnostic)]
1793#[multipart_suggestion(passes_unused_assign_suggestion, applicability = "maybe-incorrect")]
1794pub(crate) struct UnusedAssignSuggestion {
1795    pub pre: &'static str,
1796    #[suggestion_part(code = "{pre}mut ")]
1797    pub ty_span: Option<Span>,
1798    #[suggestion_part(code = "")]
1799    pub ty_ref_span: Span,
1800    #[suggestion_part(code = "*")]
1801    pub ident_span: Span,
1802    #[suggestion_part(code = "")]
1803    pub expr_ref_span: Span,
1804}
1805
1806#[derive(LintDiagnostic)]
1807#[diag(passes_unused_assign_passed)]
1808#[help]
1809pub(crate) struct UnusedAssignPassed {
1810    pub name: String,
1811}
1812
1813#[derive(LintDiagnostic)]
1814#[diag(passes_unused_variable_try_prefix)]
1815pub(crate) struct UnusedVariableTryPrefix {
1816    #[label]
1817    pub label: Option<Span>,
1818    #[subdiagnostic]
1819    pub string_interp: Vec<UnusedVariableStringInterp>,
1820    #[subdiagnostic]
1821    pub sugg: UnusedVariableSugg,
1822    pub name: String,
1823}
1824
1825#[derive(Subdiagnostic)]
1826pub(crate) enum UnusedVariableSugg {
1827    #[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")]
1828    TryPrefixSugg {
1829        #[suggestion_part(code = "_{name}")]
1830        spans: Vec<Span>,
1831        name: String,
1832    },
1833    #[help(passes_unused_variable_args_in_macro)]
1834    NoSugg {
1835        #[primary_span]
1836        span: Span,
1837        name: String,
1838    },
1839}
1840
1841pub(crate) struct UnusedVariableStringInterp {
1842    pub lit: Span,
1843    pub lo: Span,
1844    pub hi: Span,
1845}
1846
1847impl Subdiagnostic for UnusedVariableStringInterp {
1848    fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
1849        self,
1850        diag: &mut Diag<'_, G>,
1851        _f: &F,
1852    ) {
1853        diag.span_label(self.lit, crate::fluent_generated::passes_maybe_string_interpolation);
1854        diag.multipart_suggestion(
1855            crate::fluent_generated::passes_string_interpolation_only_works,
1856            vec![(self.lo, String::from("format!(")), (self.hi, String::from(")"))],
1857            Applicability::MachineApplicable,
1858        );
1859    }
1860}
1861
1862#[derive(LintDiagnostic)]
1863#[diag(passes_unused_variable_try_ignore)]
1864pub(crate) struct UnusedVarTryIgnore {
1865    #[subdiagnostic]
1866    pub sugg: UnusedVarTryIgnoreSugg,
1867}
1868
1869#[derive(Subdiagnostic)]
1870#[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")]
1871pub(crate) struct UnusedVarTryIgnoreSugg {
1872    #[suggestion_part(code = "{name}: _")]
1873    pub shorthands: Vec<Span>,
1874    #[suggestion_part(code = "_")]
1875    pub non_shorthands: Vec<Span>,
1876    pub name: String,
1877}
1878
1879#[derive(LintDiagnostic)]
1880#[diag(passes_attr_crate_level)]
1881#[note]
1882pub(crate) struct AttrCrateLevelOnly {
1883    #[subdiagnostic]
1884    pub sugg: Option<AttrCrateLevelOnlySugg>,
1885}
1886
1887#[derive(Subdiagnostic)]
1888#[suggestion(passes_suggestion, applicability = "maybe-incorrect", code = "!", style = "verbose")]
1889pub(crate) struct AttrCrateLevelOnlySugg {
1890    #[primary_span]
1891    pub attr: Span,
1892}
1893
1894#[derive(Diagnostic)]
1895#[diag(passes_no_sanitize)]
1896pub(crate) struct NoSanitize<'a> {
1897    #[primary_span]
1898    pub attr_span: Span,
1899    #[label]
1900    pub defn_span: Span,
1901    pub accepted_kind: &'a str,
1902    pub attr_str: &'a str,
1903}
1904
1905// FIXME(jdonszelmann): move back to rustc_attr
1906#[derive(Diagnostic)]
1907#[diag(passes_rustc_const_stable_indirect_pairing)]
1908pub(crate) struct RustcConstStableIndirectPairing {
1909    #[primary_span]
1910    pub span: Span,
1911}
1912
1913#[derive(Diagnostic)]
1914#[diag(passes_unsupported_attributes_in_where)]
1915#[help]
1916pub(crate) struct UnsupportedAttributesInWhere {
1917    #[primary_span]
1918    pub span: MultiSpan,
1919}