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, 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    InvalidArgument,
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_messages_note)]
774    LinkerMessagesBinaryCrateOnly,
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_argument)]
1049pub(crate) struct UnrecognizedArgument {
1050    #[primary_span]
1051    pub span: Span,
1052}
1053
1054#[derive(Diagnostic)]
1055#[diag(passes_feature_stable_twice, code = E0711)]
1056pub(crate) struct FeatureStableTwice {
1057    #[primary_span]
1058    pub span: Span,
1059    pub feature: Symbol,
1060    pub since: Symbol,
1061    pub prev_since: Symbol,
1062}
1063
1064#[derive(Diagnostic)]
1065#[diag(passes_feature_previously_declared, code = E0711)]
1066pub(crate) struct FeaturePreviouslyDeclared<'a> {
1067    #[primary_span]
1068    pub span: Span,
1069    pub feature: Symbol,
1070    pub declared: &'a str,
1071    pub prev_declared: &'a str,
1072}
1073
1074pub(crate) struct BreakNonLoop<'a> {
1075    pub span: Span,
1076    pub head: Option<Span>,
1077    pub kind: &'a str,
1078    pub suggestion: String,
1079    pub loop_label: Option<Label>,
1080    pub break_label: Option<Label>,
1081    pub break_expr_kind: &'a ExprKind<'a>,
1082    pub break_expr_span: Span,
1083}
1084
1085impl<'a, G: EmissionGuarantee> Diagnostic<'_, G> for BreakNonLoop<'a> {
1086    #[track_caller]
1087    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1088        let mut diag = Diag::new(dcx, level, fluent::passes_break_non_loop);
1089        diag.span(self.span);
1090        diag.code(E0571);
1091        diag.arg("kind", self.kind);
1092        diag.span_label(self.span, fluent::passes_label);
1093        if let Some(head) = self.head {
1094            diag.span_label(head, fluent::passes_label2);
1095        }
1096        diag.span_suggestion(
1097            self.span,
1098            fluent::passes_suggestion,
1099            self.suggestion,
1100            Applicability::MaybeIncorrect,
1101        );
1102        if let (Some(label), None) = (self.loop_label, self.break_label) {
1103            match self.break_expr_kind {
1104                ExprKind::Path(hir::QPath::Resolved(
1105                    None,
1106                    hir::Path { segments: [segment], res: hir::def::Res::Err, .. },
1107                )) if label.ident.to_string() == format!("'{}", segment.ident) => {
1108                    // This error is redundant, we will have already emitted a
1109                    // suggestion to use the label when `segment` wasn't found
1110                    // (hence the `Res::Err` check).
1111                    diag.downgrade_to_delayed_bug();
1112                }
1113                _ => {
1114                    diag.span_suggestion(
1115                        self.break_expr_span,
1116                        fluent::passes_break_expr_suggestion,
1117                        label.ident,
1118                        Applicability::MaybeIncorrect,
1119                    );
1120                }
1121            }
1122        }
1123        diag
1124    }
1125}
1126
1127#[derive(Diagnostic)]
1128#[diag(passes_continue_labeled_block, code = E0696)]
1129pub(crate) struct ContinueLabeledBlock {
1130    #[primary_span]
1131    #[label]
1132    pub span: Span,
1133    #[label(passes_block_label)]
1134    pub block_span: Span,
1135}
1136
1137#[derive(Diagnostic)]
1138#[diag(passes_break_inside_closure, code = E0267)]
1139pub(crate) struct BreakInsideClosure<'a> {
1140    #[primary_span]
1141    #[label]
1142    pub span: Span,
1143    #[label(passes_closure_label)]
1144    pub closure_span: Span,
1145    pub name: &'a str,
1146}
1147
1148#[derive(Diagnostic)]
1149#[diag(passes_break_inside_coroutine, code = E0267)]
1150pub(crate) struct BreakInsideCoroutine<'a> {
1151    #[primary_span]
1152    #[label]
1153    pub span: Span,
1154    #[label(passes_coroutine_label)]
1155    pub coroutine_span: Span,
1156    pub name: &'a str,
1157    pub kind: &'a str,
1158    pub source: &'a str,
1159}
1160
1161#[derive(Diagnostic)]
1162#[diag(passes_outside_loop, code = E0268)]
1163pub(crate) struct OutsideLoop<'a> {
1164    #[primary_span]
1165    #[label]
1166    pub spans: Vec<Span>,
1167    pub name: &'a str,
1168    pub is_break: bool,
1169    #[subdiagnostic]
1170    pub suggestion: Option<OutsideLoopSuggestion>,
1171}
1172#[derive(Subdiagnostic)]
1173#[multipart_suggestion(passes_outside_loop_suggestion, applicability = "maybe-incorrect")]
1174pub(crate) struct OutsideLoopSuggestion {
1175    #[suggestion_part(code = "'block: ")]
1176    pub block_span: Span,
1177    #[suggestion_part(code = " 'block")]
1178    pub break_spans: Vec<Span>,
1179}
1180
1181#[derive(Diagnostic)]
1182#[diag(passes_unlabeled_in_labeled_block, code = E0695)]
1183pub(crate) struct UnlabeledInLabeledBlock<'a> {
1184    #[primary_span]
1185    #[label]
1186    pub span: Span,
1187    pub cf_type: &'a str,
1188}
1189
1190#[derive(Diagnostic)]
1191#[diag(passes_unlabeled_cf_in_while_condition, code = E0590)]
1192pub(crate) struct UnlabeledCfInWhileCondition<'a> {
1193    #[primary_span]
1194    #[label]
1195    pub span: Span,
1196    pub cf_type: &'a str,
1197}
1198
1199#[derive(Diagnostic)]
1200#[diag(passes_no_patterns)]
1201pub(crate) struct NoPatterns {
1202    #[primary_span]
1203    pub span: Span,
1204}
1205
1206#[derive(Diagnostic)]
1207#[diag(passes_params_not_allowed)]
1208#[help]
1209pub(crate) struct ParamsNotAllowed {
1210    #[primary_span]
1211    pub span: Span,
1212}
1213
1214pub(crate) struct NakedFunctionsAsmBlock {
1215    pub span: Span,
1216    pub multiple_asms: Vec<Span>,
1217    pub non_asms: Vec<Span>,
1218}
1219
1220impl<G: EmissionGuarantee> Diagnostic<'_, G> for NakedFunctionsAsmBlock {
1221    #[track_caller]
1222    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1223        let mut diag = Diag::new(dcx, level, fluent::passes_naked_functions_asm_block);
1224        diag.span(self.span);
1225        diag.code(E0787);
1226        for span in self.multiple_asms.iter() {
1227            diag.span_label(*span, fluent::passes_label_multiple_asm);
1228        }
1229        for span in self.non_asms.iter() {
1230            diag.span_label(*span, fluent::passes_label_non_asm);
1231        }
1232        diag
1233    }
1234}
1235
1236#[derive(Diagnostic)]
1237#[diag(passes_naked_functions_must_naked_asm, code = E0787)]
1238pub(crate) struct NakedFunctionsMustNakedAsm {
1239    #[primary_span]
1240    #[label]
1241    pub span: Span,
1242}
1243
1244#[derive(Diagnostic)]
1245#[diag(passes_naked_functions_incompatible_attribute, code = E0736)]
1246pub(crate) struct NakedFunctionIncompatibleAttribute {
1247    #[primary_span]
1248    #[label]
1249    pub span: Span,
1250    #[label(passes_naked_attribute)]
1251    pub naked_span: Span,
1252    pub attr: String,
1253}
1254
1255#[derive(Diagnostic)]
1256#[diag(passes_naked_asm_outside_naked_fn)]
1257pub(crate) struct NakedAsmOutsideNakedFn {
1258    #[primary_span]
1259    pub span: Span,
1260}
1261
1262#[derive(Diagnostic)]
1263#[diag(passes_attr_only_in_functions)]
1264pub(crate) struct AttrOnlyInFunctions {
1265    #[primary_span]
1266    pub span: Span,
1267    pub attr: Symbol,
1268}
1269
1270#[derive(Diagnostic)]
1271#[diag(passes_multiple_rustc_main, code = E0137)]
1272pub(crate) struct MultipleRustcMain {
1273    #[primary_span]
1274    pub span: Span,
1275    #[label(passes_first)]
1276    pub first: Span,
1277    #[label(passes_additional)]
1278    pub additional: Span,
1279}
1280
1281#[derive(Diagnostic)]
1282#[diag(passes_extern_main)]
1283pub(crate) struct ExternMain {
1284    #[primary_span]
1285    pub span: Span,
1286}
1287
1288pub(crate) struct NoMainErr {
1289    pub sp: Span,
1290    pub crate_name: Symbol,
1291    pub has_filename: bool,
1292    pub filename: PathBuf,
1293    pub file_empty: bool,
1294    pub non_main_fns: Vec<Span>,
1295    pub main_def_opt: Option<MainDefinition>,
1296    pub add_teach_note: bool,
1297}
1298
1299impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NoMainErr {
1300    #[track_caller]
1301    fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
1302        let mut diag = Diag::new(dcx, level, fluent::passes_no_main_function);
1303        diag.span(DUMMY_SP);
1304        diag.code(E0601);
1305        diag.arg("crate_name", self.crate_name);
1306        diag.arg("filename", self.filename);
1307        diag.arg("has_filename", self.has_filename);
1308        let note = if !self.non_main_fns.is_empty() {
1309            for &span in &self.non_main_fns {
1310                diag.span_note(span, fluent::passes_here_is_main);
1311            }
1312            diag.note(fluent::passes_one_or_more_possible_main);
1313            diag.help(fluent::passes_consider_moving_main);
1314            // There were some functions named `main` though. Try to give the user a hint.
1315            fluent::passes_main_must_be_defined_at_crate
1316        } else if self.has_filename {
1317            fluent::passes_consider_adding_main_to_file
1318        } else {
1319            fluent::passes_consider_adding_main_at_crate
1320        };
1321        if self.file_empty {
1322            diag.note(note);
1323        } else {
1324            diag.span(self.sp.shrink_to_hi());
1325            diag.span_label(self.sp.shrink_to_hi(), note);
1326        }
1327
1328        if let Some(main_def) = self.main_def_opt
1329            && main_def.opt_fn_def_id().is_none()
1330        {
1331            // There is something at `crate::main`, but it is not a function definition.
1332            diag.span_label(main_def.span, fluent::passes_non_function_main);
1333        }
1334
1335        if self.add_teach_note {
1336            diag.note(fluent::passes_teach_note);
1337        }
1338        diag
1339    }
1340}
1341
1342pub(crate) struct DuplicateLangItem {
1343    pub local_span: Option<Span>,
1344    pub lang_item_name: Symbol,
1345    pub crate_name: Symbol,
1346    pub dependency_of: Option<Symbol>,
1347    pub is_local: bool,
1348    pub path: String,
1349    pub first_defined_span: Option<Span>,
1350    pub orig_crate_name: Option<Symbol>,
1351    pub orig_dependency_of: Option<Symbol>,
1352    pub orig_is_local: bool,
1353    pub orig_path: String,
1354    pub(crate) duplicate: Duplicate,
1355}
1356
1357impl<G: EmissionGuarantee> Diagnostic<'_, G> for DuplicateLangItem {
1358    #[track_caller]
1359    fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1360        let mut diag = Diag::new(
1361            dcx,
1362            level,
1363            match self.duplicate {
1364                Duplicate::Plain => fluent::passes_duplicate_lang_item,
1365                Duplicate::Crate => fluent::passes_duplicate_lang_item_crate,
1366                Duplicate::CrateDepends => fluent::passes_duplicate_lang_item_crate_depends,
1367            },
1368        );
1369        diag.code(E0152);
1370        diag.arg("lang_item_name", self.lang_item_name);
1371        diag.arg("crate_name", self.crate_name);
1372        if let Some(dependency_of) = self.dependency_of {
1373            diag.arg("dependency_of", dependency_of);
1374        }
1375        diag.arg("path", self.path);
1376        if let Some(orig_crate_name) = self.orig_crate_name {
1377            diag.arg("orig_crate_name", orig_crate_name);
1378        }
1379        if let Some(orig_dependency_of) = self.orig_dependency_of {
1380            diag.arg("orig_dependency_of", orig_dependency_of);
1381        }
1382        diag.arg("orig_path", self.orig_path);
1383        if let Some(span) = self.local_span {
1384            diag.span(span);
1385        }
1386        if let Some(span) = self.first_defined_span {
1387            diag.span_note(span, fluent::passes_first_defined_span);
1388        } else {
1389            if self.orig_dependency_of.is_none() {
1390                diag.note(fluent::passes_first_defined_crate);
1391            } else {
1392                diag.note(fluent::passes_first_defined_crate_depends);
1393            }
1394
1395            if self.orig_is_local {
1396                diag.note(fluent::passes_first_definition_local);
1397            } else {
1398                diag.note(fluent::passes_first_definition_path);
1399            }
1400
1401            if self.is_local {
1402                diag.note(fluent::passes_second_definition_local);
1403            } else {
1404                diag.note(fluent::passes_second_definition_path);
1405            }
1406        }
1407        diag
1408    }
1409}
1410
1411#[derive(Diagnostic)]
1412#[diag(passes_incorrect_target, code = E0718)]
1413pub(crate) struct IncorrectTarget<'a> {
1414    #[primary_span]
1415    pub span: Span,
1416    #[label]
1417    pub generics_span: Span,
1418    pub name: &'a str, // cannot be symbol because it renders e.g. `r#fn` instead of `fn`
1419    pub kind: &'static str,
1420    pub num: usize,
1421    pub actual_num: usize,
1422    pub at_least: bool,
1423}
1424
1425#[derive(Diagnostic)]
1426#[diag(passes_incorrect_crate_type)]
1427pub(crate) struct IncorrectCrateType {
1428    #[primary_span]
1429    pub span: Span,
1430}
1431
1432#[derive(LintDiagnostic)]
1433#[diag(passes_useless_assignment)]
1434pub(crate) struct UselessAssignment<'a> {
1435    pub is_field_assign: bool,
1436    pub ty: Ty<'a>,
1437}
1438
1439#[derive(LintDiagnostic)]
1440#[diag(passes_only_has_effect_on)]
1441pub(crate) struct OnlyHasEffectOn {
1442    pub attr_name: String,
1443    pub target_name: String,
1444}
1445
1446#[derive(LintDiagnostic)]
1447#[diag(passes_inline_ignored_for_exported)]
1448#[help]
1449pub(crate) struct InlineIgnoredForExported {}
1450
1451#[derive(Diagnostic)]
1452#[diag(passes_object_lifetime_err)]
1453pub(crate) struct ObjectLifetimeErr {
1454    #[primary_span]
1455    pub span: Span,
1456    pub repr: String,
1457}
1458
1459#[derive(Diagnostic)]
1460pub(crate) enum AttrApplication {
1461    #[diag(passes_attr_application_enum, code = E0517)]
1462    Enum {
1463        #[primary_span]
1464        hint_span: Span,
1465        #[label]
1466        span: Span,
1467    },
1468    #[diag(passes_attr_application_struct, code = E0517)]
1469    Struct {
1470        #[primary_span]
1471        hint_span: Span,
1472        #[label]
1473        span: Span,
1474    },
1475    #[diag(passes_attr_application_struct_union, code = E0517)]
1476    StructUnion {
1477        #[primary_span]
1478        hint_span: Span,
1479        #[label]
1480        span: Span,
1481    },
1482    #[diag(passes_attr_application_struct_enum_union, code = E0517)]
1483    StructEnumUnion {
1484        #[primary_span]
1485        hint_span: Span,
1486        #[label]
1487        span: Span,
1488    },
1489    #[diag(passes_attr_application_struct_enum_function_method_union, code = E0517)]
1490    StructEnumFunctionMethodUnion {
1491        #[primary_span]
1492        hint_span: Span,
1493        #[label]
1494        span: Span,
1495    },
1496}
1497
1498#[derive(Diagnostic)]
1499#[diag(passes_transparent_incompatible, code = E0692)]
1500pub(crate) struct TransparentIncompatible {
1501    #[primary_span]
1502    pub hint_spans: Vec<Span>,
1503    pub target: String,
1504}
1505
1506#[derive(Diagnostic)]
1507#[diag(passes_deprecated_attribute, code = E0549)]
1508pub(crate) struct DeprecatedAttribute {
1509    #[primary_span]
1510    pub span: Span,
1511}
1512
1513#[derive(Diagnostic)]
1514#[diag(passes_useless_stability)]
1515pub(crate) struct UselessStability {
1516    #[primary_span]
1517    #[label]
1518    pub span: Span,
1519    #[label(passes_item)]
1520    pub item_sp: Span,
1521}
1522
1523#[derive(Diagnostic)]
1524#[diag(passes_cannot_stabilize_deprecated)]
1525pub(crate) struct CannotStabilizeDeprecated {
1526    #[primary_span]
1527    #[label]
1528    pub span: Span,
1529    #[label(passes_item)]
1530    pub item_sp: Span,
1531}
1532
1533#[derive(Diagnostic)]
1534#[diag(passes_unstable_attr_for_already_stable_feature)]
1535pub(crate) struct UnstableAttrForAlreadyStableFeature {
1536    #[primary_span]
1537    #[label]
1538    #[help]
1539    pub span: Span,
1540    #[label(passes_item)]
1541    pub item_sp: Span,
1542}
1543
1544#[derive(Diagnostic)]
1545#[diag(passes_missing_stability_attr)]
1546pub(crate) struct MissingStabilityAttr<'a> {
1547    #[primary_span]
1548    pub span: Span,
1549    pub descr: &'a str,
1550}
1551
1552#[derive(Diagnostic)]
1553#[diag(passes_missing_const_stab_attr)]
1554pub(crate) struct MissingConstStabAttr<'a> {
1555    #[primary_span]
1556    pub span: Span,
1557    pub descr: &'a str,
1558}
1559
1560#[derive(Diagnostic)]
1561#[diag(passes_trait_impl_const_stable)]
1562#[note]
1563pub(crate) struct TraitImplConstStable {
1564    #[primary_span]
1565    pub span: Span,
1566}
1567
1568#[derive(Diagnostic)]
1569#[diag(passes_trait_impl_const_stability_mismatch)]
1570pub(crate) struct TraitImplConstStabilityMismatch {
1571    #[primary_span]
1572    pub span: Span,
1573    #[subdiagnostic]
1574    pub impl_stability: ImplConstStability,
1575    #[subdiagnostic]
1576    pub trait_stability: TraitConstStability,
1577}
1578
1579#[derive(Subdiagnostic)]
1580pub(crate) enum TraitConstStability {
1581    #[note(passes_trait_impl_const_stability_mismatch_trait_stable)]
1582    Stable {
1583        #[primary_span]
1584        span: Span,
1585    },
1586    #[note(passes_trait_impl_const_stability_mismatch_trait_unstable)]
1587    Unstable {
1588        #[primary_span]
1589        span: Span,
1590    },
1591}
1592
1593#[derive(Subdiagnostic)]
1594pub(crate) enum ImplConstStability {
1595    #[note(passes_trait_impl_const_stability_mismatch_impl_stable)]
1596    Stable {
1597        #[primary_span]
1598        span: Span,
1599    },
1600    #[note(passes_trait_impl_const_stability_mismatch_impl_unstable)]
1601    Unstable {
1602        #[primary_span]
1603        span: Span,
1604    },
1605}
1606
1607#[derive(Diagnostic)]
1608#[diag(passes_unknown_feature, code = E0635)]
1609pub(crate) struct UnknownFeature {
1610    #[primary_span]
1611    pub span: Span,
1612    pub feature: Symbol,
1613}
1614
1615#[derive(Diagnostic)]
1616#[diag(passes_implied_feature_not_exist)]
1617pub(crate) struct ImpliedFeatureNotExist {
1618    #[primary_span]
1619    pub span: Span,
1620    pub feature: Symbol,
1621    pub implied_by: Symbol,
1622}
1623
1624#[derive(Diagnostic)]
1625#[diag(passes_duplicate_feature_err, code = E0636)]
1626pub(crate) struct DuplicateFeatureErr {
1627    #[primary_span]
1628    pub span: Span,
1629    pub feature: Symbol,
1630}
1631
1632#[derive(Diagnostic)]
1633#[diag(passes_missing_const_err)]
1634pub(crate) struct MissingConstErr {
1635    #[primary_span]
1636    #[help]
1637    pub fn_sig_span: Span,
1638}
1639
1640#[derive(Diagnostic)]
1641#[diag(passes_const_stable_not_stable)]
1642pub(crate) struct ConstStableNotStable {
1643    #[primary_span]
1644    pub fn_sig_span: Span,
1645    #[label]
1646    pub const_span: Span,
1647}
1648
1649#[derive(LintDiagnostic)]
1650pub(crate) enum MultipleDeadCodes<'tcx> {
1651    #[diag(passes_dead_codes)]
1652    DeadCodes {
1653        multiple: bool,
1654        num: usize,
1655        descr: &'tcx str,
1656        participle: &'tcx str,
1657        name_list: DiagSymbolList,
1658        #[subdiagnostic]
1659        parent_info: Option<ParentInfo<'tcx>>,
1660        #[subdiagnostic]
1661        ignored_derived_impls: Option<IgnoredDerivedImpls>,
1662    },
1663    #[diag(passes_dead_codes)]
1664    UnusedTupleStructFields {
1665        multiple: bool,
1666        num: usize,
1667        descr: &'tcx str,
1668        participle: &'tcx str,
1669        name_list: DiagSymbolList,
1670        #[subdiagnostic]
1671        change_fields_suggestion: ChangeFields,
1672        #[subdiagnostic]
1673        parent_info: Option<ParentInfo<'tcx>>,
1674        #[subdiagnostic]
1675        ignored_derived_impls: Option<IgnoredDerivedImpls>,
1676    },
1677}
1678
1679#[derive(Subdiagnostic)]
1680#[label(passes_parent_info)]
1681pub(crate) struct ParentInfo<'tcx> {
1682    pub num: usize,
1683    pub descr: &'tcx str,
1684    pub parent_descr: &'tcx str,
1685    #[primary_span]
1686    pub span: Span,
1687}
1688
1689#[derive(Subdiagnostic)]
1690#[note(passes_ignored_derived_impls)]
1691pub(crate) struct IgnoredDerivedImpls {
1692    pub name: Symbol,
1693    pub trait_list: DiagSymbolList,
1694    pub trait_list_len: usize,
1695}
1696
1697#[derive(Subdiagnostic)]
1698pub(crate) enum ChangeFields {
1699    #[multipart_suggestion(
1700        passes_change_fields_to_be_of_unit_type,
1701        applicability = "has-placeholders"
1702    )]
1703    ChangeToUnitTypeOrRemove {
1704        num: usize,
1705        #[suggestion_part(code = "()")]
1706        spans: Vec<Span>,
1707    },
1708    #[help(passes_remove_fields)]
1709    Remove { num: usize },
1710}
1711
1712#[derive(Diagnostic)]
1713#[diag(passes_proc_macro_bad_sig)]
1714pub(crate) struct ProcMacroBadSig {
1715    #[primary_span]
1716    pub span: Span,
1717    pub kind: ProcMacroKind,
1718}
1719
1720#[derive(LintDiagnostic)]
1721#[diag(passes_unreachable_due_to_uninhabited)]
1722pub(crate) struct UnreachableDueToUninhabited<'desc, 'tcx> {
1723    pub descr: &'desc str,
1724    #[label]
1725    pub expr: Span,
1726    #[label(passes_label_orig)]
1727    #[note]
1728    pub orig: Span,
1729    pub ty: Ty<'tcx>,
1730}
1731
1732#[derive(LintDiagnostic)]
1733#[diag(passes_unused_var_maybe_capture_ref)]
1734#[help]
1735pub(crate) struct UnusedVarMaybeCaptureRef {
1736    pub name: String,
1737}
1738
1739#[derive(LintDiagnostic)]
1740#[diag(passes_unused_capture_maybe_capture_ref)]
1741#[help]
1742pub(crate) struct UnusedCaptureMaybeCaptureRef {
1743    pub name: String,
1744}
1745
1746#[derive(LintDiagnostic)]
1747#[diag(passes_unused_var_remove_field)]
1748pub(crate) struct UnusedVarRemoveField {
1749    pub name: String,
1750    #[subdiagnostic]
1751    pub sugg: UnusedVarRemoveFieldSugg,
1752}
1753
1754#[derive(Subdiagnostic)]
1755#[multipart_suggestion(
1756    passes_unused_var_remove_field_suggestion,
1757    applicability = "machine-applicable"
1758)]
1759pub(crate) struct UnusedVarRemoveFieldSugg {
1760    #[suggestion_part(code = "")]
1761    pub spans: Vec<Span>,
1762}
1763
1764#[derive(LintDiagnostic)]
1765#[diag(passes_unused_var_assigned_only)]
1766#[note]
1767pub(crate) struct UnusedVarAssignedOnly {
1768    pub name: String,
1769}
1770
1771#[derive(LintDiagnostic)]
1772#[diag(passes_unnecessary_stable_feature)]
1773pub(crate) struct UnnecessaryStableFeature {
1774    pub feature: Symbol,
1775    pub since: Symbol,
1776}
1777
1778#[derive(LintDiagnostic)]
1779#[diag(passes_unnecessary_partial_stable_feature)]
1780pub(crate) struct UnnecessaryPartialStableFeature {
1781    #[suggestion(code = "{implies}", applicability = "maybe-incorrect")]
1782    pub span: Span,
1783    #[suggestion(passes_suggestion_remove, code = "", applicability = "maybe-incorrect")]
1784    pub line: Span,
1785    pub feature: Symbol,
1786    pub since: Symbol,
1787    pub implies: Symbol,
1788}
1789
1790#[derive(LintDiagnostic)]
1791#[diag(passes_ineffective_unstable_impl)]
1792#[note]
1793pub(crate) struct IneffectiveUnstableImpl;
1794
1795#[derive(LintDiagnostic)]
1796#[diag(passes_unused_assign)]
1797pub(crate) struct UnusedAssign {
1798    pub name: String,
1799    #[subdiagnostic]
1800    pub suggestion: Option<UnusedAssignSuggestion>,
1801    #[help]
1802    pub help: bool,
1803}
1804
1805#[derive(Subdiagnostic)]
1806#[multipart_suggestion(passes_unused_assign_suggestion, applicability = "maybe-incorrect")]
1807pub(crate) struct UnusedAssignSuggestion {
1808    pub pre: &'static str,
1809    #[suggestion_part(code = "{pre}mut ")]
1810    pub ty_span: Option<Span>,
1811    #[suggestion_part(code = "")]
1812    pub ty_ref_span: Span,
1813    #[suggestion_part(code = "*")]
1814    pub ident_span: Span,
1815    #[suggestion_part(code = "")]
1816    pub expr_ref_span: Span,
1817}
1818
1819#[derive(LintDiagnostic)]
1820#[diag(passes_unused_assign_passed)]
1821#[help]
1822pub(crate) struct UnusedAssignPassed {
1823    pub name: String,
1824}
1825
1826#[derive(LintDiagnostic)]
1827#[diag(passes_unused_variable_try_prefix)]
1828pub(crate) struct UnusedVariableTryPrefix {
1829    #[label]
1830    pub label: Option<Span>,
1831    #[subdiagnostic]
1832    pub string_interp: Vec<UnusedVariableStringInterp>,
1833    #[subdiagnostic]
1834    pub sugg: UnusedVariableSugg,
1835    pub name: String,
1836}
1837
1838#[derive(Subdiagnostic)]
1839pub(crate) enum UnusedVariableSugg {
1840    #[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")]
1841    TryPrefixSugg {
1842        #[suggestion_part(code = "_{name}")]
1843        spans: Vec<Span>,
1844        name: String,
1845    },
1846    #[help(passes_unused_variable_args_in_macro)]
1847    NoSugg {
1848        #[primary_span]
1849        span: Span,
1850        name: String,
1851    },
1852}
1853
1854pub(crate) struct UnusedVariableStringInterp {
1855    pub lit: Span,
1856    pub lo: Span,
1857    pub hi: Span,
1858}
1859
1860impl Subdiagnostic for UnusedVariableStringInterp {
1861    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1862        diag.span_label(self.lit, crate::fluent_generated::passes_maybe_string_interpolation);
1863        diag.multipart_suggestion(
1864            crate::fluent_generated::passes_string_interpolation_only_works,
1865            vec![(self.lo, String::from("format!(")), (self.hi, String::from(")"))],
1866            Applicability::MachineApplicable,
1867        );
1868    }
1869}
1870
1871#[derive(LintDiagnostic)]
1872#[diag(passes_unused_variable_try_ignore)]
1873pub(crate) struct UnusedVarTryIgnore {
1874    #[subdiagnostic]
1875    pub sugg: UnusedVarTryIgnoreSugg,
1876}
1877
1878#[derive(Subdiagnostic)]
1879#[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")]
1880pub(crate) struct UnusedVarTryIgnoreSugg {
1881    #[suggestion_part(code = "{name}: _")]
1882    pub shorthands: Vec<Span>,
1883    #[suggestion_part(code = "_")]
1884    pub non_shorthands: Vec<Span>,
1885    pub name: String,
1886}
1887
1888#[derive(LintDiagnostic)]
1889#[diag(passes_attr_crate_level)]
1890#[note]
1891pub(crate) struct AttrCrateLevelOnly {
1892    #[subdiagnostic]
1893    pub sugg: Option<AttrCrateLevelOnlySugg>,
1894}
1895
1896#[derive(Subdiagnostic)]
1897#[suggestion(passes_suggestion, applicability = "maybe-incorrect", code = "!", style = "verbose")]
1898pub(crate) struct AttrCrateLevelOnlySugg {
1899    #[primary_span]
1900    pub attr: Span,
1901}
1902
1903#[derive(Diagnostic)]
1904#[diag(passes_no_sanitize)]
1905pub(crate) struct NoSanitize<'a> {
1906    #[primary_span]
1907    pub attr_span: Span,
1908    #[label]
1909    pub defn_span: Span,
1910    pub accepted_kind: &'a str,
1911    pub attr_str: &'a str,
1912}
1913
1914// FIXME(jdonszelmann): move back to rustc_attr
1915#[derive(Diagnostic)]
1916#[diag(passes_rustc_const_stable_indirect_pairing)]
1917pub(crate) struct RustcConstStableIndirectPairing {
1918    #[primary_span]
1919    pub span: Span,
1920}
1921
1922#[derive(Diagnostic)]
1923#[diag(passes_unsupported_attributes_in_where)]
1924#[help]
1925pub(crate) struct UnsupportedAttributesInWhere {
1926    #[primary_span]
1927    pub span: MultiSpan,
1928}
1929
1930#[derive(Diagnostic)]
1931pub(crate) enum UnexportableItem<'a> {
1932    #[diag(passes_unexportable_item)]
1933    Item {
1934        #[primary_span]
1935        span: Span,
1936        descr: &'a str,
1937    },
1938
1939    #[diag(passes_unexportable_generic_fn)]
1940    GenericFn(#[primary_span] Span),
1941
1942    #[diag(passes_unexportable_fn_abi)]
1943    FnAbi(#[primary_span] Span),
1944
1945    #[diag(passes_unexportable_type_repr)]
1946    TypeRepr(#[primary_span] Span),
1947
1948    #[diag(passes_unexportable_type_in_interface)]
1949    TypeInInterface {
1950        #[primary_span]
1951        span: Span,
1952        desc: &'a str,
1953        ty: &'a str,
1954        #[label]
1955        ty_span: Span,
1956    },
1957
1958    #[diag(passes_unexportable_priv_item)]
1959    PrivItem {
1960        #[primary_span]
1961        span: Span,
1962        #[note]
1963        vis_note: Span,
1964        vis_descr: &'a str,
1965    },
1966
1967    #[diag(passes_unexportable_adt_with_private_fields)]
1968    AdtWithPrivFields {
1969        #[primary_span]
1970        span: Span,
1971        #[note]
1972        vis_note: Span,
1973        field_name: &'a str,
1974    },
1975}