rustc_passes/
errors.rs

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