1use std::io::Error;
2use std::path::{Path, PathBuf};
3
4use rustc_ast::Label;
5use rustc_errors::codes::*;
6use rustc_errors::{
7 Applicability, Diag, DiagCtxtHandle, DiagSymbolList, Diagnostic, EmissionGuarantee, Level,
8 MultiSpan, Subdiagnostic,
9};
10use rustc_hir::{self as hir, ExprKind, Target};
11use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
12use rustc_middle::ty::{MainDefinition, Ty};
13use rustc_span::{DUMMY_SP, Span, Symbol};
14
15use crate::check_attr::ProcMacroKind;
16use crate::fluent_generated as fluent;
17use crate::lang_items::Duplicate;
18
19#[derive(LintDiagnostic)]
20#[diag(passes_incorrect_do_not_recommend_location)]
21pub(crate) struct IncorrectDoNotRecommendLocation;
22
23#[derive(LintDiagnostic)]
24#[diag(passes_incorrect_do_not_recommend_args)]
25pub(crate) struct DoNotRecommendDoesNotExpectArgs;
26
27#[derive(Diagnostic)]
28#[diag(passes_autodiff_attr)]
29pub(crate) struct AutoDiffAttr {
30 #[primary_span]
31 #[label]
32 pub attr_span: Span,
33}
34
35#[derive(LintDiagnostic)]
36#[diag(passes_outer_crate_level_attr)]
37pub(crate) struct OuterCrateLevelAttr;
38
39#[derive(LintDiagnostic)]
40#[diag(passes_inner_crate_level_attr)]
41pub(crate) struct InnerCrateLevelAttr;
42
43#[derive(LintDiagnostic)]
44#[diag(passes_ignored_attr_with_macro)]
45pub(crate) struct IgnoredAttrWithMacro<'a> {
46 pub sym: &'a str,
47}
48
49#[derive(LintDiagnostic)]
50#[diag(passes_ignored_attr)]
51pub(crate) struct IgnoredAttr<'a> {
52 pub sym: &'a str,
53}
54
55#[derive(LintDiagnostic)]
56#[diag(passes_inline_ignored_function_prototype)]
57pub(crate) struct IgnoredInlineAttrFnProto;
58
59#[derive(LintDiagnostic)]
60#[diag(passes_inline_ignored_constants)]
61#[warning]
62#[note]
63pub(crate) struct IgnoredInlineAttrConstants;
64
65#[derive(Diagnostic)]
66#[diag(passes_inline_not_fn_or_closure, code = E0518)]
67pub(crate) struct InlineNotFnOrClosure {
68 #[primary_span]
69 pub attr_span: Span,
70 #[label]
71 pub defn_span: Span,
72}
73
74#[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 InvalidArgument,
760
761 #[diag(passes_invalid_macro_export_arguments_too_many_items)]
762 TooManyItems,
763}
764
765#[derive(Subdiagnostic)]
766pub(crate) enum UnusedNote {
767 #[note(passes_unused_empty_lints_note)]
768 EmptyList { name: Symbol },
769 #[note(passes_unused_no_lints_note)]
770 NoLints { name: Symbol },
771 #[note(passes_unused_default_method_body_const_note)]
772 DefaultMethodBodyConst,
773 #[note(passes_unused_linker_messages_note)]
774 LinkerMessagesBinaryCrateOnly,
775}
776
777#[derive(LintDiagnostic)]
778#[diag(passes_unused)]
779pub(crate) struct Unused {
780 #[suggestion(code = "", applicability = "machine-applicable")]
781 pub attr_span: Span,
782 #[subdiagnostic]
783 pub note: UnusedNote,
784}
785
786#[derive(Diagnostic)]
787#[diag(passes_non_exported_macro_invalid_attrs, code = E0518)]
788pub(crate) struct NonExportedMacroInvalidAttrs {
789 #[primary_span]
790 #[label]
791 pub attr_span: Span,
792}
793
794#[derive(Diagnostic)]
795#[diag(passes_may_dangle)]
796pub(crate) struct InvalidMayDangle {
797 #[primary_span]
798 pub attr_span: Span,
799}
800
801#[derive(LintDiagnostic)]
802#[diag(passes_unused_duplicate)]
803pub(crate) struct UnusedDuplicate {
804 #[suggestion(code = "", applicability = "machine-applicable")]
805 pub this: Span,
806 #[note]
807 pub other: Span,
808 #[warning]
809 pub warning: bool,
810}
811
812#[derive(Diagnostic)]
813#[diag(passes_unused_multiple)]
814pub(crate) struct UnusedMultiple {
815 #[primary_span]
816 #[suggestion(code = "", applicability = "machine-applicable")]
817 pub this: Span,
818 #[note]
819 pub other: Span,
820 pub name: Symbol,
821}
822
823#[derive(Diagnostic)]
824#[diag(passes_rustc_lint_opt_ty)]
825pub(crate) struct RustcLintOptTy {
826 #[primary_span]
827 pub attr_span: Span,
828 #[label]
829 pub span: Span,
830}
831
832#[derive(Diagnostic)]
833#[diag(passes_rustc_lint_opt_deny_field_access)]
834pub(crate) struct RustcLintOptDenyFieldAccess {
835 #[primary_span]
836 pub attr_span: Span,
837 #[label]
838 pub span: Span,
839}
840
841#[derive(Diagnostic)]
842#[diag(passes_collapse_debuginfo)]
843pub(crate) struct CollapseDebuginfo {
844 #[primary_span]
845 pub attr_span: Span,
846 #[label]
847 pub defn_span: Span,
848}
849
850#[derive(LintDiagnostic)]
851#[diag(passes_deprecated_annotation_has_no_effect)]
852pub(crate) struct DeprecatedAnnotationHasNoEffect {
853 #[suggestion(applicability = "machine-applicable", code = "")]
854 pub span: Span,
855}
856
857#[derive(Diagnostic)]
858#[diag(passes_unknown_external_lang_item, code = E0264)]
859pub(crate) struct UnknownExternLangItem {
860 #[primary_span]
861 pub span: Span,
862 pub lang_item: Symbol,
863}
864
865#[derive(Diagnostic)]
866#[diag(passes_missing_panic_handler)]
867pub(crate) struct MissingPanicHandler;
868
869#[derive(Diagnostic)]
870#[diag(passes_panic_unwind_without_std)]
871#[help]
872#[note]
873pub(crate) struct PanicUnwindWithoutStd;
874
875#[derive(Diagnostic)]
876#[diag(passes_missing_lang_item)]
877#[note]
878#[help]
879pub(crate) struct MissingLangItem {
880 pub name: Symbol,
881}
882
883#[derive(Diagnostic)]
884#[diag(passes_lang_item_fn_with_track_caller)]
885pub(crate) struct LangItemWithTrackCaller {
886 #[primary_span]
887 pub attr_span: Span,
888 pub name: Symbol,
889 #[label]
890 pub sig_span: Span,
891}
892
893#[derive(Diagnostic)]
894#[diag(passes_lang_item_fn_with_target_feature)]
895pub(crate) struct LangItemWithTargetFeature {
896 #[primary_span]
897 pub attr_span: Span,
898 pub name: Symbol,
899 #[label]
900 pub sig_span: Span,
901}
902
903#[derive(Diagnostic)]
904#[diag(passes_lang_item_on_incorrect_target, code = E0718)]
905pub(crate) struct LangItemOnIncorrectTarget {
906 #[primary_span]
907 #[label]
908 pub span: Span,
909 pub name: Symbol,
910 pub expected_target: Target,
911 pub actual_target: Target,
912}
913
914#[derive(Diagnostic)]
915#[diag(passes_unknown_lang_item, code = E0522)]
916pub(crate) struct UnknownLangItem {
917 #[primary_span]
918 #[label]
919 pub span: Span,
920 pub name: Symbol,
921}
922
923pub(crate) struct InvalidAttrAtCrateLevel {
924 pub span: Span,
925 pub sugg_span: Option<Span>,
926 pub name: Symbol,
927 pub item: Option<ItemFollowingInnerAttr>,
928}
929
930#[derive(Clone, Copy)]
931pub(crate) struct ItemFollowingInnerAttr {
932 pub span: Span,
933 pub kind: &'static str,
934}
935
936impl<G: EmissionGuarantee> Diagnostic<'_, G> for InvalidAttrAtCrateLevel {
937 #[track_caller]
938 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
939 let mut diag = Diag::new(dcx, level, fluent::passes_invalid_attr_at_crate_level);
940 diag.span(self.span);
941 diag.arg("name", self.name);
942 if let Some(span) = self.sugg_span {
945 diag.span_suggestion_verbose(
946 span,
947 fluent::passes_suggestion,
948 String::new(),
949 Applicability::MachineApplicable,
950 );
951 }
952 if let Some(item) = self.item {
953 diag.arg("kind", item.kind);
954 diag.span_label(item.span, fluent::passes_invalid_attr_at_crate_level_item);
955 }
956 diag
957 }
958}
959
960#[derive(Diagnostic)]
961#[diag(passes_duplicate_diagnostic_item_in_crate)]
962pub(crate) struct DuplicateDiagnosticItemInCrate {
963 #[primary_span]
964 pub duplicate_span: Option<Span>,
965 #[note(passes_diagnostic_item_first_defined)]
966 pub orig_span: Option<Span>,
967 #[note]
968 pub different_crates: bool,
969 pub crate_name: Symbol,
970 pub orig_crate_name: Symbol,
971 pub name: Symbol,
972}
973
974#[derive(Diagnostic)]
975#[diag(passes_layout_abi)]
976pub(crate) struct LayoutAbi {
977 #[primary_span]
978 pub span: Span,
979 pub abi: String,
980}
981
982#[derive(Diagnostic)]
983#[diag(passes_layout_align)]
984pub(crate) struct LayoutAlign {
985 #[primary_span]
986 pub span: Span,
987 pub align: String,
988}
989
990#[derive(Diagnostic)]
991#[diag(passes_layout_size)]
992pub(crate) struct LayoutSize {
993 #[primary_span]
994 pub span: Span,
995 pub size: String,
996}
997
998#[derive(Diagnostic)]
999#[diag(passes_layout_homogeneous_aggregate)]
1000pub(crate) struct LayoutHomogeneousAggregate {
1001 #[primary_span]
1002 pub span: Span,
1003 pub homogeneous_aggregate: String,
1004}
1005
1006#[derive(Diagnostic)]
1007#[diag(passes_layout_of)]
1008pub(crate) struct LayoutOf<'tcx> {
1009 #[primary_span]
1010 pub span: Span,
1011 pub normalized_ty: Ty<'tcx>,
1012 pub ty_layout: String,
1013}
1014
1015#[derive(Diagnostic)]
1016#[diag(passes_layout_invalid_attribute)]
1017pub(crate) struct LayoutInvalidAttribute {
1018 #[primary_span]
1019 pub span: Span,
1020}
1021
1022#[derive(Diagnostic)]
1023#[diag(passes_abi_of)]
1024pub(crate) struct AbiOf {
1025 #[primary_span]
1026 pub span: Span,
1027 pub fn_name: Symbol,
1028 pub fn_abi: String,
1029}
1030
1031#[derive(Diagnostic)]
1032#[diag(passes_abi_ne)]
1033pub(crate) struct AbiNe {
1034 #[primary_span]
1035 pub span: Span,
1036 pub left: String,
1037 pub right: String,
1038}
1039
1040#[derive(Diagnostic)]
1041#[diag(passes_abi_invalid_attribute)]
1042pub(crate) struct AbiInvalidAttribute {
1043 #[primary_span]
1044 pub span: Span,
1045}
1046
1047#[derive(Diagnostic)]
1048#[diag(passes_unrecognized_argument)]
1049pub(crate) struct UnrecognizedArgument {
1050 #[primary_span]
1051 pub span: Span,
1052}
1053
1054#[derive(Diagnostic)]
1055#[diag(passes_feature_stable_twice, code = E0711)]
1056pub(crate) struct FeatureStableTwice {
1057 #[primary_span]
1058 pub span: Span,
1059 pub feature: Symbol,
1060 pub since: Symbol,
1061 pub prev_since: Symbol,
1062}
1063
1064#[derive(Diagnostic)]
1065#[diag(passes_feature_previously_declared, code = E0711)]
1066pub(crate) struct FeaturePreviouslyDeclared<'a> {
1067 #[primary_span]
1068 pub span: Span,
1069 pub feature: Symbol,
1070 pub declared: &'a str,
1071 pub prev_declared: &'a str,
1072}
1073
1074pub(crate) struct BreakNonLoop<'a> {
1075 pub span: Span,
1076 pub head: Option<Span>,
1077 pub kind: &'a str,
1078 pub suggestion: String,
1079 pub loop_label: Option<Label>,
1080 pub break_label: Option<Label>,
1081 pub break_expr_kind: &'a ExprKind<'a>,
1082 pub break_expr_span: Span,
1083}
1084
1085impl<'a, G: EmissionGuarantee> Diagnostic<'_, G> for BreakNonLoop<'a> {
1086 #[track_caller]
1087 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1088 let mut diag = Diag::new(dcx, level, fluent::passes_break_non_loop);
1089 diag.span(self.span);
1090 diag.code(E0571);
1091 diag.arg("kind", self.kind);
1092 diag.span_label(self.span, fluent::passes_label);
1093 if let Some(head) = self.head {
1094 diag.span_label(head, fluent::passes_label2);
1095 }
1096 diag.span_suggestion(
1097 self.span,
1098 fluent::passes_suggestion,
1099 self.suggestion,
1100 Applicability::MaybeIncorrect,
1101 );
1102 if let (Some(label), None) = (self.loop_label, self.break_label) {
1103 match self.break_expr_kind {
1104 ExprKind::Path(hir::QPath::Resolved(
1105 None,
1106 hir::Path { segments: [segment], res: hir::def::Res::Err, .. },
1107 )) if label.ident.to_string() == format!("'{}", segment.ident) => {
1108 diag.downgrade_to_delayed_bug();
1112 }
1113 _ => {
1114 diag.span_suggestion(
1115 self.break_expr_span,
1116 fluent::passes_break_expr_suggestion,
1117 label.ident,
1118 Applicability::MaybeIncorrect,
1119 );
1120 }
1121 }
1122 }
1123 diag
1124 }
1125}
1126
1127#[derive(Diagnostic)]
1128#[diag(passes_continue_labeled_block, code = E0696)]
1129pub(crate) struct ContinueLabeledBlock {
1130 #[primary_span]
1131 #[label]
1132 pub span: Span,
1133 #[label(passes_block_label)]
1134 pub block_span: Span,
1135}
1136
1137#[derive(Diagnostic)]
1138#[diag(passes_break_inside_closure, code = E0267)]
1139pub(crate) struct BreakInsideClosure<'a> {
1140 #[primary_span]
1141 #[label]
1142 pub span: Span,
1143 #[label(passes_closure_label)]
1144 pub closure_span: Span,
1145 pub name: &'a str,
1146}
1147
1148#[derive(Diagnostic)]
1149#[diag(passes_break_inside_coroutine, code = E0267)]
1150pub(crate) struct BreakInsideCoroutine<'a> {
1151 #[primary_span]
1152 #[label]
1153 pub span: Span,
1154 #[label(passes_coroutine_label)]
1155 pub coroutine_span: Span,
1156 pub name: &'a str,
1157 pub kind: &'a str,
1158 pub source: &'a str,
1159}
1160
1161#[derive(Diagnostic)]
1162#[diag(passes_outside_loop, code = E0268)]
1163pub(crate) struct OutsideLoop<'a> {
1164 #[primary_span]
1165 #[label]
1166 pub spans: Vec<Span>,
1167 pub name: &'a str,
1168 pub is_break: bool,
1169 #[subdiagnostic]
1170 pub suggestion: Option<OutsideLoopSuggestion>,
1171}
1172#[derive(Subdiagnostic)]
1173#[multipart_suggestion(passes_outside_loop_suggestion, applicability = "maybe-incorrect")]
1174pub(crate) struct OutsideLoopSuggestion {
1175 #[suggestion_part(code = "'block: ")]
1176 pub block_span: Span,
1177 #[suggestion_part(code = " 'block")]
1178 pub break_spans: Vec<Span>,
1179}
1180
1181#[derive(Diagnostic)]
1182#[diag(passes_unlabeled_in_labeled_block, code = E0695)]
1183pub(crate) struct UnlabeledInLabeledBlock<'a> {
1184 #[primary_span]
1185 #[label]
1186 pub span: Span,
1187 pub cf_type: &'a str,
1188}
1189
1190#[derive(Diagnostic)]
1191#[diag(passes_unlabeled_cf_in_while_condition, code = E0590)]
1192pub(crate) struct UnlabeledCfInWhileCondition<'a> {
1193 #[primary_span]
1194 #[label]
1195 pub span: Span,
1196 pub cf_type: &'a str,
1197}
1198
1199#[derive(Diagnostic)]
1200#[diag(passes_naked_functions_incompatible_attribute, code = E0736)]
1201pub(crate) struct NakedFunctionIncompatibleAttribute {
1202 #[primary_span]
1203 #[label]
1204 pub span: Span,
1205 #[label(passes_naked_attribute)]
1206 pub naked_span: Span,
1207 pub attr: String,
1208}
1209
1210#[derive(Diagnostic)]
1211#[diag(passes_attr_only_in_functions)]
1212pub(crate) struct AttrOnlyInFunctions {
1213 #[primary_span]
1214 pub span: Span,
1215 pub attr: Symbol,
1216}
1217
1218#[derive(Diagnostic)]
1219#[diag(passes_multiple_rustc_main, code = E0137)]
1220pub(crate) struct MultipleRustcMain {
1221 #[primary_span]
1222 pub span: Span,
1223 #[label(passes_first)]
1224 pub first: Span,
1225 #[label(passes_additional)]
1226 pub additional: Span,
1227}
1228
1229#[derive(Diagnostic)]
1230#[diag(passes_extern_main)]
1231pub(crate) struct ExternMain {
1232 #[primary_span]
1233 pub span: Span,
1234}
1235
1236pub(crate) struct NoMainErr {
1237 pub sp: Span,
1238 pub crate_name: Symbol,
1239 pub has_filename: bool,
1240 pub filename: PathBuf,
1241 pub file_empty: bool,
1242 pub non_main_fns: Vec<Span>,
1243 pub main_def_opt: Option<MainDefinition>,
1244 pub add_teach_note: bool,
1245}
1246
1247impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NoMainErr {
1248 #[track_caller]
1249 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
1250 let mut diag = Diag::new(dcx, level, fluent::passes_no_main_function);
1251 diag.span(DUMMY_SP);
1252 diag.code(E0601);
1253 diag.arg("crate_name", self.crate_name);
1254 diag.arg("filename", self.filename);
1255 diag.arg("has_filename", self.has_filename);
1256 let note = if !self.non_main_fns.is_empty() {
1257 for &span in &self.non_main_fns {
1258 diag.span_note(span, fluent::passes_here_is_main);
1259 }
1260 diag.note(fluent::passes_one_or_more_possible_main);
1261 diag.help(fluent::passes_consider_moving_main);
1262 fluent::passes_main_must_be_defined_at_crate
1264 } else if self.has_filename {
1265 fluent::passes_consider_adding_main_to_file
1266 } else {
1267 fluent::passes_consider_adding_main_at_crate
1268 };
1269 if self.file_empty {
1270 diag.note(note);
1271 } else {
1272 diag.span(self.sp.shrink_to_hi());
1273 diag.span_label(self.sp.shrink_to_hi(), note);
1274 }
1275
1276 if let Some(main_def) = self.main_def_opt
1277 && main_def.opt_fn_def_id().is_none()
1278 {
1279 diag.span_label(main_def.span, fluent::passes_non_function_main);
1281 }
1282
1283 if self.add_teach_note {
1284 diag.note(fluent::passes_teach_note);
1285 }
1286 diag
1287 }
1288}
1289
1290pub(crate) struct DuplicateLangItem {
1291 pub local_span: Option<Span>,
1292 pub lang_item_name: Symbol,
1293 pub crate_name: Symbol,
1294 pub dependency_of: Option<Symbol>,
1295 pub is_local: bool,
1296 pub path: String,
1297 pub first_defined_span: Option<Span>,
1298 pub orig_crate_name: Option<Symbol>,
1299 pub orig_dependency_of: Option<Symbol>,
1300 pub orig_is_local: bool,
1301 pub orig_path: String,
1302 pub(crate) duplicate: Duplicate,
1303}
1304
1305impl<G: EmissionGuarantee> Diagnostic<'_, G> for DuplicateLangItem {
1306 #[track_caller]
1307 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
1308 let mut diag = Diag::new(
1309 dcx,
1310 level,
1311 match self.duplicate {
1312 Duplicate::Plain => fluent::passes_duplicate_lang_item,
1313 Duplicate::Crate => fluent::passes_duplicate_lang_item_crate,
1314 Duplicate::CrateDepends => fluent::passes_duplicate_lang_item_crate_depends,
1315 },
1316 );
1317 diag.code(E0152);
1318 diag.arg("lang_item_name", self.lang_item_name);
1319 diag.arg("crate_name", self.crate_name);
1320 if let Some(dependency_of) = self.dependency_of {
1321 diag.arg("dependency_of", dependency_of);
1322 }
1323 diag.arg("path", self.path);
1324 if let Some(orig_crate_name) = self.orig_crate_name {
1325 diag.arg("orig_crate_name", orig_crate_name);
1326 }
1327 if let Some(orig_dependency_of) = self.orig_dependency_of {
1328 diag.arg("orig_dependency_of", orig_dependency_of);
1329 }
1330 diag.arg("orig_path", self.orig_path);
1331 if let Some(span) = self.local_span {
1332 diag.span(span);
1333 }
1334 if let Some(span) = self.first_defined_span {
1335 diag.span_note(span, fluent::passes_first_defined_span);
1336 } else {
1337 if self.orig_dependency_of.is_none() {
1338 diag.note(fluent::passes_first_defined_crate);
1339 } else {
1340 diag.note(fluent::passes_first_defined_crate_depends);
1341 }
1342
1343 if self.orig_is_local {
1344 diag.note(fluent::passes_first_definition_local);
1345 } else {
1346 diag.note(fluent::passes_first_definition_path);
1347 }
1348
1349 if self.is_local {
1350 diag.note(fluent::passes_second_definition_local);
1351 } else {
1352 diag.note(fluent::passes_second_definition_path);
1353 }
1354 }
1355 diag
1356 }
1357}
1358
1359#[derive(Diagnostic)]
1360#[diag(passes_incorrect_target, code = E0718)]
1361pub(crate) struct IncorrectTarget<'a> {
1362 #[primary_span]
1363 pub span: Span,
1364 #[label]
1365 pub generics_span: Span,
1366 pub name: &'a str, pub kind: &'static str,
1368 pub num: usize,
1369 pub actual_num: usize,
1370 pub at_least: bool,
1371}
1372
1373#[derive(Diagnostic)]
1374#[diag(passes_incorrect_crate_type)]
1375pub(crate) struct IncorrectCrateType {
1376 #[primary_span]
1377 pub span: Span,
1378}
1379
1380#[derive(LintDiagnostic)]
1381#[diag(passes_useless_assignment)]
1382pub(crate) struct UselessAssignment<'a> {
1383 pub is_field_assign: bool,
1384 pub ty: Ty<'a>,
1385}
1386
1387#[derive(LintDiagnostic)]
1388#[diag(passes_only_has_effect_on)]
1389pub(crate) struct OnlyHasEffectOn {
1390 pub attr_name: String,
1391 pub target_name: String,
1392}
1393
1394#[derive(LintDiagnostic)]
1395#[diag(passes_inline_ignored_for_exported)]
1396#[help]
1397pub(crate) struct InlineIgnoredForExported {}
1398
1399#[derive(Diagnostic)]
1400#[diag(passes_object_lifetime_err)]
1401pub(crate) struct ObjectLifetimeErr {
1402 #[primary_span]
1403 pub span: Span,
1404 pub repr: String,
1405}
1406
1407#[derive(Diagnostic)]
1408pub(crate) enum AttrApplication {
1409 #[diag(passes_attr_application_enum, code = E0517)]
1410 Enum {
1411 #[primary_span]
1412 hint_span: Span,
1413 #[label]
1414 span: Span,
1415 },
1416 #[diag(passes_attr_application_struct, code = E0517)]
1417 Struct {
1418 #[primary_span]
1419 hint_span: Span,
1420 #[label]
1421 span: Span,
1422 },
1423 #[diag(passes_attr_application_struct_union, code = E0517)]
1424 StructUnion {
1425 #[primary_span]
1426 hint_span: Span,
1427 #[label]
1428 span: Span,
1429 },
1430 #[diag(passes_attr_application_struct_enum_union, code = E0517)]
1431 StructEnumUnion {
1432 #[primary_span]
1433 hint_span: Span,
1434 #[label]
1435 span: Span,
1436 },
1437 #[diag(passes_attr_application_struct_enum_function_method_union, code = E0517)]
1438 StructEnumFunctionMethodUnion {
1439 #[primary_span]
1440 hint_span: Span,
1441 #[label]
1442 span: Span,
1443 },
1444}
1445
1446#[derive(Diagnostic)]
1447#[diag(passes_transparent_incompatible, code = E0692)]
1448pub(crate) struct TransparentIncompatible {
1449 #[primary_span]
1450 pub hint_spans: Vec<Span>,
1451 pub target: String,
1452}
1453
1454#[derive(Diagnostic)]
1455#[diag(passes_deprecated_attribute, code = E0549)]
1456pub(crate) struct DeprecatedAttribute {
1457 #[primary_span]
1458 pub span: Span,
1459}
1460
1461#[derive(Diagnostic)]
1462#[diag(passes_useless_stability)]
1463pub(crate) struct UselessStability {
1464 #[primary_span]
1465 #[label]
1466 pub span: Span,
1467 #[label(passes_item)]
1468 pub item_sp: Span,
1469}
1470
1471#[derive(Diagnostic)]
1472#[diag(passes_cannot_stabilize_deprecated)]
1473pub(crate) struct CannotStabilizeDeprecated {
1474 #[primary_span]
1475 #[label]
1476 pub span: Span,
1477 #[label(passes_item)]
1478 pub item_sp: Span,
1479}
1480
1481#[derive(Diagnostic)]
1482#[diag(passes_unstable_attr_for_already_stable_feature)]
1483pub(crate) struct UnstableAttrForAlreadyStableFeature {
1484 #[primary_span]
1485 #[label]
1486 #[help]
1487 pub span: Span,
1488 #[label(passes_item)]
1489 pub item_sp: Span,
1490}
1491
1492#[derive(Diagnostic)]
1493#[diag(passes_missing_stability_attr)]
1494pub(crate) struct MissingStabilityAttr<'a> {
1495 #[primary_span]
1496 pub span: Span,
1497 pub descr: &'a str,
1498}
1499
1500#[derive(Diagnostic)]
1501#[diag(passes_missing_const_stab_attr)]
1502pub(crate) struct MissingConstStabAttr<'a> {
1503 #[primary_span]
1504 pub span: Span,
1505 pub descr: &'a str,
1506}
1507
1508#[derive(Diagnostic)]
1509#[diag(passes_trait_impl_const_stable)]
1510#[note]
1511pub(crate) struct TraitImplConstStable {
1512 #[primary_span]
1513 pub span: Span,
1514}
1515
1516#[derive(Diagnostic)]
1517#[diag(passes_trait_impl_const_stability_mismatch)]
1518pub(crate) struct TraitImplConstStabilityMismatch {
1519 #[primary_span]
1520 pub span: Span,
1521 #[subdiagnostic]
1522 pub impl_stability: ImplConstStability,
1523 #[subdiagnostic]
1524 pub trait_stability: TraitConstStability,
1525}
1526
1527#[derive(Subdiagnostic)]
1528pub(crate) enum TraitConstStability {
1529 #[note(passes_trait_impl_const_stability_mismatch_trait_stable)]
1530 Stable {
1531 #[primary_span]
1532 span: Span,
1533 },
1534 #[note(passes_trait_impl_const_stability_mismatch_trait_unstable)]
1535 Unstable {
1536 #[primary_span]
1537 span: Span,
1538 },
1539}
1540
1541#[derive(Subdiagnostic)]
1542pub(crate) enum ImplConstStability {
1543 #[note(passes_trait_impl_const_stability_mismatch_impl_stable)]
1544 Stable {
1545 #[primary_span]
1546 span: Span,
1547 },
1548 #[note(passes_trait_impl_const_stability_mismatch_impl_unstable)]
1549 Unstable {
1550 #[primary_span]
1551 span: Span,
1552 },
1553}
1554
1555#[derive(Diagnostic)]
1556#[diag(passes_unknown_feature, code = E0635)]
1557pub(crate) struct UnknownFeature {
1558 #[primary_span]
1559 pub span: Span,
1560 pub feature: Symbol,
1561}
1562
1563#[derive(Diagnostic)]
1564#[diag(passes_implied_feature_not_exist)]
1565pub(crate) struct ImpliedFeatureNotExist {
1566 #[primary_span]
1567 pub span: Span,
1568 pub feature: Symbol,
1569 pub implied_by: Symbol,
1570}
1571
1572#[derive(Diagnostic)]
1573#[diag(passes_duplicate_feature_err, code = E0636)]
1574pub(crate) struct DuplicateFeatureErr {
1575 #[primary_span]
1576 pub span: Span,
1577 pub feature: Symbol,
1578}
1579
1580#[derive(Diagnostic)]
1581#[diag(passes_missing_const_err)]
1582pub(crate) struct MissingConstErr {
1583 #[primary_span]
1584 #[help]
1585 pub fn_sig_span: Span,
1586}
1587
1588#[derive(Diagnostic)]
1589#[diag(passes_const_stable_not_stable)]
1590pub(crate) struct ConstStableNotStable {
1591 #[primary_span]
1592 pub fn_sig_span: Span,
1593 #[label]
1594 pub const_span: Span,
1595}
1596
1597#[derive(LintDiagnostic)]
1598pub(crate) enum MultipleDeadCodes<'tcx> {
1599 #[diag(passes_dead_codes)]
1600 DeadCodes {
1601 multiple: bool,
1602 num: usize,
1603 descr: &'tcx str,
1604 participle: &'tcx str,
1605 name_list: DiagSymbolList,
1606 #[subdiagnostic]
1607 parent_info: Option<ParentInfo<'tcx>>,
1608 #[subdiagnostic]
1609 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1610 },
1611 #[diag(passes_dead_codes)]
1612 UnusedTupleStructFields {
1613 multiple: bool,
1614 num: usize,
1615 descr: &'tcx str,
1616 participle: &'tcx str,
1617 name_list: DiagSymbolList,
1618 #[subdiagnostic]
1619 change_fields_suggestion: ChangeFields,
1620 #[subdiagnostic]
1621 parent_info: Option<ParentInfo<'tcx>>,
1622 #[subdiagnostic]
1623 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1624 },
1625}
1626
1627#[derive(Subdiagnostic)]
1628#[label(passes_parent_info)]
1629pub(crate) struct ParentInfo<'tcx> {
1630 pub num: usize,
1631 pub descr: &'tcx str,
1632 pub parent_descr: &'tcx str,
1633 #[primary_span]
1634 pub span: Span,
1635}
1636
1637#[derive(Subdiagnostic)]
1638#[note(passes_ignored_derived_impls)]
1639pub(crate) struct IgnoredDerivedImpls {
1640 pub name: Symbol,
1641 pub trait_list: DiagSymbolList,
1642 pub trait_list_len: usize,
1643}
1644
1645#[derive(Subdiagnostic)]
1646pub(crate) enum ChangeFields {
1647 #[multipart_suggestion(
1648 passes_change_fields_to_be_of_unit_type,
1649 applicability = "has-placeholders"
1650 )]
1651 ChangeToUnitTypeOrRemove {
1652 num: usize,
1653 #[suggestion_part(code = "()")]
1654 spans: Vec<Span>,
1655 },
1656 #[help(passes_remove_fields)]
1657 Remove { num: usize },
1658}
1659
1660#[derive(Diagnostic)]
1661#[diag(passes_proc_macro_bad_sig)]
1662pub(crate) struct ProcMacroBadSig {
1663 #[primary_span]
1664 pub span: Span,
1665 pub kind: ProcMacroKind,
1666}
1667
1668#[derive(LintDiagnostic)]
1669#[diag(passes_unreachable_due_to_uninhabited)]
1670pub(crate) struct UnreachableDueToUninhabited<'desc, 'tcx> {
1671 pub descr: &'desc str,
1672 #[label]
1673 pub expr: Span,
1674 #[label(passes_label_orig)]
1675 #[note]
1676 pub orig: Span,
1677 pub ty: Ty<'tcx>,
1678}
1679
1680#[derive(LintDiagnostic)]
1681#[diag(passes_unused_var_maybe_capture_ref)]
1682#[help]
1683pub(crate) struct UnusedVarMaybeCaptureRef {
1684 pub name: String,
1685}
1686
1687#[derive(LintDiagnostic)]
1688#[diag(passes_unused_capture_maybe_capture_ref)]
1689#[help]
1690pub(crate) struct UnusedCaptureMaybeCaptureRef {
1691 pub name: String,
1692}
1693
1694#[derive(LintDiagnostic)]
1695#[diag(passes_unused_var_remove_field)]
1696pub(crate) struct UnusedVarRemoveField {
1697 pub name: String,
1698 #[subdiagnostic]
1699 pub sugg: UnusedVarRemoveFieldSugg,
1700}
1701
1702#[derive(Subdiagnostic)]
1703#[multipart_suggestion(
1704 passes_unused_var_remove_field_suggestion,
1705 applicability = "machine-applicable"
1706)]
1707pub(crate) struct UnusedVarRemoveFieldSugg {
1708 #[suggestion_part(code = "")]
1709 pub spans: Vec<Span>,
1710}
1711
1712#[derive(LintDiagnostic)]
1713#[diag(passes_unused_var_assigned_only)]
1714#[note]
1715pub(crate) struct UnusedVarAssignedOnly {
1716 pub name: String,
1717}
1718
1719#[derive(LintDiagnostic)]
1720#[diag(passes_unnecessary_stable_feature)]
1721pub(crate) struct UnnecessaryStableFeature {
1722 pub feature: Symbol,
1723 pub since: Symbol,
1724}
1725
1726#[derive(LintDiagnostic)]
1727#[diag(passes_unnecessary_partial_stable_feature)]
1728pub(crate) struct UnnecessaryPartialStableFeature {
1729 #[suggestion(code = "{implies}", applicability = "maybe-incorrect")]
1730 pub span: Span,
1731 #[suggestion(passes_suggestion_remove, code = "", applicability = "maybe-incorrect")]
1732 pub line: Span,
1733 pub feature: Symbol,
1734 pub since: Symbol,
1735 pub implies: Symbol,
1736}
1737
1738#[derive(LintDiagnostic)]
1739#[diag(passes_ineffective_unstable_impl)]
1740#[note]
1741pub(crate) struct IneffectiveUnstableImpl;
1742
1743#[derive(LintDiagnostic)]
1744#[diag(passes_unused_assign)]
1745pub(crate) struct UnusedAssign {
1746 pub name: String,
1747 #[subdiagnostic]
1748 pub suggestion: Option<UnusedAssignSuggestion>,
1749 #[help]
1750 pub help: bool,
1751}
1752
1753#[derive(Subdiagnostic)]
1754#[multipart_suggestion(passes_unused_assign_suggestion, applicability = "maybe-incorrect")]
1755pub(crate) struct UnusedAssignSuggestion {
1756 pub pre: &'static str,
1757 #[suggestion_part(code = "{pre}mut ")]
1758 pub ty_span: Option<Span>,
1759 #[suggestion_part(code = "")]
1760 pub ty_ref_span: Span,
1761 #[suggestion_part(code = "*")]
1762 pub ident_span: Span,
1763 #[suggestion_part(code = "")]
1764 pub expr_ref_span: Span,
1765}
1766
1767#[derive(LintDiagnostic)]
1768#[diag(passes_unused_assign_passed)]
1769#[help]
1770pub(crate) struct UnusedAssignPassed {
1771 pub name: String,
1772}
1773
1774#[derive(LintDiagnostic)]
1775#[diag(passes_unused_variable_try_prefix)]
1776pub(crate) struct UnusedVariableTryPrefix {
1777 #[label]
1778 pub label: Option<Span>,
1779 #[subdiagnostic]
1780 pub string_interp: Vec<UnusedVariableStringInterp>,
1781 #[subdiagnostic]
1782 pub sugg: UnusedVariableSugg,
1783 pub name: String,
1784}
1785
1786#[derive(Subdiagnostic)]
1787pub(crate) enum UnusedVariableSugg {
1788 #[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")]
1789 TryPrefixSugg {
1790 #[suggestion_part(code = "_{name}")]
1791 spans: Vec<Span>,
1792 name: String,
1793 },
1794 #[help(passes_unused_variable_args_in_macro)]
1795 NoSugg {
1796 #[primary_span]
1797 span: Span,
1798 name: String,
1799 },
1800}
1801
1802pub(crate) struct UnusedVariableStringInterp {
1803 pub lit: Span,
1804 pub lo: Span,
1805 pub hi: Span,
1806}
1807
1808impl Subdiagnostic for UnusedVariableStringInterp {
1809 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1810 diag.span_label(self.lit, crate::fluent_generated::passes_maybe_string_interpolation);
1811 diag.multipart_suggestion(
1812 crate::fluent_generated::passes_string_interpolation_only_works,
1813 vec![(self.lo, String::from("format!(")), (self.hi, String::from(")"))],
1814 Applicability::MachineApplicable,
1815 );
1816 }
1817}
1818
1819#[derive(LintDiagnostic)]
1820#[diag(passes_unused_variable_try_ignore)]
1821pub(crate) struct UnusedVarTryIgnore {
1822 #[subdiagnostic]
1823 pub sugg: UnusedVarTryIgnoreSugg,
1824}
1825
1826#[derive(Subdiagnostic)]
1827#[multipart_suggestion(passes_suggestion, applicability = "maybe-incorrect")]
1828pub(crate) struct UnusedVarTryIgnoreSugg {
1829 #[suggestion_part(code = "{name}: _")]
1830 pub shorthands: Vec<Span>,
1831 #[suggestion_part(code = "_")]
1832 pub non_shorthands: Vec<Span>,
1833 pub name: String,
1834}
1835
1836#[derive(LintDiagnostic)]
1837#[diag(passes_attr_crate_level)]
1838#[note]
1839pub(crate) struct AttrCrateLevelOnly {
1840 #[subdiagnostic]
1841 pub sugg: Option<AttrCrateLevelOnlySugg>,
1842}
1843
1844#[derive(Subdiagnostic)]
1845#[suggestion(passes_suggestion, applicability = "maybe-incorrect", code = "!", style = "verbose")]
1846pub(crate) struct AttrCrateLevelOnlySugg {
1847 #[primary_span]
1848 pub attr: Span,
1849}
1850
1851#[derive(Diagnostic)]
1852#[diag(passes_no_sanitize)]
1853pub(crate) struct NoSanitize<'a> {
1854 #[primary_span]
1855 pub attr_span: Span,
1856 #[label]
1857 pub defn_span: Span,
1858 pub accepted_kind: &'a str,
1859 pub attr_str: &'a str,
1860}
1861
1862#[derive(Diagnostic)]
1864#[diag(passes_rustc_const_stable_indirect_pairing)]
1865pub(crate) struct RustcConstStableIndirectPairing {
1866 #[primary_span]
1867 pub span: Span,
1868}
1869
1870#[derive(Diagnostic)]
1871#[diag(passes_unsupported_attributes_in_where)]
1872#[help]
1873pub(crate) struct UnsupportedAttributesInWhere {
1874 #[primary_span]
1875 pub span: MultiSpan,
1876}
1877
1878#[derive(Diagnostic)]
1879pub(crate) enum UnexportableItem<'a> {
1880 #[diag(passes_unexportable_item)]
1881 Item {
1882 #[primary_span]
1883 span: Span,
1884 descr: &'a str,
1885 },
1886
1887 #[diag(passes_unexportable_generic_fn)]
1888 GenericFn(#[primary_span] Span),
1889
1890 #[diag(passes_unexportable_fn_abi)]
1891 FnAbi(#[primary_span] Span),
1892
1893 #[diag(passes_unexportable_type_repr)]
1894 TypeRepr(#[primary_span] Span),
1895
1896 #[diag(passes_unexportable_type_in_interface)]
1897 TypeInInterface {
1898 #[primary_span]
1899 span: Span,
1900 desc: &'a str,
1901 ty: &'a str,
1902 #[label]
1903 ty_span: Span,
1904 },
1905
1906 #[diag(passes_unexportable_priv_item)]
1907 PrivItem {
1908 #[primary_span]
1909 span: Span,
1910 #[note]
1911 vis_note: Span,
1912 vis_descr: &'a str,
1913 },
1914
1915 #[diag(passes_unexportable_adt_with_private_fields)]
1916 AdtWithPrivFields {
1917 #[primary_span]
1918 span: Span,
1919 #[note]
1920 vis_note: Span,
1921 field_name: &'a str,
1922 },
1923}