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