1use std::io::Error;
2use std::path::{Path, PathBuf};
3
4use rustc_errors::codes::*;
5use rustc_errors::{
6 Applicability, Diag, DiagCtxtHandle, DiagSymbolList, Diagnostic, EmissionGuarantee, Level,
7 MultiSpan,
8};
9use rustc_hir::Target;
10use rustc_hir::attrs::{MirDialect, MirPhase};
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(Diagnostic)]
36#[diag(passes_loop_match_attr)]
37pub(crate) struct LoopMatchAttr {
38 #[primary_span]
39 pub attr_span: Span,
40 #[label]
41 pub node_span: Span,
42}
43
44#[derive(Diagnostic)]
45#[diag(passes_const_continue_attr)]
46pub(crate) struct ConstContinueAttr {
47 #[primary_span]
48 pub attr_span: Span,
49 #[label]
50 pub node_span: Span,
51}
52
53#[derive(LintDiagnostic)]
54#[diag(passes_mixed_export_name_and_no_mangle)]
55pub(crate) struct MixedExportNameAndNoMangle {
56 #[label]
57 #[suggestion(style = "verbose", code = "", applicability = "machine-applicable")]
58 pub no_mangle_span: Span,
59 #[note]
60 pub export_name_span: Span,
61 pub no_mangle_attr: &'static str,
62 pub export_name_attr: &'static str,
63}
64
65#[derive(LintDiagnostic)]
66#[diag(passes_outer_crate_level_attr)]
67pub(crate) struct OuterCrateLevelAttr {
68 #[subdiagnostic]
69 pub suggestion: OuterCrateLevelAttrSuggestion,
70}
71
72#[derive(Subdiagnostic)]
73#[multipart_suggestion(passes_outer_crate_level_attr_suggestion, style = "verbose")]
74pub(crate) struct OuterCrateLevelAttrSuggestion {
75 #[suggestion_part(code = "!")]
76 pub bang_position: Span,
77}
78
79#[derive(LintDiagnostic)]
80#[diag(passes_inner_crate_level_attr)]
81pub(crate) struct InnerCrateLevelAttr;
82
83#[derive(LintDiagnostic)]
84#[diag(passes_ignored_attr_with_macro)]
85pub(crate) struct IgnoredAttrWithMacro<'a> {
86 pub sym: &'a str,
87}
88
89#[derive(Diagnostic)]
90#[diag(passes_should_be_applied_to_fn)]
91pub(crate) struct AttrShouldBeAppliedToFn {
92 #[primary_span]
93 pub attr_span: Span,
94 #[label]
95 pub defn_span: Span,
96 pub on_crate: bool,
97}
98
99#[derive(Diagnostic)]
100#[diag(passes_non_exhaustive_with_default_field_values)]
101pub(crate) struct NonExhaustiveWithDefaultFieldValues {
102 #[primary_span]
103 pub attr_span: Span,
104 #[label]
105 pub defn_span: Span,
106}
107
108#[derive(Diagnostic)]
109#[diag(passes_should_be_applied_to_trait)]
110pub(crate) struct AttrShouldBeAppliedToTrait {
111 #[primary_span]
112 pub attr_span: Span,
113 #[label]
114 pub defn_span: Span,
115}
116
117#[derive(Diagnostic)]
118#[diag(passes_should_be_applied_to_static)]
119pub(crate) struct AttrShouldBeAppliedToStatic {
120 #[primary_span]
121 pub attr_span: Span,
122 #[label]
123 pub defn_span: Span,
124}
125
126#[derive(Diagnostic)]
127#[diag(passes_doc_expect_str)]
128pub(crate) struct DocExpectStr<'a> {
129 #[primary_span]
130 pub attr_span: Span,
131 pub attr_name: &'a str,
132}
133
134#[derive(Diagnostic)]
135#[diag(passes_doc_alias_empty)]
136pub(crate) struct DocAliasEmpty<'a> {
137 #[primary_span]
138 pub span: Span,
139 pub attr_str: &'a str,
140}
141
142#[derive(Diagnostic)]
143#[diag(passes_doc_alias_bad_char)]
144pub(crate) struct DocAliasBadChar<'a> {
145 #[primary_span]
146 pub span: Span,
147 pub attr_str: &'a str,
148 pub char_: char,
149}
150
151#[derive(Diagnostic)]
152#[diag(passes_doc_alias_start_end)]
153pub(crate) struct DocAliasStartEnd<'a> {
154 #[primary_span]
155 pub span: Span,
156 pub attr_str: &'a str,
157}
158
159#[derive(Diagnostic)]
160#[diag(passes_doc_alias_bad_location)]
161pub(crate) struct DocAliasBadLocation<'a> {
162 #[primary_span]
163 pub span: Span,
164 pub attr_str: &'a str,
165 pub location: &'a str,
166}
167
168#[derive(Diagnostic)]
169#[diag(passes_doc_alias_not_an_alias)]
170pub(crate) struct DocAliasNotAnAlias<'a> {
171 #[primary_span]
172 pub span: Span,
173 pub attr_str: &'a str,
174}
175
176#[derive(LintDiagnostic)]
177#[diag(passes_doc_alias_duplicated)]
178pub(crate) struct DocAliasDuplicated {
179 #[label]
180 pub first_defn: Span,
181}
182
183#[derive(Diagnostic)]
184#[diag(passes_doc_alias_not_string_literal)]
185pub(crate) struct DocAliasNotStringLiteral {
186 #[primary_span]
187 pub span: Span,
188}
189
190#[derive(Diagnostic)]
191#[diag(passes_doc_alias_malformed)]
192pub(crate) struct DocAliasMalformed {
193 #[primary_span]
194 pub span: Span,
195}
196
197#[derive(Diagnostic)]
198#[diag(passes_doc_keyword_attribute_empty_mod)]
199pub(crate) struct DocKeywordAttributeEmptyMod {
200 #[primary_span]
201 pub span: Span,
202 pub attr_name: &'static str,
203}
204
205#[derive(Diagnostic)]
206#[diag(passes_doc_keyword_not_keyword)]
207#[help]
208pub(crate) struct DocKeywordNotKeyword {
209 #[primary_span]
210 pub span: Span,
211 pub keyword: Symbol,
212}
213
214#[derive(Diagnostic)]
215#[diag(passes_doc_attribute_not_attribute)]
216#[help]
217pub(crate) struct DocAttributeNotAttribute {
218 #[primary_span]
219 pub span: Span,
220 pub attribute: Symbol,
221}
222
223#[derive(Diagnostic)]
224#[diag(passes_doc_keyword_attribute_not_mod)]
225pub(crate) struct DocKeywordAttributeNotMod {
226 #[primary_span]
227 pub span: Span,
228 pub attr_name: &'static str,
229}
230
231#[derive(Diagnostic)]
232#[diag(passes_doc_fake_variadic_not_valid)]
233pub(crate) struct DocFakeVariadicNotValid {
234 #[primary_span]
235 pub span: Span,
236}
237
238#[derive(Diagnostic)]
239#[diag(passes_doc_keyword_only_impl)]
240pub(crate) struct DocKeywordOnlyImpl {
241 #[primary_span]
242 pub span: Span,
243}
244
245#[derive(Diagnostic)]
246#[diag(passes_doc_search_unbox_invalid)]
247pub(crate) struct DocSearchUnboxInvalid {
248 #[primary_span]
249 pub span: Span,
250}
251
252#[derive(Diagnostic)]
253#[diag(passes_doc_inline_conflict)]
254#[help]
255pub(crate) struct DocKeywordConflict {
256 #[primary_span]
257 pub spans: MultiSpan,
258}
259
260#[derive(LintDiagnostic)]
261#[diag(passes_doc_inline_only_use)]
262#[note]
263pub(crate) struct DocInlineOnlyUse {
264 #[label]
265 pub attr_span: Span,
266 #[label(passes_not_a_use_item_label)]
267 pub item_span: Option<Span>,
268}
269
270#[derive(LintDiagnostic)]
271#[diag(passes_doc_masked_only_extern_crate)]
272#[note]
273pub(crate) struct DocMaskedOnlyExternCrate {
274 #[label]
275 pub attr_span: Span,
276 #[label(passes_not_an_extern_crate_label)]
277 pub item_span: Option<Span>,
278}
279
280#[derive(LintDiagnostic)]
281#[diag(passes_doc_masked_not_extern_crate_self)]
282pub(crate) struct DocMaskedNotExternCrateSelf {
283 #[label]
284 pub attr_span: Span,
285 #[label(passes_extern_crate_self_label)]
286 pub item_span: Option<Span>,
287}
288
289#[derive(Diagnostic)]
290#[diag(passes_doc_attr_not_crate_level)]
291pub(crate) struct DocAttrNotCrateLevel<'a> {
292 #[primary_span]
293 pub span: Span,
294 pub attr_name: &'a str,
295}
296
297#[derive(LintDiagnostic)]
298#[diag(passes_doc_test_unknown)]
299pub(crate) struct DocTestUnknown {
300 pub path: String,
301}
302
303#[derive(LintDiagnostic)]
304#[diag(passes_doc_test_literal)]
305pub(crate) struct DocTestLiteral;
306
307#[derive(LintDiagnostic)]
308#[diag(passes_doc_test_takes_list)]
309pub(crate) struct DocTestTakesList;
310
311#[derive(LintDiagnostic)]
312#[diag(passes_doc_auto_cfg_wrong_literal)]
313pub(crate) struct DocAutoCfgWrongLiteral;
314
315#[derive(LintDiagnostic)]
316#[diag(passes_doc_auto_cfg_expects_hide_or_show)]
317pub(crate) struct DocAutoCfgExpectsHideOrShow;
318
319#[derive(LintDiagnostic)]
320#[diag(passes_doc_auto_cfg_hide_show_expects_list)]
321pub(crate) struct DocAutoCfgHideShowExpectsList {
322 pub attr_name: Symbol,
323}
324
325#[derive(LintDiagnostic)]
326#[diag(passes_doc_auto_cfg_hide_show_unexpected_item)]
327pub(crate) struct DocAutoCfgHideShowUnexpectedItem {
328 pub attr_name: Symbol,
329}
330
331#[derive(LintDiagnostic)]
332#[diag(passes_doc_test_unknown_any)]
333pub(crate) struct DocTestUnknownAny {
334 pub path: String,
335}
336
337#[derive(LintDiagnostic)]
338#[diag(passes_doc_test_unknown_spotlight)]
339#[note]
340#[note(passes_no_op_note)]
341pub(crate) struct DocTestUnknownSpotlight {
342 pub path: String,
343 #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")]
344 pub span: Span,
345}
346
347#[derive(LintDiagnostic)]
348#[diag(passes_doc_test_unknown_passes)]
349#[note]
350#[note(passes_no_op_note)]
351pub(crate) struct DocTestUnknownPasses {
352 pub path: String,
353 #[label]
354 pub span: Span,
355}
356
357#[derive(LintDiagnostic)]
358#[diag(passes_doc_test_unknown_plugins)]
359#[note]
360#[note(passes_no_op_note)]
361pub(crate) struct DocTestUnknownPlugins {
362 pub path: String,
363 #[label]
364 pub span: Span,
365}
366
367#[derive(LintDiagnostic)]
368#[diag(passes_doc_test_unknown_include)]
369pub(crate) struct DocTestUnknownInclude {
370 pub path: String,
371 pub value: String,
372 pub inner: &'static str,
373 #[suggestion(code = "#{inner}[doc = include_str!(\"{value}\")]")]
374 pub sugg: (Span, Applicability),
375}
376
377#[derive(LintDiagnostic)]
378#[diag(passes_doc_invalid)]
379pub(crate) struct DocInvalid;
380
381#[derive(Diagnostic)]
382#[diag(passes_has_incoherent_inherent_impl)]
383pub(crate) struct HasIncoherentInherentImpl {
384 #[primary_span]
385 pub attr_span: Span,
386 #[label]
387 pub span: Span,
388}
389
390#[derive(Diagnostic)]
391#[diag(passes_both_ffi_const_and_pure, code = E0757)]
392pub(crate) struct BothFfiConstAndPure {
393 #[primary_span]
394 pub attr_span: Span,
395}
396
397#[derive(Diagnostic)]
398#[diag(passes_must_not_suspend)]
399pub(crate) struct MustNotSuspend {
400 #[primary_span]
401 pub attr_span: Span,
402 #[label]
403 pub span: Span,
404}
405
406#[derive(LintDiagnostic)]
407#[diag(passes_link)]
408#[warning]
409pub(crate) struct Link {
410 #[label]
411 pub span: Option<Span>,
412}
413
414#[derive(Diagnostic)]
415#[diag(passes_no_link)]
416pub(crate) struct NoLink {
417 #[primary_span]
418 pub attr_span: Span,
419 #[label]
420 pub span: Span,
421}
422
423#[derive(Diagnostic)]
424#[diag(passes_rustc_legacy_const_generics_only)]
425pub(crate) struct RustcLegacyConstGenericsOnly {
426 #[primary_span]
427 pub attr_span: Span,
428 #[label]
429 pub param_span: Span,
430}
431
432#[derive(Diagnostic)]
433#[diag(passes_rustc_legacy_const_generics_index)]
434pub(crate) struct RustcLegacyConstGenericsIndex {
435 #[primary_span]
436 pub attr_span: Span,
437 #[label]
438 pub generics_span: Span,
439}
440
441#[derive(Diagnostic)]
442#[diag(passes_rustc_legacy_const_generics_index_exceed)]
443pub(crate) struct RustcLegacyConstGenericsIndexExceed {
444 #[primary_span]
445 #[label]
446 pub span: Span,
447 pub arg_count: usize,
448}
449
450#[derive(Diagnostic)]
451#[diag(passes_rustc_legacy_const_generics_index_negative)]
452pub(crate) struct RustcLegacyConstGenericsIndexNegative {
453 #[primary_span]
454 pub invalid_args: Vec<Span>,
455}
456
457#[derive(Diagnostic)]
458#[diag(passes_rustc_dirty_clean)]
459pub(crate) struct RustcDirtyClean {
460 #[primary_span]
461 pub span: Span,
462}
463
464#[derive(Diagnostic)]
465#[diag(passes_repr_conflicting, code = E0566)]
466pub(crate) struct ReprConflicting {
467 #[primary_span]
468 pub hint_spans: Vec<Span>,
469}
470
471#[derive(Diagnostic)]
472#[diag(passes_repr_align_greater_than_target_max, code = E0589)]
473#[note]
474pub(crate) struct InvalidReprAlignForTarget {
475 #[primary_span]
476 pub span: Span,
477 pub size: u64,
478}
479
480#[derive(LintDiagnostic)]
481#[diag(passes_repr_conflicting, code = E0566)]
482pub(crate) struct ReprConflictingLint;
483
484#[derive(Diagnostic)]
485#[diag(passes_macro_only_attribute)]
486pub(crate) struct MacroOnlyAttribute {
487 #[primary_span]
488 pub attr_span: Span,
489 #[label]
490 pub span: Span,
491}
492
493#[derive(Diagnostic)]
494#[diag(passes_debug_visualizer_unreadable)]
495pub(crate) struct DebugVisualizerUnreadable<'a> {
496 #[primary_span]
497 pub span: Span,
498 pub file: &'a Path,
499 pub error: Error,
500}
501
502#[derive(Diagnostic)]
503#[diag(passes_rustc_allow_const_fn_unstable)]
504pub(crate) struct RustcAllowConstFnUnstable {
505 #[primary_span]
506 pub attr_span: Span,
507 #[label]
508 pub span: Span,
509}
510
511#[derive(Diagnostic)]
512#[diag(passes_rustc_pub_transparent)]
513pub(crate) struct RustcPubTransparent {
514 #[primary_span]
515 pub attr_span: Span,
516 #[label]
517 pub span: Span,
518}
519
520#[derive(Diagnostic)]
521#[diag(passes_rustc_force_inline_coro)]
522pub(crate) struct RustcForceInlineCoro {
523 #[primary_span]
524 pub attr_span: Span,
525 #[label]
526 pub span: Span,
527}
528
529#[derive(LintDiagnostic)]
530pub(crate) enum MacroExport {
531 #[diag(passes_macro_export_on_decl_macro)]
532 #[note]
533 OnDeclMacro,
534}
535
536#[derive(Subdiagnostic)]
537pub(crate) enum UnusedNote {
538 #[note(passes_unused_empty_lints_note)]
539 EmptyList { name: Symbol },
540 #[note(passes_unused_no_lints_note)]
541 NoLints { name: Symbol },
542 #[note(passes_unused_default_method_body_const_note)]
543 DefaultMethodBodyConst,
544 #[note(passes_unused_linker_messages_note)]
545 LinkerMessagesBinaryCrateOnly,
546}
547
548#[derive(LintDiagnostic)]
549#[diag(passes_unused)]
550pub(crate) struct Unused {
551 #[suggestion(code = "", applicability = "machine-applicable")]
552 pub attr_span: Span,
553 #[subdiagnostic]
554 pub note: UnusedNote,
555}
556
557#[derive(Diagnostic)]
558#[diag(passes_non_exported_macro_invalid_attrs, code = E0518)]
559pub(crate) struct NonExportedMacroInvalidAttrs {
560 #[primary_span]
561 #[label]
562 pub attr_span: Span,
563}
564
565#[derive(Diagnostic)]
566#[diag(passes_may_dangle)]
567pub(crate) struct InvalidMayDangle {
568 #[primary_span]
569 pub attr_span: Span,
570}
571
572#[derive(LintDiagnostic)]
573#[diag(passes_unused_duplicate)]
574pub(crate) struct UnusedDuplicate {
575 #[suggestion(code = "", applicability = "machine-applicable")]
576 pub this: Span,
577 #[note]
578 pub other: Span,
579 #[warning]
580 pub warning: bool,
581}
582
583#[derive(Diagnostic)]
584#[diag(passes_unused_multiple)]
585pub(crate) struct UnusedMultiple {
586 #[primary_span]
587 #[suggestion(code = "", applicability = "machine-applicable")]
588 pub this: Span,
589 #[note]
590 pub other: Span,
591 pub name: Symbol,
592}
593
594#[derive(Diagnostic)]
595#[diag(passes_rustc_lint_opt_ty)]
596pub(crate) struct RustcLintOptTy {
597 #[primary_span]
598 pub attr_span: Span,
599 #[label]
600 pub span: Span,
601}
602
603#[derive(Diagnostic)]
604#[diag(passes_rustc_lint_opt_deny_field_access)]
605pub(crate) struct RustcLintOptDenyFieldAccess {
606 #[primary_span]
607 pub attr_span: Span,
608 #[label]
609 pub span: Span,
610}
611
612#[derive(Diagnostic)]
613#[diag(passes_collapse_debuginfo)]
614pub(crate) struct CollapseDebuginfo {
615 #[primary_span]
616 pub attr_span: Span,
617 #[label]
618 pub defn_span: Span,
619}
620
621#[derive(LintDiagnostic)]
622#[diag(passes_deprecated_annotation_has_no_effect)]
623pub(crate) struct DeprecatedAnnotationHasNoEffect {
624 #[suggestion(applicability = "machine-applicable", code = "")]
625 pub span: Span,
626}
627
628#[derive(Diagnostic)]
629#[diag(passes_unknown_external_lang_item, code = E0264)]
630pub(crate) struct UnknownExternLangItem {
631 #[primary_span]
632 pub span: Span,
633 pub lang_item: Symbol,
634}
635
636#[derive(Diagnostic)]
637#[diag(passes_missing_panic_handler)]
638pub(crate) struct MissingPanicHandler;
639
640#[derive(Diagnostic)]
641#[diag(passes_panic_unwind_without_std)]
642#[help]
643#[note]
644pub(crate) struct PanicUnwindWithoutStd;
645
646#[derive(Diagnostic)]
647#[diag(passes_missing_lang_item)]
648#[note]
649#[help]
650pub(crate) struct MissingLangItem {
651 pub name: Symbol,
652}
653
654#[derive(Diagnostic)]
655#[diag(passes_lang_item_fn_with_track_caller)]
656pub(crate) struct LangItemWithTrackCaller {
657 #[primary_span]
658 pub attr_span: Span,
659 pub name: Symbol,
660 #[label]
661 pub sig_span: Span,
662}
663
664#[derive(Diagnostic)]
665#[diag(passes_lang_item_fn_with_target_feature)]
666pub(crate) struct LangItemWithTargetFeature {
667 #[primary_span]
668 pub attr_span: Span,
669 pub name: Symbol,
670 #[label]
671 pub sig_span: Span,
672}
673
674#[derive(Diagnostic)]
675#[diag(passes_lang_item_on_incorrect_target, code = E0718)]
676pub(crate) struct LangItemOnIncorrectTarget {
677 #[primary_span]
678 #[label]
679 pub span: Span,
680 pub name: Symbol,
681 pub expected_target: Target,
682 pub actual_target: Target,
683}
684
685#[derive(Diagnostic)]
686#[diag(passes_unknown_lang_item, code = E0522)]
687pub(crate) struct UnknownLangItem {
688 #[primary_span]
689 #[label]
690 pub span: Span,
691 pub name: Symbol,
692}
693
694pub(crate) struct InvalidAttrAtCrateLevel {
695 pub span: Span,
696 pub sugg_span: Option<Span>,
697 pub name: Symbol,
698 pub item: Option<ItemFollowingInnerAttr>,
699}
700
701#[derive(Clone, Copy)]
702pub(crate) struct ItemFollowingInnerAttr {
703 pub span: Span,
704 pub kind: &'static str,
705}
706
707impl<G: EmissionGuarantee> Diagnostic<'_, G> for InvalidAttrAtCrateLevel {
708 #[track_caller]
709 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
710 let mut diag = Diag::new(dcx, level, fluent::passes_invalid_attr_at_crate_level);
711 diag.span(self.span);
712 diag.arg("name", self.name);
713 if let Some(span) = self.sugg_span {
716 diag.span_suggestion_verbose(
717 span,
718 fluent::passes_suggestion,
719 String::new(),
720 Applicability::MachineApplicable,
721 );
722 }
723 if let Some(item) = self.item {
724 diag.arg("kind", item.kind);
725 diag.span_label(item.span, fluent::passes_invalid_attr_at_crate_level_item);
726 }
727 diag
728 }
729}
730
731#[derive(Diagnostic)]
732#[diag(passes_duplicate_diagnostic_item_in_crate)]
733pub(crate) struct DuplicateDiagnosticItemInCrate {
734 #[primary_span]
735 pub duplicate_span: Option<Span>,
736 #[note(passes_diagnostic_item_first_defined)]
737 pub orig_span: Option<Span>,
738 #[note]
739 pub different_crates: bool,
740 pub crate_name: Symbol,
741 pub orig_crate_name: Symbol,
742 pub name: Symbol,
743}
744
745#[derive(Diagnostic)]
746#[diag(passes_layout_abi)]
747pub(crate) struct LayoutAbi {
748 #[primary_span]
749 pub span: Span,
750 pub abi: String,
751}
752
753#[derive(Diagnostic)]
754#[diag(passes_layout_align)]
755pub(crate) struct LayoutAlign {
756 #[primary_span]
757 pub span: Span,
758 pub align: String,
759}
760
761#[derive(Diagnostic)]
762#[diag(passes_layout_size)]
763pub(crate) struct LayoutSize {
764 #[primary_span]
765 pub span: Span,
766 pub size: String,
767}
768
769#[derive(Diagnostic)]
770#[diag(passes_layout_homogeneous_aggregate)]
771pub(crate) struct LayoutHomogeneousAggregate {
772 #[primary_span]
773 pub span: Span,
774 pub homogeneous_aggregate: String,
775}
776
777#[derive(Diagnostic)]
778#[diag(passes_layout_of)]
779pub(crate) struct LayoutOf<'tcx> {
780 #[primary_span]
781 pub span: Span,
782 pub normalized_ty: Ty<'tcx>,
783 pub ty_layout: String,
784}
785
786#[derive(Diagnostic)]
787#[diag(passes_layout_invalid_attribute)]
788pub(crate) struct LayoutInvalidAttribute {
789 #[primary_span]
790 pub span: Span,
791}
792
793#[derive(Diagnostic)]
794#[diag(passes_abi_of)]
795pub(crate) struct AbiOf {
796 #[primary_span]
797 pub span: Span,
798 pub fn_name: Symbol,
799 pub fn_abi: String,
800}
801
802#[derive(Diagnostic)]
803#[diag(passes_abi_ne)]
804pub(crate) struct AbiNe {
805 #[primary_span]
806 pub span: Span,
807 pub left: String,
808 pub right: String,
809}
810
811#[derive(Diagnostic)]
812#[diag(passes_abi_invalid_attribute)]
813pub(crate) struct AbiInvalidAttribute {
814 #[primary_span]
815 pub span: Span,
816}
817
818#[derive(Diagnostic)]
819#[diag(passes_unrecognized_argument)]
820pub(crate) struct UnrecognizedArgument {
821 #[primary_span]
822 pub span: Span,
823}
824
825#[derive(Diagnostic)]
826#[diag(passes_feature_stable_twice, code = E0711)]
827pub(crate) struct FeatureStableTwice {
828 #[primary_span]
829 pub span: Span,
830 pub feature: Symbol,
831 pub since: Symbol,
832 pub prev_since: Symbol,
833}
834
835#[derive(Diagnostic)]
836#[diag(passes_feature_previously_declared, code = E0711)]
837pub(crate) struct FeaturePreviouslyDeclared<'a> {
838 #[primary_span]
839 pub span: Span,
840 pub feature: Symbol,
841 pub declared: &'a str,
842 pub prev_declared: &'a str,
843}
844
845#[derive(Diagnostic)]
846#[diag(passes_multiple_rustc_main, code = E0137)]
847pub(crate) struct MultipleRustcMain {
848 #[primary_span]
849 pub span: Span,
850 #[label(passes_first)]
851 pub first: Span,
852 #[label(passes_additional)]
853 pub additional: Span,
854}
855
856#[derive(Diagnostic)]
857#[diag(passes_extern_main)]
858pub(crate) struct ExternMain {
859 #[primary_span]
860 pub span: Span,
861}
862
863pub(crate) struct NoMainErr {
864 pub sp: Span,
865 pub crate_name: Symbol,
866 pub has_filename: bool,
867 pub filename: PathBuf,
868 pub file_empty: bool,
869 pub non_main_fns: Vec<Span>,
870 pub main_def_opt: Option<MainDefinition>,
871 pub add_teach_note: bool,
872}
873
874impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NoMainErr {
875 #[track_caller]
876 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
877 let mut diag = Diag::new(dcx, level, fluent::passes_no_main_function);
878 diag.span(DUMMY_SP);
879 diag.code(E0601);
880 diag.arg("crate_name", self.crate_name);
881 diag.arg("filename", self.filename);
882 diag.arg("has_filename", self.has_filename);
883 let note = if !self.non_main_fns.is_empty() {
884 for &span in &self.non_main_fns {
885 diag.span_note(span, fluent::passes_here_is_main);
886 }
887 diag.note(fluent::passes_one_or_more_possible_main);
888 diag.help(fluent::passes_consider_moving_main);
889 fluent::passes_main_must_be_defined_at_crate
891 } else if self.has_filename {
892 fluent::passes_consider_adding_main_to_file
893 } else {
894 fluent::passes_consider_adding_main_at_crate
895 };
896 if self.file_empty {
897 diag.note(note);
898 } else {
899 diag.span(self.sp.shrink_to_hi());
900 diag.span_label(self.sp.shrink_to_hi(), note);
901 }
902
903 if let Some(main_def) = self.main_def_opt
904 && main_def.opt_fn_def_id().is_none()
905 {
906 diag.span_label(main_def.span, fluent::passes_non_function_main);
908 }
909
910 if self.add_teach_note {
911 diag.note(fluent::passes_teach_note);
912 }
913 diag
914 }
915}
916
917pub(crate) struct DuplicateLangItem {
918 pub local_span: Option<Span>,
919 pub lang_item_name: Symbol,
920 pub crate_name: Symbol,
921 pub dependency_of: Option<Symbol>,
922 pub is_local: bool,
923 pub path: String,
924 pub first_defined_span: Option<Span>,
925 pub orig_crate_name: Option<Symbol>,
926 pub orig_dependency_of: Option<Symbol>,
927 pub orig_is_local: bool,
928 pub orig_path: String,
929 pub(crate) duplicate: Duplicate,
930}
931
932impl<G: EmissionGuarantee> Diagnostic<'_, G> for DuplicateLangItem {
933 #[track_caller]
934 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
935 let mut diag = Diag::new(
936 dcx,
937 level,
938 match self.duplicate {
939 Duplicate::Plain => fluent::passes_duplicate_lang_item,
940 Duplicate::Crate => fluent::passes_duplicate_lang_item_crate,
941 Duplicate::CrateDepends => fluent::passes_duplicate_lang_item_crate_depends,
942 },
943 );
944 diag.code(E0152);
945 diag.arg("lang_item_name", self.lang_item_name);
946 diag.arg("crate_name", self.crate_name);
947 if let Some(dependency_of) = self.dependency_of {
948 diag.arg("dependency_of", dependency_of);
949 }
950 diag.arg("path", self.path);
951 if let Some(orig_crate_name) = self.orig_crate_name {
952 diag.arg("orig_crate_name", orig_crate_name);
953 }
954 if let Some(orig_dependency_of) = self.orig_dependency_of {
955 diag.arg("orig_dependency_of", orig_dependency_of);
956 }
957 diag.arg("orig_path", self.orig_path);
958 if let Some(span) = self.local_span {
959 diag.span(span);
960 }
961 if let Some(span) = self.first_defined_span {
962 diag.span_note(span, fluent::passes_first_defined_span);
963 } else {
964 if self.orig_dependency_of.is_none() {
965 diag.note(fluent::passes_first_defined_crate);
966 } else {
967 diag.note(fluent::passes_first_defined_crate_depends);
968 }
969
970 if self.orig_is_local {
971 diag.note(fluent::passes_first_definition_local);
972 } else {
973 diag.note(fluent::passes_first_definition_path);
974 }
975
976 if self.is_local {
977 diag.note(fluent::passes_second_definition_local);
978 } else {
979 diag.note(fluent::passes_second_definition_path);
980 }
981 }
982 diag
983 }
984}
985
986#[derive(Diagnostic)]
987#[diag(passes_incorrect_target, code = E0718)]
988pub(crate) struct IncorrectTarget<'a> {
989 #[primary_span]
990 pub span: Span,
991 #[label]
992 pub generics_span: Span,
993 pub name: &'a str, pub kind: &'static str,
995 pub num: usize,
996 pub actual_num: usize,
997 pub at_least: bool,
998}
999
1000#[derive(Diagnostic)]
1001#[diag(passes_incorrect_crate_type)]
1002pub(crate) struct IncorrectCrateType {
1003 #[primary_span]
1004 pub span: Span,
1005}
1006
1007#[derive(LintDiagnostic)]
1008#[diag(passes_useless_assignment)]
1009pub(crate) struct UselessAssignment<'a> {
1010 pub is_field_assign: bool,
1011 pub ty: Ty<'a>,
1012}
1013
1014#[derive(LintDiagnostic)]
1015#[diag(passes_inline_ignored_for_exported)]
1016#[help]
1017pub(crate) struct InlineIgnoredForExported {}
1018
1019#[derive(Diagnostic)]
1020#[diag(passes_object_lifetime_err)]
1021pub(crate) struct ObjectLifetimeErr {
1022 #[primary_span]
1023 pub span: Span,
1024 pub repr: String,
1025}
1026
1027#[derive(Diagnostic)]
1028pub(crate) enum AttrApplication {
1029 #[diag(passes_attr_application_enum, code = E0517)]
1030 Enum {
1031 #[primary_span]
1032 hint_span: Span,
1033 #[label]
1034 span: Span,
1035 },
1036 #[diag(passes_attr_application_struct, code = E0517)]
1037 Struct {
1038 #[primary_span]
1039 hint_span: Span,
1040 #[label]
1041 span: Span,
1042 },
1043 #[diag(passes_attr_application_struct_union, code = E0517)]
1044 StructUnion {
1045 #[primary_span]
1046 hint_span: Span,
1047 #[label]
1048 span: Span,
1049 },
1050 #[diag(passes_attr_application_struct_enum_union, code = E0517)]
1051 StructEnumUnion {
1052 #[primary_span]
1053 hint_span: Span,
1054 #[label]
1055 span: Span,
1056 },
1057}
1058
1059#[derive(Diagnostic)]
1060#[diag(passes_transparent_incompatible, code = E0692)]
1061pub(crate) struct TransparentIncompatible {
1062 #[primary_span]
1063 pub hint_spans: Vec<Span>,
1064 pub target: String,
1065}
1066
1067#[derive(Diagnostic)]
1068#[diag(passes_deprecated_attribute, code = E0549)]
1069pub(crate) struct DeprecatedAttribute {
1070 #[primary_span]
1071 pub span: Span,
1072}
1073
1074#[derive(Diagnostic)]
1075#[diag(passes_useless_stability)]
1076pub(crate) struct UselessStability {
1077 #[primary_span]
1078 #[label]
1079 pub span: Span,
1080 #[label(passes_item)]
1081 pub item_sp: Span,
1082}
1083
1084#[derive(Diagnostic)]
1085#[diag(passes_cannot_stabilize_deprecated)]
1086pub(crate) struct CannotStabilizeDeprecated {
1087 #[primary_span]
1088 #[label]
1089 pub span: Span,
1090 #[label(passes_item)]
1091 pub item_sp: Span,
1092}
1093
1094#[derive(Diagnostic)]
1095#[diag(passes_unstable_attr_for_already_stable_feature)]
1096pub(crate) struct UnstableAttrForAlreadyStableFeature {
1097 #[primary_span]
1098 #[label]
1099 #[help]
1100 pub attr_span: Span,
1101 #[label(passes_item)]
1102 pub item_span: Span,
1103}
1104
1105#[derive(Diagnostic)]
1106#[diag(passes_missing_stability_attr)]
1107pub(crate) struct MissingStabilityAttr<'a> {
1108 #[primary_span]
1109 pub span: Span,
1110 pub descr: &'a str,
1111}
1112
1113#[derive(Diagnostic)]
1114#[diag(passes_missing_const_stab_attr)]
1115pub(crate) struct MissingConstStabAttr<'a> {
1116 #[primary_span]
1117 pub span: Span,
1118 pub descr: &'a str,
1119}
1120
1121#[derive(Diagnostic)]
1122#[diag(passes_trait_impl_const_stable)]
1123#[note]
1124pub(crate) struct TraitImplConstStable {
1125 #[primary_span]
1126 pub span: Span,
1127}
1128
1129#[derive(Diagnostic)]
1130#[diag(passes_trait_impl_const_stability_mismatch)]
1131pub(crate) struct TraitImplConstStabilityMismatch {
1132 #[primary_span]
1133 pub span: Span,
1134 #[subdiagnostic]
1135 pub impl_stability: ImplConstStability,
1136 #[subdiagnostic]
1137 pub trait_stability: TraitConstStability,
1138}
1139
1140#[derive(Subdiagnostic)]
1141pub(crate) enum TraitConstStability {
1142 #[note(passes_trait_impl_const_stability_mismatch_trait_stable)]
1143 Stable {
1144 #[primary_span]
1145 span: Span,
1146 },
1147 #[note(passes_trait_impl_const_stability_mismatch_trait_unstable)]
1148 Unstable {
1149 #[primary_span]
1150 span: Span,
1151 },
1152}
1153
1154#[derive(Subdiagnostic)]
1155pub(crate) enum ImplConstStability {
1156 #[note(passes_trait_impl_const_stability_mismatch_impl_stable)]
1157 Stable {
1158 #[primary_span]
1159 span: Span,
1160 },
1161 #[note(passes_trait_impl_const_stability_mismatch_impl_unstable)]
1162 Unstable {
1163 #[primary_span]
1164 span: Span,
1165 },
1166}
1167
1168#[derive(Diagnostic)]
1169#[diag(passes_unknown_feature, code = E0635)]
1170pub(crate) struct UnknownFeature {
1171 #[primary_span]
1172 pub span: Span,
1173 pub feature: Symbol,
1174}
1175
1176#[derive(Diagnostic)]
1177#[diag(passes_unknown_feature_alias, code = E0635)]
1178pub(crate) struct RenamedFeature {
1179 #[primary_span]
1180 pub span: Span,
1181 pub feature: Symbol,
1182 pub alias: Symbol,
1183}
1184
1185#[derive(Diagnostic)]
1186#[diag(passes_implied_feature_not_exist)]
1187pub(crate) struct ImpliedFeatureNotExist {
1188 #[primary_span]
1189 pub span: Span,
1190 pub feature: Symbol,
1191 pub implied_by: Symbol,
1192}
1193
1194#[derive(Diagnostic)]
1195#[diag(passes_duplicate_feature_err, code = E0636)]
1196pub(crate) struct DuplicateFeatureErr {
1197 #[primary_span]
1198 pub span: Span,
1199 pub feature: Symbol,
1200}
1201
1202#[derive(Diagnostic)]
1203#[diag(passes_missing_const_err)]
1204pub(crate) struct MissingConstErr {
1205 #[primary_span]
1206 #[help]
1207 pub fn_sig_span: Span,
1208}
1209
1210#[derive(Diagnostic)]
1211#[diag(passes_const_stable_not_stable)]
1212pub(crate) struct ConstStableNotStable {
1213 #[primary_span]
1214 pub fn_sig_span: Span,
1215 #[label]
1216 pub const_span: Span,
1217}
1218
1219#[derive(LintDiagnostic)]
1220pub(crate) enum MultipleDeadCodes<'tcx> {
1221 #[diag(passes_dead_codes)]
1222 DeadCodes {
1223 multiple: bool,
1224 num: usize,
1225 descr: &'tcx str,
1226 participle: &'tcx str,
1227 name_list: DiagSymbolList,
1228 #[subdiagnostic]
1229 enum_variants_with_same_name: Vec<EnumVariantSameName<'tcx>>,
1231 #[subdiagnostic]
1232 parent_info: Option<ParentInfo<'tcx>>,
1233 #[subdiagnostic]
1234 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1235 },
1236 #[diag(passes_dead_codes)]
1237 UnusedTupleStructFields {
1238 multiple: bool,
1239 num: usize,
1240 descr: &'tcx str,
1241 participle: &'tcx str,
1242 name_list: DiagSymbolList,
1243 #[subdiagnostic]
1244 change_fields_suggestion: ChangeFields,
1245 #[subdiagnostic]
1246 parent_info: Option<ParentInfo<'tcx>>,
1247 #[subdiagnostic]
1248 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1249 },
1250}
1251
1252#[derive(Subdiagnostic)]
1253#[note(passes_enum_variant_same_name)]
1254pub(crate) struct EnumVariantSameName<'tcx> {
1255 #[primary_span]
1256 pub variant_span: Span,
1257 pub dead_name: Symbol,
1258 pub dead_descr: &'tcx str,
1259}
1260
1261#[derive(Subdiagnostic)]
1262#[label(passes_parent_info)]
1263pub(crate) struct ParentInfo<'tcx> {
1264 pub num: usize,
1265 pub descr: &'tcx str,
1266 pub parent_descr: &'tcx str,
1267 #[primary_span]
1268 pub span: Span,
1269}
1270
1271#[derive(Subdiagnostic)]
1272#[note(passes_ignored_derived_impls)]
1273pub(crate) struct IgnoredDerivedImpls {
1274 pub name: Symbol,
1275 pub trait_list: DiagSymbolList,
1276 pub trait_list_len: usize,
1277}
1278
1279#[derive(Subdiagnostic)]
1280pub(crate) enum ChangeFields {
1281 #[multipart_suggestion(
1282 passes_change_fields_to_be_of_unit_type,
1283 applicability = "has-placeholders"
1284 )]
1285 ChangeToUnitTypeOrRemove {
1286 num: usize,
1287 #[suggestion_part(code = "()")]
1288 spans: Vec<Span>,
1289 },
1290 #[help(passes_remove_fields)]
1291 Remove { num: usize },
1292}
1293
1294#[derive(Diagnostic)]
1295#[diag(passes_proc_macro_bad_sig)]
1296pub(crate) struct ProcMacroBadSig {
1297 #[primary_span]
1298 pub span: Span,
1299 pub kind: ProcMacroKind,
1300}
1301
1302#[derive(LintDiagnostic)]
1303#[diag(passes_unnecessary_stable_feature)]
1304pub(crate) struct UnnecessaryStableFeature {
1305 pub feature: Symbol,
1306 pub since: Symbol,
1307}
1308
1309#[derive(LintDiagnostic)]
1310#[diag(passes_unnecessary_partial_stable_feature)]
1311pub(crate) struct UnnecessaryPartialStableFeature {
1312 #[suggestion(code = "{implies}", applicability = "maybe-incorrect")]
1313 pub span: Span,
1314 #[suggestion(passes_suggestion_remove, code = "", applicability = "maybe-incorrect")]
1315 pub line: Span,
1316 pub feature: Symbol,
1317 pub since: Symbol,
1318 pub implies: Symbol,
1319}
1320
1321#[derive(LintDiagnostic)]
1322#[diag(passes_ineffective_unstable_impl)]
1323#[note]
1324pub(crate) struct IneffectiveUnstableImpl;
1325
1326#[derive(LintDiagnostic)]
1327#[diag(passes_attr_crate_level)]
1328#[note]
1329pub(crate) struct AttrCrateLevelOnly {
1330 #[subdiagnostic]
1331 pub sugg: Option<AttrCrateLevelOnlySugg>,
1332}
1333
1334#[derive(Subdiagnostic)]
1335#[suggestion(passes_suggestion, applicability = "maybe-incorrect", code = "!", style = "verbose")]
1336pub(crate) struct AttrCrateLevelOnlySugg {
1337 #[primary_span]
1338 pub attr: Span,
1339}
1340
1341#[derive(Diagnostic)]
1343#[diag(passes_sanitize_attribute_not_allowed)]
1344pub(crate) struct SanitizeAttributeNotAllowed {
1345 #[primary_span]
1346 pub attr_span: Span,
1347 #[label(passes_not_fn_impl_mod)]
1349 pub not_fn_impl_mod: Option<Span>,
1350 #[label(passes_no_body)]
1352 pub no_body: Option<Span>,
1353 #[help]
1355 pub help: (),
1356}
1357
1358#[derive(Diagnostic)]
1360#[diag(passes_rustc_const_stable_indirect_pairing)]
1361pub(crate) struct RustcConstStableIndirectPairing {
1362 #[primary_span]
1363 pub span: Span,
1364}
1365
1366#[derive(Diagnostic)]
1367#[diag(passes_unsupported_attributes_in_where)]
1368#[help]
1369pub(crate) struct UnsupportedAttributesInWhere {
1370 #[primary_span]
1371 pub span: MultiSpan,
1372}
1373
1374#[derive(Diagnostic)]
1375pub(crate) enum UnexportableItem<'a> {
1376 #[diag(passes_unexportable_item)]
1377 Item {
1378 #[primary_span]
1379 span: Span,
1380 descr: &'a str,
1381 },
1382
1383 #[diag(passes_unexportable_generic_fn)]
1384 GenericFn(#[primary_span] Span),
1385
1386 #[diag(passes_unexportable_fn_abi)]
1387 FnAbi(#[primary_span] Span),
1388
1389 #[diag(passes_unexportable_type_repr)]
1390 TypeRepr(#[primary_span] Span),
1391
1392 #[diag(passes_unexportable_type_in_interface)]
1393 TypeInInterface {
1394 #[primary_span]
1395 span: Span,
1396 desc: &'a str,
1397 ty: &'a str,
1398 #[label]
1399 ty_span: Span,
1400 },
1401
1402 #[diag(passes_unexportable_priv_item)]
1403 PrivItem {
1404 #[primary_span]
1405 span: Span,
1406 #[note]
1407 vis_note: Span,
1408 vis_descr: &'a str,
1409 },
1410
1411 #[diag(passes_unexportable_adt_with_private_fields)]
1412 AdtWithPrivFields {
1413 #[primary_span]
1414 span: Span,
1415 #[note]
1416 vis_note: Span,
1417 field_name: &'a str,
1418 },
1419}
1420
1421#[derive(Diagnostic)]
1422#[diag(passes_repr_align_should_be_align)]
1423pub(crate) struct ReprAlignShouldBeAlign {
1424 #[primary_span]
1425 #[help]
1426 pub span: Span,
1427 pub item: &'static str,
1428}
1429
1430#[derive(Diagnostic)]
1431#[diag(passes_repr_align_should_be_align_static)]
1432pub(crate) struct ReprAlignShouldBeAlignStatic {
1433 #[primary_span]
1434 #[help]
1435 pub span: Span,
1436 pub item: &'static str,
1437}
1438
1439#[derive(Diagnostic)]
1440#[diag(passes_custom_mir_phase_requires_dialect)]
1441pub(crate) struct CustomMirPhaseRequiresDialect {
1442 #[primary_span]
1443 pub attr_span: Span,
1444 #[label]
1445 pub phase_span: Span,
1446}
1447
1448#[derive(Diagnostic)]
1449#[diag(passes_custom_mir_incompatible_dialect_and_phase)]
1450pub(crate) struct CustomMirIncompatibleDialectAndPhase {
1451 pub dialect: MirDialect,
1452 pub phase: MirPhase,
1453 #[primary_span]
1454 pub attr_span: Span,
1455 #[label]
1456 pub dialect_span: Span,
1457 #[label]
1458 pub phase_span: Span,
1459}