8 error_code, Applicability, DiagnosticSymbolList, ErrorGuaranteed, IntoDiagnostic, MultiSpan,
10 use rustc_hir::{self as hir, ExprKind, Target};
11 use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
12 use rustc_middle::ty::{MainDefinition, Ty};
13 use rustc_span::{Span, Symbol, DUMMY_SP};
15 use crate::check_attr::ProcMacroKind;
16 use crate::lang_items::Duplicate;
19 #[diag(passes_incorrect_do_not_recommend_location)]
20 pub struct IncorrectDoNotRecommendLocation {
25 #[derive(LintDiagnostic)]
26 #[diag(passes_outer_crate_level_attr)]
27 pub struct OuterCrateLevelAttr;
29 #[derive(LintDiagnostic)]
30 #[diag(passes_inner_crate_level_attr)]
31 pub struct InnerCrateLevelAttr;
33 #[derive(LintDiagnostic)]
34 #[diag(passes_ignored_attr_with_macro)]
35 pub struct IgnoredAttrWithMacro<'a> {
39 #[derive(LintDiagnostic)]
40 #[diag(passes_ignored_attr)]
41 pub struct IgnoredAttr<'a> {
45 #[derive(LintDiagnostic)]
46 #[diag(passes_inline_ignored_function_prototype)]
47 pub struct IgnoredInlineAttrFnProto;
49 #[derive(LintDiagnostic)]
50 #[diag(passes_inline_ignored_constants)]
53 pub struct IgnoredInlineAttrConstants;
56 #[diag(passes_inline_not_fn_or_closure, code = "E0518")]
57 pub struct InlineNotFnOrClosure {
64 #[derive(LintDiagnostic)]
65 #[diag(passes_no_coverage_ignored_function_prototype)]
66 pub struct IgnoredNoCoverageFnProto;
68 #[derive(LintDiagnostic)]
69 #[diag(passes_no_coverage_propagate)]
70 pub struct IgnoredNoCoveragePropagate;
72 #[derive(LintDiagnostic)]
73 #[diag(passes_no_coverage_fn_defn)]
74 pub struct IgnoredNoCoverageFnDefn;
77 #[diag(passes_no_coverage_not_coverable, code = "E0788")]
78 pub struct IgnoredNoCoverageNotCoverable {
86 #[diag(passes_should_be_applied_to_fn)]
87 pub struct AttrShouldBeAppliedToFn {
96 #[diag(passes_naked_tracked_caller, code = "E0736")]
97 pub struct NakedTrackedCaller {
102 #[derive(Diagnostic)]
103 #[diag(passes_should_be_applied_to_fn, code = "E0739")]
104 pub struct TrackedCallerWrongLocation {
112 #[derive(Diagnostic)]
113 #[diag(passes_should_be_applied_to_struct_enum, code = "E0701")]
114 pub struct NonExhaustiveWrongLocation {
121 #[derive(Diagnostic)]
122 #[diag(passes_should_be_applied_to_trait)]
123 pub struct AttrShouldBeAppliedToTrait {
130 #[derive(LintDiagnostic)]
131 #[diag(passes_target_feature_on_statement)]
132 pub struct TargetFeatureOnStatement;
134 #[derive(Diagnostic)]
135 #[diag(passes_should_be_applied_to_static)]
136 pub struct AttrShouldBeAppliedToStatic {
143 #[derive(Diagnostic)]
144 #[diag(passes_doc_expect_str)]
145 pub struct DocExpectStr<'a> {
148 pub attr_name: &'a str,
151 #[derive(Diagnostic)]
152 #[diag(passes_doc_alias_empty)]
153 pub struct DocAliasEmpty<'a> {
156 pub attr_str: &'a str,
159 #[derive(Diagnostic)]
160 #[diag(passes_doc_alias_bad_char)]
161 pub struct DocAliasBadChar<'a> {
164 pub attr_str: &'a str,
168 #[derive(Diagnostic)]
169 #[diag(passes_doc_alias_start_end)]
170 pub struct DocAliasStartEnd<'a> {
173 pub attr_str: &'a str,
176 #[derive(Diagnostic)]
177 #[diag(passes_doc_alias_bad_location)]
178 pub struct DocAliasBadLocation<'a> {
181 pub attr_str: &'a str,
182 pub location: &'a str,
185 #[derive(Diagnostic)]
186 #[diag(passes_doc_alias_not_an_alias)]
187 pub struct DocAliasNotAnAlias<'a> {
190 pub attr_str: &'a str,
193 #[derive(LintDiagnostic)]
194 #[diag(passes_doc_alias_duplicated)]
195 pub struct DocAliasDuplicated {
197 pub first_defn: Span,
200 #[derive(Diagnostic)]
201 #[diag(passes_doc_alias_not_string_literal)]
202 pub struct DocAliasNotStringLiteral {
207 #[derive(Diagnostic)]
208 #[diag(passes_doc_alias_malformed)]
209 pub struct DocAliasMalformed {
214 #[derive(Diagnostic)]
215 #[diag(passes_doc_keyword_empty_mod)]
216 pub struct DocKeywordEmptyMod {
221 #[derive(Diagnostic)]
222 #[diag(passes_doc_keyword_not_mod)]
223 pub struct DocKeywordNotMod {
228 #[derive(Diagnostic)]
229 #[diag(passes_doc_keyword_invalid_ident)]
230 pub struct DocKeywordInvalidIdent {
233 pub doc_keyword: Symbol,
236 #[derive(Diagnostic)]
237 #[diag(passes_doc_fake_variadic_not_valid)]
238 pub struct DocFakeVariadicNotValid {
243 #[derive(Diagnostic)]
244 #[diag(passes_doc_keyword_only_impl)]
245 pub struct DocKeywordOnlyImpl {
250 #[derive(Diagnostic)]
251 #[diag(passes_doc_inline_conflict)]
253 pub struct DocKeywordConflict {
255 pub spans: MultiSpan,
258 #[derive(LintDiagnostic)]
259 #[diag(passes_doc_inline_only_use)]
261 pub struct DocInlineOnlyUse {
264 #[label(not_a_use_item_label)]
265 pub item_span: Option<Span>,
268 #[derive(Diagnostic)]
269 #[diag(passes_doc_attr_not_crate_level)]
270 pub struct DocAttrNotCrateLevel<'a> {
273 pub attr_name: &'a str,
276 #[derive(LintDiagnostic)]
277 #[diag(passes_doc_test_unknown)]
278 pub struct DocTestUnknown {
282 #[derive(LintDiagnostic)]
283 #[diag(passes_doc_test_takes_list)]
284 pub struct DocTestTakesList;
286 #[derive(LintDiagnostic)]
287 #[diag(passes_doc_cfg_hide_takes_list)]
288 pub struct DocCfgHideTakesList;
290 #[derive(LintDiagnostic)]
291 #[diag(passes_doc_primitive)]
292 pub struct DocPrimitive;
294 #[derive(LintDiagnostic)]
295 #[diag(passes_doc_test_unknown_any)]
296 pub struct DocTestUnknownAny {
300 #[derive(LintDiagnostic)]
301 #[diag(passes_doc_test_unknown_spotlight)]
304 pub struct DocTestUnknownSpotlight {
306 #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")]
310 #[derive(LintDiagnostic)]
311 #[diag(passes_doc_test_unknown_include)]
312 pub struct DocTestUnknownInclude {
315 pub inner: &'static str,
316 #[suggestion(code = "#{inner}[doc = include_str!(\"{value}\")]")]
317 pub sugg: (Span, Applicability),
320 #[derive(LintDiagnostic)]
321 #[diag(passes_doc_invalid)]
322 pub struct DocInvalid;
324 #[derive(Diagnostic)]
325 #[diag(passes_pass_by_value)]
326 pub struct PassByValue {
333 #[derive(Diagnostic)]
334 #[diag(passes_allow_incoherent_impl)]
335 pub struct AllowIncoherentImpl {
342 #[derive(Diagnostic)]
343 #[diag(passes_has_incoherent_inherent_impl)]
344 pub struct HasIncoherentInherentImpl {
351 #[derive(Diagnostic)]
352 #[diag(passes_both_ffi_const_and_pure, code = "E0757")]
353 pub struct BothFfiConstAndPure {
358 #[derive(Diagnostic)]
359 #[diag(passes_ffi_pure_invalid_target, code = "E0755")]
360 pub struct FfiPureInvalidTarget {
365 #[derive(Diagnostic)]
366 #[diag(passes_ffi_const_invalid_target, code = "E0756")]
367 pub struct FfiConstInvalidTarget {
372 #[derive(Diagnostic)]
373 #[diag(passes_ffi_returns_twice_invalid_target, code = "E0724")]
374 pub struct FfiReturnsTwiceInvalidTarget {
379 #[derive(LintDiagnostic)]
380 #[diag(passes_must_use_async)]
381 pub struct MustUseAsync {
386 #[derive(LintDiagnostic)]
387 #[diag(passes_must_use_no_effect)]
388 pub struct MustUseNoEffect {
389 pub article: &'static str,
390 pub target: rustc_hir::Target,
393 #[derive(Diagnostic)]
394 #[diag(passes_must_not_suspend)]
395 pub struct MustNotSuspend {
402 #[derive(LintDiagnostic)]
411 #[derive(LintDiagnostic)]
416 pub span: Option<Span>,
419 #[derive(LintDiagnostic)]
420 #[diag(passes_link_name)]
422 pub struct LinkName<'a> {
424 pub attr_span: Option<Span>,
430 #[derive(Diagnostic)]
431 #[diag(passes_no_link)]
439 #[derive(Diagnostic)]
440 #[diag(passes_export_name)]
441 pub struct ExportName {
448 #[derive(Diagnostic)]
449 #[diag(passes_rustc_layout_scalar_valid_range_not_struct)]
450 pub struct RustcLayoutScalarValidRangeNotStruct {
457 #[derive(Diagnostic)]
458 #[diag(passes_rustc_layout_scalar_valid_range_arg)]
459 pub struct RustcLayoutScalarValidRangeArg {
464 #[derive(Diagnostic)]
465 #[diag(passes_rustc_legacy_const_generics_only)]
466 pub struct RustcLegacyConstGenericsOnly {
470 pub param_span: Span,
473 #[derive(Diagnostic)]
474 #[diag(passes_rustc_legacy_const_generics_index)]
475 pub struct RustcLegacyConstGenericsIndex {
479 pub generics_span: Span,
482 #[derive(Diagnostic)]
483 #[diag(passes_rustc_legacy_const_generics_index_exceed)]
484 pub struct RustcLegacyConstGenericsIndexExceed {
488 pub arg_count: usize,
491 #[derive(Diagnostic)]
492 #[diag(passes_rustc_legacy_const_generics_index_negative)]
493 pub struct RustcLegacyConstGenericsIndexNegative {
495 pub invalid_args: Vec<Span>,
498 #[derive(Diagnostic)]
499 #[diag(passes_rustc_dirty_clean)]
500 pub struct RustcDirtyClean {
505 #[derive(LintDiagnostic)]
506 #[diag(passes_link_section)]
508 pub struct LinkSection {
513 #[derive(LintDiagnostic)]
514 #[diag(passes_no_mangle_foreign)]
517 pub struct NoMangleForeign {
520 #[suggestion(code = "", applicability = "machine-applicable")]
522 pub foreign_item_kind: &'static str,
525 #[derive(LintDiagnostic)]
526 #[diag(passes_no_mangle)]
528 pub struct NoMangle {
533 #[derive(Diagnostic)]
534 #[diag(passes_repr_ident, code = "E0565")]
535 pub struct ReprIdent {
540 #[derive(LintDiagnostic)]
541 #[diag(passes_repr_conflicting, code = "E0566")]
542 pub struct ReprConflicting;
544 #[derive(Diagnostic)]
545 #[diag(passes_used_static)]
546 pub struct UsedStatic {
551 #[derive(Diagnostic)]
552 #[diag(passes_used_compiler_linker)]
553 pub struct UsedCompilerLinker {
555 pub spans: Vec<Span>,
558 #[derive(Diagnostic)]
559 #[diag(passes_allow_internal_unstable)]
560 pub struct AllowInternalUnstable {
567 #[derive(Diagnostic)]
568 #[diag(passes_debug_visualizer_placement)]
569 pub struct DebugVisualizerPlacement {
574 #[derive(Diagnostic)]
575 #[diag(passes_debug_visualizer_invalid)]
579 pub struct DebugVisualizerInvalid {
584 #[derive(Diagnostic)]
585 #[diag(passes_debug_visualizer_unreadable)]
586 pub struct DebugVisualizerUnreadable<'a> {
593 #[derive(Diagnostic)]
594 #[diag(passes_rustc_allow_const_fn_unstable)]
595 pub struct RustcAllowConstFnUnstable {
602 #[derive(Diagnostic)]
603 #[diag(passes_rustc_std_internal_symbol)]
604 pub struct RustcStdInternalSymbol {
611 #[derive(Diagnostic)]
612 #[diag(passes_const_trait)]
613 pub struct ConstTrait {
618 #[derive(Diagnostic)]
619 #[diag(passes_link_ordinal)]
620 pub struct LinkOrdinal {
625 #[derive(Diagnostic)]
626 #[diag(passes_stability_promotable)]
627 pub struct StabilityPromotable {
632 #[derive(LintDiagnostic)]
633 #[diag(passes_deprecated)]
634 pub struct Deprecated;
636 #[derive(LintDiagnostic)]
637 #[diag(passes_macro_use)]
638 pub struct MacroUse {
642 #[derive(LintDiagnostic)]
643 #[diag(passes_macro_export)]
644 pub struct MacroExport;
646 #[derive(LintDiagnostic)]
647 #[diag(passes_plugin_registrar)]
648 pub struct PluginRegistrar;
650 #[derive(Subdiagnostic)]
651 pub enum UnusedNote {
652 #[note(passes_unused_empty_lints_note)]
653 EmptyList { name: Symbol },
654 #[note(passes_unused_no_lints_note)]
655 NoLints { name: Symbol },
656 #[note(passes_unused_default_method_body_const_note)]
657 DefaultMethodBodyConst,
660 #[derive(LintDiagnostic)]
661 #[diag(passes_unused)]
663 #[suggestion(code = "", applicability = "machine-applicable")]
666 pub note: UnusedNote,
669 #[derive(Diagnostic)]
670 #[diag(passes_non_exported_macro_invalid_attrs, code = "E0518")]
671 pub struct NonExportedMacroInvalidAttrs {
677 #[derive(LintDiagnostic)]
678 #[diag(passes_unused_duplicate)]
679 pub struct UnusedDuplicate {
680 #[suggestion(code = "", applicability = "machine-applicable")]
685 pub warning: Option<()>,
688 #[derive(Diagnostic)]
689 #[diag(passes_unused_multiple)]
690 pub struct UnusedMultiple {
692 #[suggestion(code = "", applicability = "machine-applicable")]
699 #[derive(Diagnostic)]
700 #[diag(passes_rustc_lint_opt_ty)]
701 pub struct RustcLintOptTy {
708 #[derive(Diagnostic)]
709 #[diag(passes_rustc_lint_opt_deny_field_access)]
710 pub struct RustcLintOptDenyFieldAccess {
717 #[derive(Diagnostic)]
718 #[diag(passes_collapse_debuginfo)]
719 pub struct CollapseDebuginfo {
726 #[derive(LintDiagnostic)]
727 #[diag(passes_deprecated_annotation_has_no_effect)]
728 pub struct DeprecatedAnnotationHasNoEffect {
729 #[suggestion(applicability = "machine-applicable", code = "")]
733 #[derive(Diagnostic)]
734 #[diag(passes_unknown_external_lang_item, code = "E0264")]
735 pub struct UnknownExternLangItem {
738 pub lang_item: Symbol,
741 #[derive(Diagnostic)]
742 #[diag(passes_missing_panic_handler)]
743 pub struct MissingPanicHandler;
745 #[derive(Diagnostic)]
746 #[diag(passes_missing_lang_item)]
749 pub struct MissingLangItem {
753 #[derive(Diagnostic)]
754 #[diag(passes_lang_item_on_incorrect_target, code = "E0718")]
755 pub struct LangItemOnIncorrectTarget {
760 pub expected_target: Target,
761 pub actual_target: Target,
764 #[derive(Diagnostic)]
765 #[diag(passes_unknown_lang_item, code = "E0522")]
766 pub struct UnknownLangItem {
773 pub struct InvalidAttrAtCrateLevel {
775 pub snippet: Option<String>,
779 impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel {
783 handler: &'_ rustc_errors::Handler,
784 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
785 let mut diag = handler.struct_err(rustc_errors::fluent::passes_invalid_attr_at_crate_level);
786 diag.set_span(self.span);
787 diag.set_arg("name", self.name);
788 // Only emit an error with a suggestion if we can create a string out
789 // of the attribute span
790 if let Some(src) = self.snippet {
791 let replacement = src.replace("#!", "#");
792 diag.span_suggestion_verbose(
794 rustc_errors::fluent::suggestion,
796 rustc_errors::Applicability::MachineApplicable,
803 #[derive(Diagnostic)]
804 #[diag(passes_duplicate_diagnostic_item)]
805 pub struct DuplicateDiagnosticItem {
811 #[derive(Diagnostic)]
812 #[diag(passes_duplicate_diagnostic_item_in_crate)]
813 pub struct DuplicateDiagnosticItemInCrate {
814 #[note(passes_diagnostic_item_first_defined)]
815 pub span: Option<Span>,
816 pub orig_crate_name: Symbol,
818 pub have_orig_crate_name: Option<()>,
819 pub crate_name: Symbol,
823 #[derive(Diagnostic)]
831 #[derive(Diagnostic)]
832 #[diag(passes_align)]
839 #[derive(Diagnostic)]
847 #[derive(Diagnostic)]
848 #[diag(passes_homogeneous_aggregate)]
849 pub struct HomogeneousAggregate {
852 pub homogeneous_aggregate: String,
855 #[derive(Diagnostic)]
856 #[diag(passes_layout_of)]
857 pub struct LayoutOf {
860 pub normalized_ty: String,
861 pub ty_layout: String,
864 #[derive(Diagnostic)]
865 #[diag(passes_unrecognized_field)]
866 pub struct UnrecognizedField {
872 #[derive(Diagnostic)]
873 #[diag(passes_feature_stable_twice, code = "E0711")]
874 pub struct FeatureStableTwice {
879 pub prev_since: Symbol,
882 #[derive(Diagnostic)]
883 #[diag(passes_feature_previously_declared, code = "E0711")]
884 pub struct FeaturePreviouslyDeclared<'a, 'b> {
888 pub declared: &'a str,
889 pub prev_declared: &'b str,
892 #[derive(Diagnostic)]
893 #[diag(passes_expr_not_allowed_in_context, code = "E0744")]
894 pub struct ExprNotAllowedInContext<'a> {
898 pub context: &'a str,
901 pub struct BreakNonLoop<'a> {
903 pub head: Option<Span>,
905 pub suggestion: String,
906 pub loop_label: Option<Label>,
907 pub break_label: Option<Label>,
908 pub break_expr_kind: &'a ExprKind<'a>,
909 pub break_expr_span: Span,
912 impl<'a> IntoDiagnostic<'_> for BreakNonLoop<'a> {
916 handler: &rustc_errors::Handler,
917 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
918 let mut diag = handler.struct_span_err_with_code(
920 rustc_errors::fluent::passes_break_non_loop,
923 diag.set_arg("kind", self.kind);
924 diag.span_label(self.span, rustc_errors::fluent::label);
925 if let Some(head) = self.head {
926 diag.span_label(head, rustc_errors::fluent::label2);
928 diag.span_suggestion(
930 rustc_errors::fluent::suggestion,
932 Applicability::MaybeIncorrect,
934 if let (Some(label), None) = (self.loop_label, self.break_label) {
935 match self.break_expr_kind {
936 ExprKind::Path(hir::QPath::Resolved(
938 hir::Path { segments: [segment], res: hir::def::Res::Err, .. },
939 )) if label.ident.to_string() == format!("'{}", segment.ident) => {
940 // This error is redundant, we will have already emitted a
941 // suggestion to use the label when `segment` wasn't found
942 // (hence the `Res::Err` check).
946 diag.span_suggestion(
947 self.break_expr_span,
948 rustc_errors::fluent::break_expr_suggestion,
950 Applicability::MaybeIncorrect,
959 #[derive(Diagnostic)]
960 #[diag(passes_continue_labeled_block, code = "E0696")]
961 pub struct ContinueLabeledBlock {
965 #[label(block_label)]
966 pub block_span: Span,
969 #[derive(Diagnostic)]
970 #[diag(passes_break_inside_closure, code = "E0267")]
971 pub struct BreakInsideClosure<'a> {
975 #[label(closure_label)]
976 pub closure_span: Span,
980 #[derive(Diagnostic)]
981 #[diag(passes_break_inside_async_block, code = "E0267")]
982 pub struct BreakInsideAsyncBlock<'a> {
986 #[label(async_block_label)]
987 pub closure_span: Span,
991 #[derive(Diagnostic)]
992 #[diag(passes_outside_loop, code = "E0268")]
993 pub struct OutsideLoop<'a> {
1001 #[derive(Diagnostic)]
1002 #[diag(passes_unlabeled_in_labeled_block, code = "E0695")]
1003 pub struct UnlabeledInLabeledBlock<'a> {
1007 pub cf_type: &'a str,
1010 #[derive(Diagnostic)]
1011 #[diag(passes_unlabeled_cf_in_while_condition, code = "E0590")]
1012 pub struct UnlabeledCfInWhileCondition<'a> {
1016 pub cf_type: &'a str,
1019 #[derive(Diagnostic)]
1020 #[diag(passes_cannot_inline_naked_function)]
1021 pub struct CannotInlineNakedFunction {
1026 #[derive(LintDiagnostic)]
1027 #[diag(passes_undefined_naked_function_abi)]
1028 pub struct UndefinedNakedFunctionAbi;
1030 #[derive(Diagnostic)]
1031 #[diag(passes_no_patterns)]
1032 pub struct NoPatterns {
1037 #[derive(Diagnostic)]
1038 #[diag(passes_params_not_allowed)]
1040 pub struct ParamsNotAllowed {
1045 pub struct NakedFunctionsAsmBlock {
1047 pub multiple_asms: Vec<Span>,
1048 pub non_asms: Vec<Span>,
1051 impl IntoDiagnostic<'_> for NakedFunctionsAsmBlock {
1055 handler: &rustc_errors::Handler,
1056 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
1057 let mut diag = handler.struct_span_err_with_code(
1059 rustc_errors::fluent::passes_naked_functions_asm_block,
1062 for span in self.multiple_asms.iter() {
1063 diag.span_label(*span, rustc_errors::fluent::label_multiple_asm);
1065 for span in self.non_asms.iter() {
1066 diag.span_label(*span, rustc_errors::fluent::label_non_asm);
1072 #[derive(Diagnostic)]
1073 #[diag(passes_naked_functions_operands, code = "E0787")]
1074 pub struct NakedFunctionsOperands {
1076 pub unsupported_operands: Vec<Span>,
1079 #[derive(Diagnostic)]
1080 #[diag(passes_naked_functions_asm_options, code = "E0787")]
1081 pub struct NakedFunctionsAsmOptions {
1084 pub unsupported_options: String,
1087 #[derive(Diagnostic)]
1088 #[diag(passes_naked_functions_must_use_noreturn, code = "E0787")]
1089 pub struct NakedFunctionsMustUseNoreturn {
1092 #[suggestion(code = ", options(noreturn)", applicability = "machine-applicable")]
1093 pub last_span: Span,
1096 #[derive(Diagnostic)]
1097 #[diag(passes_attr_only_on_main)]
1098 pub struct AttrOnlyOnMain {
1104 #[derive(Diagnostic)]
1105 #[diag(passes_attr_only_on_root_main)]
1106 pub struct AttrOnlyOnRootMain {
1112 #[derive(Diagnostic)]
1113 #[diag(passes_attr_only_in_functions)]
1114 pub struct AttrOnlyInFunctions {
1120 #[derive(Diagnostic)]
1121 #[diag(passes_multiple_rustc_main, code = "E0137")]
1122 pub struct MultipleRustcMain {
1127 #[label(additional)]
1128 pub additional: Span,
1131 #[derive(Diagnostic)]
1132 #[diag(passes_multiple_start_functions, code = "E0138")]
1133 pub struct MultipleStartFunctions {
1142 #[derive(Diagnostic)]
1143 #[diag(passes_extern_main)]
1144 pub struct ExternMain {
1149 #[derive(Diagnostic)]
1150 #[diag(passes_unix_sigpipe_values)]
1151 pub struct UnixSigpipeValues {
1156 #[derive(Diagnostic)]
1157 #[diag(passes_no_main_function, code = "E0601")]
1158 pub struct NoMainFunction {
1161 pub crate_name: String,
1164 pub struct NoMainErr {
1166 pub crate_name: Symbol,
1167 pub has_filename: bool,
1168 pub filename: PathBuf,
1169 pub file_empty: bool,
1170 pub non_main_fns: Vec<Span>,
1171 pub main_def_opt: Option<MainDefinition>,
1172 pub add_teach_note: bool,
1175 impl<'a> IntoDiagnostic<'a> for NoMainErr {
1179 handler: &'a rustc_errors::Handler,
1180 ) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> {
1181 let mut diag = handler.struct_span_err_with_code(
1183 rustc_errors::fluent::passes_no_main_function,
1186 diag.set_arg("crate_name", self.crate_name);
1187 diag.set_arg("filename", self.filename);
1188 diag.set_arg("has_filename", self.has_filename);
1189 let note = if !self.non_main_fns.is_empty() {
1190 for &span in &self.non_main_fns {
1191 diag.span_note(span, rustc_errors::fluent::here_is_main);
1193 diag.note(rustc_errors::fluent::one_or_more_possible_main);
1194 diag.help(rustc_errors::fluent::consider_moving_main);
1195 // There were some functions named `main` though. Try to give the user a hint.
1196 rustc_errors::fluent::main_must_be_defined_at_crate
1197 } else if self.has_filename {
1198 rustc_errors::fluent::consider_adding_main_to_file
1200 rustc_errors::fluent::consider_adding_main_at_crate
1202 if self.file_empty {
1205 diag.set_span(self.sp.shrink_to_hi());
1206 diag.span_label(self.sp.shrink_to_hi(), note);
1209 if let Some(main_def) = self.main_def_opt && main_def.opt_fn_def_id().is_none(){
1210 // There is something at `crate::main`, but it is not a function definition.
1211 diag.span_label(main_def.span, rustc_errors::fluent::non_function_main);
1214 if self.add_teach_note {
1215 diag.note(rustc_errors::fluent::teach_note);
1221 pub struct DuplicateLangItem {
1222 pub local_span: Option<Span>,
1223 pub lang_item_name: Symbol,
1224 pub crate_name: Symbol,
1225 pub dependency_of: Symbol,
1228 pub first_defined_span: Option<Span>,
1229 pub orig_crate_name: Symbol,
1230 pub orig_dependency_of: Symbol,
1231 pub orig_is_local: bool,
1232 pub orig_path: String,
1233 pub(crate) duplicate: Duplicate,
1236 impl IntoDiagnostic<'_> for DuplicateLangItem {
1240 handler: &rustc_errors::Handler,
1241 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
1242 let mut diag = handler.struct_err_with_code(
1243 match self.duplicate {
1244 Duplicate::Plain => rustc_errors::fluent::passes_duplicate_lang_item,
1246 Duplicate::Crate => rustc_errors::fluent::passes_duplicate_lang_item_crate,
1247 Duplicate::CrateDepends => {
1248 rustc_errors::fluent::passes_duplicate_lang_item_crate_depends
1253 diag.set_arg("lang_item_name", self.lang_item_name);
1254 diag.set_arg("crate_name", self.crate_name);
1255 diag.set_arg("dependency_of", self.dependency_of);
1256 diag.set_arg("path", self.path);
1257 diag.set_arg("orig_crate_name", self.orig_crate_name);
1258 diag.set_arg("orig_dependency_of", self.orig_dependency_of);
1259 diag.set_arg("orig_path", self.orig_path);
1260 if let Some(span) = self.local_span {
1261 diag.set_span(span);
1263 if let Some(span) = self.first_defined_span {
1264 diag.span_note(span, rustc_errors::fluent::first_defined_span);
1266 if self.orig_dependency_of.is_empty() {
1267 diag.note(rustc_errors::fluent::first_defined_crate);
1269 diag.note(rustc_errors::fluent::first_defined_crate_depends);
1272 if self.orig_is_local {
1273 diag.note(rustc_errors::fluent::first_definition_local);
1275 diag.note(rustc_errors::fluent::first_definition_path);
1279 diag.note(rustc_errors::fluent::second_definition_local);
1281 diag.note(rustc_errors::fluent::second_definition_path);
1288 #[derive(Diagnostic)]
1289 #[diag(passes_incorrect_target, code = "E0718")]
1290 pub struct IncorrectTarget<'a> {
1294 pub generics_span: Span,
1295 pub name: &'a str, // cannot be symbol because it renders e.g. `r#fn` instead of `fn`
1296 pub kind: &'static str,
1298 pub actual_num: usize,
1302 #[derive(LintDiagnostic)]
1303 #[diag(passes_useless_assignment)]
1304 pub struct UselessAssignment<'a> {
1305 pub is_field_assign: bool,
1309 #[derive(LintDiagnostic)]
1310 #[diag(passes_only_has_effect_on)]
1311 pub struct OnlyHasEffectOn {
1312 pub attr_name: Symbol,
1313 pub target_name: String,
1316 #[derive(Diagnostic)]
1317 #[diag(passes_object_lifetime_err)]
1318 pub struct ObjectLifetimeErr {
1324 #[derive(Diagnostic)]
1325 #[diag(passes_unrecognized_repr_hint, code = "E0552")]
1327 pub struct UnrecognizedReprHint {
1332 #[derive(Diagnostic)]
1333 pub enum AttrApplication {
1334 #[diag(passes_attr_application_enum, code = "E0517")]
1341 #[diag(passes_attr_application_struct, code = "E0517")]
1348 #[diag(passes_attr_application_struct_union, code = "E0517")]
1355 #[diag(passes_attr_application_struct_enum_union, code = "E0517")]
1362 #[diag(passes_attr_application_struct_enum_function_union, code = "E0517")]
1363 StructEnumFunctionUnion {
1371 #[derive(Diagnostic)]
1372 #[diag(passes_transparent_incompatible, code = "E0692")]
1373 pub struct TransparentIncompatible {
1375 pub hint_spans: Vec<Span>,
1379 #[derive(Diagnostic)]
1380 #[diag(passes_deprecated_attribute, code = "E0549")]
1381 pub struct DeprecatedAttribute {
1386 #[derive(Diagnostic)]
1387 #[diag(passes_useless_stability)]
1388 pub struct UselessStability {
1396 #[derive(Diagnostic)]
1397 #[diag(passes_invalid_stability)]
1398 pub struct InvalidStability {
1406 #[derive(Diagnostic)]
1407 #[diag(passes_cannot_stabilize_deprecated)]
1408 pub struct CannotStabilizeDeprecated {
1416 #[derive(Diagnostic)]
1417 #[diag(passes_invalid_deprecation_version)]
1418 pub struct InvalidDeprecationVersion {
1426 #[derive(Diagnostic)]
1427 #[diag(passes_missing_stability_attr)]
1428 pub struct MissingStabilityAttr<'a> {
1434 #[derive(Diagnostic)]
1435 #[diag(passes_missing_const_stab_attr)]
1436 pub struct MissingConstStabAttr<'a> {
1442 #[derive(Diagnostic)]
1443 #[diag(passes_trait_impl_const_stable)]
1445 pub struct TraitImplConstStable {
1450 #[derive(Diagnostic)]
1451 #[diag(passes_feature_only_on_nightly, code = "E0554")]
1452 pub struct FeatureOnlyOnNightly {
1455 pub release_channel: &'static str,
1458 #[derive(Diagnostic)]
1459 #[diag(passes_unknown_feature, code = "E0635")]
1460 pub struct UnknownFeature {
1463 pub feature: Symbol,
1466 #[derive(Diagnostic)]
1467 #[diag(passes_implied_feature_not_exist)]
1468 pub struct ImpliedFeatureNotExist {
1471 pub feature: Symbol,
1472 pub implied_by: Symbol,
1475 #[derive(Diagnostic)]
1476 #[diag(passes_duplicate_feature_err, code = "E0636")]
1477 pub struct DuplicateFeatureErr {
1480 pub feature: Symbol,
1482 #[derive(Diagnostic)]
1483 #[diag(passes_missing_const_err)]
1484 pub struct MissingConstErr {
1487 pub fn_sig_span: Span,
1489 pub const_span: Span,
1492 #[derive(LintDiagnostic)]
1493 pub enum MultipleDeadCodes<'tcx> {
1494 #[diag(passes_dead_codes)]
1499 participle: &'tcx str,
1500 name_list: DiagnosticSymbolList,
1502 parent_info: Option<ParentInfo<'tcx>>,
1504 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1506 #[diag(passes_dead_codes)]
1507 UnusedTupleStructFields {
1511 participle: &'tcx str,
1512 name_list: DiagnosticSymbolList,
1514 change_fields_suggestion: ChangeFieldsToBeOfUnitType,
1516 parent_info: Option<ParentInfo<'tcx>>,
1518 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1522 #[derive(Subdiagnostic)]
1523 #[label(passes_parent_info)]
1524 pub struct ParentInfo<'tcx> {
1526 pub descr: &'tcx str,
1527 pub parent_descr: &'tcx str,
1532 #[derive(Subdiagnostic)]
1533 #[note(passes_ignored_derived_impls)]
1534 pub struct IgnoredDerivedImpls {
1536 pub trait_list: DiagnosticSymbolList,
1537 pub trait_list_len: usize,
1540 #[derive(Subdiagnostic)]
1541 #[multipart_suggestion(passes_change_fields_to_be_of_unit_type, applicability = "has-placeholders")]
1542 pub struct ChangeFieldsToBeOfUnitType {
1544 #[suggestion_part(code = "()")]
1545 pub spans: Vec<Span>,
1548 #[derive(Diagnostic)]
1549 #[diag(passes_proc_macro_typeerror)]
1551 pub(crate) struct ProcMacroTypeError<'tcx> {
1555 pub found: Ty<'tcx>,
1556 pub kind: ProcMacroKind,
1557 pub expected_signature: &'static str,
1560 #[derive(Diagnostic)]
1561 #[diag(passes_proc_macro_diff_arg_count)]
1562 pub(crate) struct ProcMacroDiffArguments {
1567 pub kind: ProcMacroKind,
1568 pub expected_signature: &'static str,
1571 #[derive(Diagnostic)]
1572 #[diag(passes_proc_macro_missing_args)]
1573 pub(crate) struct ProcMacroMissingArguments {
1577 pub expected_input_count: usize,
1578 pub kind: ProcMacroKind,
1579 pub expected_signature: &'static str,
1582 #[derive(Diagnostic)]
1583 #[diag(passes_proc_macro_invalid_abi)]
1584 pub(crate) struct ProcMacroInvalidAbi {
1587 pub abi: &'static str,
1590 #[derive(Diagnostic)]
1591 #[diag(passes_proc_macro_unsafe)]
1592 pub(crate) struct ProcMacroUnsafe {
1597 #[derive(Diagnostic)]
1598 #[diag(passes_skipping_const_checks)]
1599 pub struct SkippingConstChecks {