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