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