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 rustc_errors::{pluralize, AddToDiagnostic, Diagnostic, SubdiagnosticMessage};
17 use crate::lang_items::Duplicate;
19 #[derive(LintDiagnostic)]
20 #[diag(passes_outer_crate_level_attr)]
21 pub struct OuterCrateLevelAttr;
23 #[derive(LintDiagnostic)]
24 #[diag(passes_inner_crate_level_attr)]
25 pub struct InnerCrateLevelAttr;
27 #[derive(LintDiagnostic)]
28 #[diag(passes_ignored_attr_with_macro)]
29 pub struct IgnoredAttrWithMacro<'a> {
33 #[derive(LintDiagnostic)]
34 #[diag(passes_ignored_attr)]
35 pub struct IgnoredAttr<'a> {
39 #[derive(LintDiagnostic)]
40 #[diag(passes_inline_ignored_function_prototype)]
41 pub struct IgnoredInlineAttrFnProto;
43 #[derive(LintDiagnostic)]
44 #[diag(passes_inline_ignored_constants)]
47 pub struct IgnoredInlineAttrConstants;
50 #[diag(passes_inline_not_fn_or_closure, code = "E0518")]
51 pub struct InlineNotFnOrClosure {
58 #[derive(LintDiagnostic)]
59 #[diag(passes_no_coverage_ignored_function_prototype)]
60 pub struct IgnoredNoCoverageFnProto;
62 #[derive(LintDiagnostic)]
63 #[diag(passes_no_coverage_propagate)]
64 pub struct IgnoredNoCoveragePropagate;
66 #[derive(LintDiagnostic)]
67 #[diag(passes_no_coverage_fn_defn)]
68 pub struct IgnoredNoCoverageFnDefn;
71 #[diag(passes_no_coverage_not_coverable, code = "E0788")]
72 pub struct IgnoredNoCoverageNotCoverable {
80 #[diag(passes_should_be_applied_to_fn)]
81 pub struct AttrShouldBeAppliedToFn {
89 #[diag(passes_naked_tracked_caller, code = "E0736")]
90 pub struct NakedTrackedCaller {
96 #[diag(passes_should_be_applied_to_fn, code = "E0739")]
97 pub struct TrackedCallerWrongLocation {
104 #[derive(Diagnostic)]
105 #[diag(passes_should_be_applied_to_struct_enum, code = "E0701")]
106 pub struct NonExhaustiveWrongLocation {
113 #[derive(Diagnostic)]
114 #[diag(passes_should_be_applied_to_trait)]
115 pub struct AttrShouldBeAppliedToTrait {
122 #[derive(LintDiagnostic)]
123 #[diag(passes_target_feature_on_statement)]
124 pub struct TargetFeatureOnStatement;
126 #[derive(Diagnostic)]
127 #[diag(passes_should_be_applied_to_static)]
128 pub struct AttrShouldBeAppliedToStatic {
135 #[derive(Diagnostic)]
136 #[diag(passes_doc_expect_str)]
137 pub struct DocExpectStr<'a> {
140 pub attr_name: &'a str,
143 #[derive(Diagnostic)]
144 #[diag(passes_doc_alias_empty)]
145 pub struct DocAliasEmpty<'a> {
148 pub attr_str: &'a str,
151 #[derive(Diagnostic)]
152 #[diag(passes_doc_alias_bad_char)]
153 pub struct DocAliasBadChar<'a> {
156 pub attr_str: &'a str,
160 #[derive(Diagnostic)]
161 #[diag(passes_doc_alias_start_end)]
162 pub struct DocAliasStartEnd<'a> {
165 pub attr_str: &'a str,
168 #[derive(Diagnostic)]
169 #[diag(passes_doc_alias_bad_location)]
170 pub struct DocAliasBadLocation<'a> {
173 pub attr_str: &'a str,
174 pub location: &'a str,
177 #[derive(Diagnostic)]
178 #[diag(passes_doc_alias_not_an_alias)]
179 pub struct DocAliasNotAnAlias<'a> {
182 pub attr_str: &'a str,
185 #[derive(LintDiagnostic)]
186 #[diag(passes_doc_alias_duplicated)]
187 pub struct DocAliasDuplicated {
189 pub first_defn: Span,
192 #[derive(Diagnostic)]
193 #[diag(passes_doc_alias_not_string_literal)]
194 pub struct DocAliasNotStringLiteral {
199 #[derive(Diagnostic)]
200 #[diag(passes_doc_alias_malformed)]
201 pub struct DocAliasMalformed {
206 #[derive(Diagnostic)]
207 #[diag(passes_doc_keyword_empty_mod)]
208 pub struct DocKeywordEmptyMod {
213 #[derive(Diagnostic)]
214 #[diag(passes_doc_keyword_not_mod)]
215 pub struct DocKeywordNotMod {
220 #[derive(Diagnostic)]
221 #[diag(passes_doc_keyword_invalid_ident)]
222 pub struct DocKeywordInvalidIdent {
225 pub doc_keyword: Symbol,
228 #[derive(Diagnostic)]
229 #[diag(passes_doc_fake_variadic_not_valid)]
230 pub struct DocFakeVariadicNotValid {
235 #[derive(Diagnostic)]
236 #[diag(passes_doc_keyword_only_impl)]
237 pub struct DocKeywordOnlyImpl {
242 #[derive(Diagnostic)]
243 #[diag(passes_doc_inline_conflict)]
245 pub struct DocKeywordConflict {
247 pub spans: MultiSpan,
250 #[derive(LintDiagnostic)]
251 #[diag(passes_doc_inline_only_use)]
253 pub struct DocInlineOnlyUse {
256 #[label(not_a_use_item_label)]
257 pub item_span: Option<Span>,
260 #[derive(Diagnostic)]
261 #[diag(passes_doc_attr_not_crate_level)]
262 pub struct DocAttrNotCrateLevel<'a> {
265 pub attr_name: &'a str,
268 #[derive(LintDiagnostic)]
269 #[diag(passes_doc_test_unknown)]
270 pub struct DocTestUnknown {
274 #[derive(LintDiagnostic)]
275 #[diag(passes_doc_test_takes_list)]
276 pub struct DocTestTakesList;
278 #[derive(LintDiagnostic)]
279 #[diag(passes_doc_cfg_hide_takes_list)]
280 pub struct DocCfgHideTakesList;
282 #[derive(LintDiagnostic)]
283 #[diag(passes_doc_primitive)]
284 pub struct DocPrimitive;
286 #[derive(LintDiagnostic)]
287 #[diag(passes_doc_test_unknown_any)]
288 pub struct DocTestUnknownAny {
292 #[derive(LintDiagnostic)]
293 #[diag(passes_doc_test_unknown_spotlight)]
296 pub struct DocTestUnknownSpotlight {
298 #[suggestion_short(applicability = "machine-applicable", code = "notable_trait")]
302 #[derive(LintDiagnostic)]
303 #[diag(passes_doc_test_unknown_include)]
304 pub struct DocTestUnknownInclude {
307 pub inner: &'static str,
308 #[suggestion(code = "#{inner}[doc = include_str!(\"{value}\")]")]
309 pub sugg: (Span, Applicability),
312 #[derive(LintDiagnostic)]
313 #[diag(passes_doc_invalid)]
314 pub struct DocInvalid;
316 #[derive(Diagnostic)]
317 #[diag(passes_pass_by_value)]
318 pub struct PassByValue {
325 #[derive(Diagnostic)]
326 #[diag(passes_allow_incoherent_impl)]
327 pub struct AllowIncoherentImpl {
334 #[derive(Diagnostic)]
335 #[diag(passes_has_incoherent_inherent_impl)]
336 pub struct HasIncoherentInherentImpl {
343 #[derive(LintDiagnostic)]
344 #[diag(passes_must_use_async)]
345 pub struct MustUseAsync {
350 #[derive(LintDiagnostic)]
351 #[diag(passes_must_use_no_effect)]
352 pub struct MustUseNoEffect {
353 pub article: &'static str,
354 pub target: rustc_hir::Target,
357 #[derive(Diagnostic)]
358 #[diag(passes_must_not_suspend)]
359 pub struct MustNotSuspend {
366 #[derive(LintDiagnostic)]
374 #[derive(LintDiagnostic)]
379 pub span: Option<Span>,
382 #[derive(LintDiagnostic)]
383 #[diag(passes_link_name)]
385 pub struct LinkName<'a> {
387 pub attr_span: Option<Span>,
393 #[derive(Diagnostic)]
394 #[diag(passes_no_link)]
402 #[derive(Diagnostic)]
403 #[diag(passes_export_name)]
404 pub struct ExportName {
411 #[derive(Diagnostic)]
412 #[diag(passes_rustc_layout_scalar_valid_range_not_struct)]
413 pub struct RustcLayoutScalarValidRangeNotStruct {
420 #[derive(Diagnostic)]
421 #[diag(passes_rustc_layout_scalar_valid_range_arg)]
422 pub struct RustcLayoutScalarValidRangeArg {
427 #[derive(Diagnostic)]
428 #[diag(passes_rustc_legacy_const_generics_only)]
429 pub struct RustcLegacyConstGenericsOnly {
433 pub param_span: Span,
436 #[derive(Diagnostic)]
437 #[diag(passes_rustc_legacy_const_generics_index)]
438 pub struct RustcLegacyConstGenericsIndex {
442 pub generics_span: Span,
445 #[derive(Diagnostic)]
446 #[diag(passes_rustc_legacy_const_generics_index_exceed)]
447 pub struct RustcLegacyConstGenericsIndexExceed {
451 pub arg_count: usize,
454 #[derive(Diagnostic)]
455 #[diag(passes_rustc_legacy_const_generics_index_negative)]
456 pub struct RustcLegacyConstGenericsIndexNegative {
458 pub invalid_args: Vec<Span>,
461 #[derive(Diagnostic)]
462 #[diag(passes_rustc_dirty_clean)]
463 pub struct RustcDirtyClean {
468 #[derive(LintDiagnostic)]
469 #[diag(passes_link_section)]
471 pub struct LinkSection {
476 #[derive(LintDiagnostic)]
477 #[diag(passes_no_mangle_foreign)]
480 pub struct NoMangleForeign {
483 #[suggestion(code = "", applicability = "machine-applicable")]
485 pub foreign_item_kind: &'static str,
488 #[derive(LintDiagnostic)]
489 #[diag(passes_no_mangle)]
491 pub struct NoMangle {
496 #[derive(Diagnostic)]
497 #[diag(passes_repr_ident, code = "E0565")]
498 pub struct ReprIdent {
503 #[derive(LintDiagnostic)]
504 #[diag(passes_repr_conflicting, code = "E0566")]
505 pub struct ReprConflicting;
507 #[derive(Diagnostic)]
508 #[diag(passes_used_static)]
509 pub struct UsedStatic {
514 #[derive(Diagnostic)]
515 #[diag(passes_used_compiler_linker)]
516 pub struct UsedCompilerLinker {
518 pub spans: Vec<Span>,
521 #[derive(Diagnostic)]
522 #[diag(passes_allow_internal_unstable)]
523 pub struct AllowInternalUnstable {
530 #[derive(Diagnostic)]
531 #[diag(passes_debug_visualizer_placement)]
532 pub struct DebugVisualizerPlacement {
537 #[derive(Diagnostic)]
538 #[diag(passes_debug_visualizer_invalid)]
542 pub struct DebugVisualizerInvalid {
547 #[derive(Diagnostic)]
548 #[diag(passes_debug_visualizer_unreadable)]
549 pub struct DebugVisualizerUnreadable<'a> {
556 #[derive(Diagnostic)]
557 #[diag(passes_rustc_allow_const_fn_unstable)]
558 pub struct RustcAllowConstFnUnstable {
565 #[derive(Diagnostic)]
566 #[diag(passes_rustc_std_internal_symbol)]
567 pub struct RustcStdInternalSymbol {
574 #[derive(Diagnostic)]
575 #[diag(passes_const_trait)]
576 pub struct ConstTrait {
581 #[derive(Diagnostic)]
582 #[diag(passes_link_ordinal)]
583 pub struct LinkOrdinal {
588 #[derive(Diagnostic)]
589 #[diag(passes_stability_promotable)]
590 pub struct StabilityPromotable {
595 #[derive(LintDiagnostic)]
596 #[diag(passes_deprecated)]
597 pub struct Deprecated;
599 #[derive(LintDiagnostic)]
600 #[diag(passes_macro_use)]
601 pub struct MacroUse {
605 #[derive(LintDiagnostic)]
606 #[diag(passes_macro_export)]
607 pub struct MacroExport;
609 #[derive(LintDiagnostic)]
610 #[diag(passes_plugin_registrar)]
611 pub struct PluginRegistrar;
613 #[derive(Subdiagnostic)]
614 pub enum UnusedNote {
615 #[note(passes_unused_empty_lints_note)]
616 EmptyList { name: Symbol },
617 #[note(passes_unused_no_lints_note)]
618 NoLints { name: Symbol },
619 #[note(passes_unused_default_method_body_const_note)]
620 DefaultMethodBodyConst,
623 #[derive(LintDiagnostic)]
624 #[diag(passes_unused)]
626 #[suggestion(code = "", applicability = "machine-applicable")]
629 pub note: UnusedNote,
632 #[derive(Diagnostic)]
633 #[diag(passes_non_exported_macro_invalid_attrs, code = "E0518")]
634 pub struct NonExportedMacroInvalidAttrs {
640 #[derive(LintDiagnostic)]
641 #[diag(passes_unused_duplicate)]
642 pub struct UnusedDuplicate {
643 #[suggestion(code = "", applicability = "machine-applicable")]
648 pub warning: Option<()>,
651 #[derive(Diagnostic)]
652 #[diag(passes_unused_multiple)]
653 pub struct UnusedMultiple {
655 #[suggestion(code = "", applicability = "machine-applicable")]
662 #[derive(Diagnostic)]
663 #[diag(passes_rustc_lint_opt_ty)]
664 pub struct RustcLintOptTy {
671 #[derive(Diagnostic)]
672 #[diag(passes_rustc_lint_opt_deny_field_access)]
673 pub struct RustcLintOptDenyFieldAccess {
680 #[derive(Diagnostic)]
681 #[diag(passes_collapse_debuginfo)]
682 pub struct CollapseDebuginfo {
689 #[derive(LintDiagnostic)]
690 #[diag(passes_deprecated_annotation_has_no_effect)]
691 pub struct DeprecatedAnnotationHasNoEffect {
692 #[suggestion(applicability = "machine-applicable", code = "")]
696 #[derive(Diagnostic)]
697 #[diag(passes_unknown_external_lang_item, code = "E0264")]
698 pub struct UnknownExternLangItem {
701 pub lang_item: Symbol,
704 #[derive(Diagnostic)]
705 #[diag(passes_missing_panic_handler)]
706 pub struct MissingPanicHandler;
708 #[derive(Diagnostic)]
709 #[diag(passes_alloc_func_required)]
710 pub struct AllocFuncRequired;
712 #[derive(Diagnostic)]
713 #[diag(passes_missing_alloc_error_handler)]
714 pub struct MissingAllocErrorHandler;
716 #[derive(Diagnostic)]
717 #[diag(passes_missing_lang_item)]
720 pub struct MissingLangItem {
724 #[derive(Diagnostic)]
725 #[diag(passes_lang_item_on_incorrect_target, code = "E0718")]
726 pub struct LangItemOnIncorrectTarget {
731 pub expected_target: Target,
732 pub actual_target: Target,
735 #[derive(Diagnostic)]
736 #[diag(passes_unknown_lang_item, code = "E0522")]
737 pub struct UnknownLangItem {
744 pub struct InvalidAttrAtCrateLevel {
746 pub snippet: Option<String>,
750 impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel {
753 handler: &'_ rustc_errors::Handler,
754 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
755 let mut diag = handler.struct_err(rustc_errors::fluent::passes_invalid_attr_at_crate_level);
756 diag.set_span(self.span);
757 diag.set_arg("name", self.name);
758 // Only emit an error with a suggestion if we can create a string out
759 // of the attribute span
760 if let Some(src) = self.snippet {
761 let replacement = src.replace("#!", "#");
762 diag.span_suggestion_verbose(
764 rustc_errors::fluent::suggestion,
766 rustc_errors::Applicability::MachineApplicable,
773 #[derive(Diagnostic)]
774 #[diag(passes_duplicate_diagnostic_item)]
775 pub struct DuplicateDiagnosticItem {
781 #[derive(Diagnostic)]
782 #[diag(passes_duplicate_diagnostic_item_in_crate)]
783 pub struct DuplicateDiagnosticItemInCrate {
784 #[note(passes_diagnostic_item_first_defined)]
785 pub span: Option<Span>,
786 pub orig_crate_name: Symbol,
788 pub have_orig_crate_name: Option<()>,
789 pub crate_name: Symbol,
793 #[derive(Diagnostic)]
801 #[derive(Diagnostic)]
802 #[diag(passes_align)]
809 #[derive(Diagnostic)]
817 #[derive(Diagnostic)]
818 #[diag(passes_homogeneous_aggregate)]
819 pub struct HomogeneousAggregate {
822 pub homogeneous_aggregate: String,
825 #[derive(Diagnostic)]
826 #[diag(passes_layout_of)]
827 pub struct LayoutOf {
830 pub normalized_ty: String,
831 pub ty_layout: String,
834 #[derive(Diagnostic)]
835 #[diag(passes_unrecognized_field)]
836 pub struct UnrecognizedField {
842 #[derive(Diagnostic)]
843 #[diag(passes_feature_stable_twice, code = "E0711")]
844 pub struct FeatureStableTwice {
849 pub prev_since: Symbol,
852 #[derive(Diagnostic)]
853 #[diag(passes_feature_previously_declared, code = "E0711")]
854 pub struct FeaturePreviouslyDeclared<'a, 'b> {
858 pub declared: &'a str,
859 pub prev_declared: &'b str,
862 #[derive(Diagnostic)]
863 #[diag(passes_expr_not_allowed_in_context, code = "E0744")]
864 pub struct ExprNotAllowedInContext<'a> {
868 pub context: &'a str,
871 pub struct BreakNonLoop<'a> {
873 pub head: Option<Span>,
875 pub suggestion: String,
876 pub loop_label: Option<Label>,
877 pub break_label: Option<Label>,
878 pub break_expr_kind: &'a ExprKind<'a>,
879 pub break_expr_span: Span,
882 impl<'a> IntoDiagnostic<'_> for BreakNonLoop<'a> {
885 handler: &rustc_errors::Handler,
886 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
887 let mut diag = handler.struct_span_err_with_code(
889 rustc_errors::fluent::passes_break_non_loop,
892 diag.set_arg("kind", self.kind);
893 diag.span_label(self.span, rustc_errors::fluent::label);
894 if let Some(head) = self.head {
895 diag.span_label(head, rustc_errors::fluent::label2);
897 diag.span_suggestion(
899 rustc_errors::fluent::suggestion,
901 Applicability::MaybeIncorrect,
903 if let (Some(label), None) = (self.loop_label, self.break_label) {
904 match self.break_expr_kind {
905 ExprKind::Path(hir::QPath::Resolved(
907 hir::Path { segments: [segment], res: hir::def::Res::Err, .. },
908 )) if label.ident.to_string() == format!("'{}", segment.ident) => {
909 // This error is redundant, we will have already emitted a
910 // suggestion to use the label when `segment` wasn't found
911 // (hence the `Res::Err` check).
915 diag.span_suggestion(
916 self.break_expr_span,
917 rustc_errors::fluent::break_expr_suggestion,
919 Applicability::MaybeIncorrect,
928 #[derive(Diagnostic)]
929 #[diag(passes_continue_labeled_block, code = "E0696")]
930 pub struct ContinueLabeledBlock {
934 #[label(block_label)]
935 pub block_span: Span,
938 #[derive(Diagnostic)]
939 #[diag(passes_break_inside_closure, code = "E0267")]
940 pub struct BreakInsideClosure<'a> {
944 #[label(closure_label)]
945 pub closure_span: Span,
949 #[derive(Diagnostic)]
950 #[diag(passes_break_inside_async_block, code = "E0267")]
951 pub struct BreakInsideAsyncBlock<'a> {
955 #[label(async_block_label)]
956 pub closure_span: Span,
960 #[derive(Diagnostic)]
961 #[diag(passes_outside_loop, code = "E0268")]
962 pub struct OutsideLoop<'a> {
969 #[derive(Diagnostic)]
970 #[diag(passes_unlabeled_in_labeled_block, code = "E0695")]
971 pub struct UnlabeledInLabeledBlock<'a> {
975 pub cf_type: &'a str,
978 #[derive(Diagnostic)]
979 #[diag(passes_unlabeled_cf_in_while_condition, code = "E0590")]
980 pub struct UnlabeledCfInWhileCondition<'a> {
984 pub cf_type: &'a str,
987 #[derive(Diagnostic)]
988 #[diag(passes_cannot_inline_naked_function)]
989 pub struct CannotInlineNakedFunction {
994 #[derive(LintDiagnostic)]
995 #[diag(passes_undefined_naked_function_abi)]
996 pub struct UndefinedNakedFunctionAbi;
998 #[derive(Diagnostic)]
999 #[diag(passes_no_patterns)]
1000 pub struct NoPatterns {
1005 #[derive(Diagnostic)]
1006 #[diag(passes_params_not_allowed)]
1008 pub struct ParamsNotAllowed {
1013 pub struct NakedFunctionsAsmBlock {
1015 pub multiple_asms: Vec<Span>,
1016 pub non_asms: Vec<Span>,
1019 impl IntoDiagnostic<'_> for NakedFunctionsAsmBlock {
1022 handler: &rustc_errors::Handler,
1023 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
1024 let mut diag = handler.struct_span_err_with_code(
1026 rustc_errors::fluent::passes_naked_functions_asm_block,
1029 for span in self.multiple_asms.iter() {
1030 diag.span_label(*span, rustc_errors::fluent::label_multiple_asm);
1032 for span in self.non_asms.iter() {
1033 diag.span_label(*span, rustc_errors::fluent::label_non_asm);
1039 #[derive(Diagnostic)]
1040 #[diag(passes_naked_functions_operands, code = "E0787")]
1041 pub struct NakedFunctionsOperands {
1043 pub unsupported_operands: Vec<Span>,
1046 #[derive(Diagnostic)]
1047 #[diag(passes_naked_functions_asm_options, code = "E0787")]
1048 pub struct NakedFunctionsAsmOptions {
1051 pub unsupported_options: String,
1054 #[derive(Diagnostic)]
1055 #[diag(passes_naked_functions_must_use_noreturn, code = "E0787")]
1056 pub struct NakedFunctionsMustUseNoreturn {
1059 #[suggestion(code = ", options(noreturn)", applicability = "machine-applicable")]
1060 pub last_span: Span,
1063 #[derive(Diagnostic)]
1064 #[diag(passes_attr_only_on_main)]
1065 pub struct AttrOnlyOnMain {
1071 #[derive(Diagnostic)]
1072 #[diag(passes_attr_only_on_root_main)]
1073 pub struct AttrOnlyOnRootMain {
1079 #[derive(Diagnostic)]
1080 #[diag(passes_attr_only_in_functions)]
1081 pub struct AttrOnlyInFunctions {
1087 #[derive(Diagnostic)]
1088 #[diag(passes_multiple_rustc_main, code = "E0137")]
1089 pub struct MultipleRustcMain {
1094 #[label(additional)]
1095 pub additional: Span,
1098 #[derive(Diagnostic)]
1099 #[diag(passes_multiple_start_functions, code = "E0138")]
1100 pub struct MultipleStartFunctions {
1109 #[derive(Diagnostic)]
1110 #[diag(passes_extern_main)]
1111 pub struct ExternMain {
1116 #[derive(Diagnostic)]
1117 #[diag(passes_unix_sigpipe_values)]
1118 pub struct UnixSigpipeValues {
1123 #[derive(Diagnostic)]
1124 #[diag(passes_no_main_function, code = "E0601")]
1125 pub struct NoMainFunction {
1128 pub crate_name: String,
1131 pub struct NoMainErr {
1133 pub crate_name: Symbol,
1134 pub has_filename: bool,
1135 pub filename: PathBuf,
1136 pub file_empty: bool,
1137 pub non_main_fns: Vec<Span>,
1138 pub main_def_opt: Option<MainDefinition>,
1139 pub add_teach_note: bool,
1142 impl<'a> IntoDiagnostic<'a> for NoMainErr {
1145 handler: &'a rustc_errors::Handler,
1146 ) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> {
1147 let mut diag = handler.struct_span_err_with_code(
1149 rustc_errors::fluent::passes_no_main_function,
1152 diag.set_arg("crate_name", self.crate_name);
1153 diag.set_arg("filename", self.filename);
1154 diag.set_arg("has_filename", self.has_filename);
1155 let note = if !self.non_main_fns.is_empty() {
1156 for &span in &self.non_main_fns {
1157 diag.span_note(span, rustc_errors::fluent::here_is_main);
1159 diag.note(rustc_errors::fluent::one_or_more_possible_main);
1160 diag.help(rustc_errors::fluent::consider_moving_main);
1161 // There were some functions named `main` though. Try to give the user a hint.
1162 rustc_errors::fluent::main_must_be_defined_at_crate
1163 } else if self.has_filename {
1164 rustc_errors::fluent::consider_adding_main_to_file
1166 rustc_errors::fluent::consider_adding_main_at_crate
1168 if self.file_empty {
1171 diag.set_span(self.sp.shrink_to_hi());
1172 diag.span_label(self.sp.shrink_to_hi(), note);
1175 if let Some(main_def) = self.main_def_opt && main_def.opt_fn_def_id().is_none(){
1176 // There is something at `crate::main`, but it is not a function definition.
1177 diag.span_label(main_def.span, rustc_errors::fluent::non_function_main);
1180 if self.add_teach_note {
1181 diag.note(rustc_errors::fluent::teach_note);
1187 pub struct DuplicateLangItem {
1188 pub local_span: Option<Span>,
1189 pub lang_item_name: Symbol,
1190 pub crate_name: Symbol,
1191 pub dependency_of: Symbol,
1194 pub first_defined_span: Option<Span>,
1195 pub orig_crate_name: Symbol,
1196 pub orig_dependency_of: Symbol,
1197 pub orig_is_local: bool,
1198 pub orig_path: String,
1199 pub(crate) duplicate: Duplicate,
1202 impl IntoDiagnostic<'_> for DuplicateLangItem {
1205 handler: &rustc_errors::Handler,
1206 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
1207 let mut diag = handler.struct_err_with_code(
1208 match self.duplicate {
1209 Duplicate::Plain => rustc_errors::fluent::passes_duplicate_lang_item,
1211 Duplicate::Crate => rustc_errors::fluent::passes_duplicate_lang_item_crate,
1212 Duplicate::CrateDepends => {
1213 rustc_errors::fluent::passes_duplicate_lang_item_crate_depends
1218 diag.set_arg("lang_item_name", self.lang_item_name);
1219 diag.set_arg("crate_name", self.crate_name);
1220 diag.set_arg("dependency_of", self.dependency_of);
1221 diag.set_arg("path", self.path);
1222 diag.set_arg("orig_crate_name", self.orig_crate_name);
1223 diag.set_arg("orig_dependency_of", self.orig_dependency_of);
1224 diag.set_arg("orig_path", self.orig_path);
1225 if let Some(span) = self.local_span {
1226 diag.set_span(span);
1228 if let Some(span) = self.first_defined_span {
1229 diag.span_note(span, rustc_errors::fluent::first_defined_span);
1231 if self.orig_dependency_of.is_empty() {
1232 diag.note(rustc_errors::fluent::first_defined_crate);
1234 diag.note(rustc_errors::fluent::first_defined_crate_depends);
1237 if self.orig_is_local {
1238 diag.note(rustc_errors::fluent::first_definition_local);
1240 diag.note(rustc_errors::fluent::first_definition_path);
1244 diag.note(rustc_errors::fluent::second_definition_local);
1246 diag.note(rustc_errors::fluent::second_definition_path);
1253 #[derive(Diagnostic)]
1254 #[diag(passes_incorrect_target, code = "E0718")]
1255 pub struct IncorrectTarget<'a> {
1259 pub generics_span: Span,
1260 pub name: &'a str, // cannot be symbol because it renders e.g. `r#fn` instead of `fn`
1261 pub kind: &'static str,
1263 pub actual_num: usize,
1267 #[derive(LintDiagnostic)]
1268 #[diag(passes_useless_assignment)]
1269 pub struct UselessAssignment<'a> {
1270 pub is_field_assign: bool,
1274 #[derive(LintDiagnostic)]
1275 #[diag(passes_only_has_effect_on)]
1276 pub struct OnlyHasEffectOn {
1277 pub attr_name: Symbol,
1278 pub target_name: String,
1281 #[derive(Diagnostic)]
1282 #[diag(passes_object_lifetime_err)]
1283 pub struct ObjectLifetimeErr {
1289 #[derive(Diagnostic)]
1290 #[diag(passes_unrecognized_repr_hint, code = "E0552")]
1292 pub struct UnrecognizedReprHint {
1297 #[derive(Diagnostic)]
1298 pub enum AttrApplication {
1299 #[diag(passes_attr_application_enum, code = "E0517")]
1306 #[diag(passes_attr_application_struct, code = "E0517")]
1313 #[diag(passes_attr_application_struct_union, code = "E0517")]
1320 #[diag(passes_attr_application_struct_enum_union, code = "E0517")]
1327 #[diag(passes_attr_application_struct_enum_function_union, code = "E0517")]
1328 StructEnumFunctionUnion {
1336 #[derive(Diagnostic)]
1337 #[diag(passes_transparent_incompatible, code = "E0692")]
1338 pub struct TransparentIncompatible {
1340 pub hint_spans: Vec<Span>,
1344 #[derive(Diagnostic)]
1345 #[diag(passes_deprecated_attribute, code = "E0549")]
1346 pub struct DeprecatedAttribute {
1351 #[derive(Diagnostic)]
1352 #[diag(passes_useless_stability)]
1353 pub struct UselessStability {
1361 #[derive(Diagnostic)]
1362 #[diag(passes_invalid_stability)]
1363 pub struct InvalidStability {
1371 #[derive(Diagnostic)]
1372 #[diag(passes_cannot_stabilize_deprecated)]
1373 pub struct CannotStabilizeDeprecated {
1381 #[derive(Diagnostic)]
1382 #[diag(passes_invalid_deprecation_version)]
1383 pub struct InvalidDeprecationVersion {
1391 #[derive(Diagnostic)]
1392 #[diag(passes_missing_stability_attr)]
1393 pub struct MissingStabilityAttr<'a> {
1399 #[derive(Diagnostic)]
1400 #[diag(passes_missing_const_stab_attr)]
1401 pub struct MissingConstStabAttr<'a> {
1407 #[derive(Diagnostic)]
1408 #[diag(passes_trait_impl_const_stable)]
1410 pub struct TraitImplConstStable {
1415 #[derive(Diagnostic)]
1416 #[diag(passes_feature_only_on_nightly, code = "E0554")]
1417 pub struct FeatureOnlyOnNightly {
1420 pub release_channel: &'static str,
1423 #[derive(Diagnostic)]
1424 #[diag(passes_unknown_feature, code = "E0635")]
1425 pub struct UnknownFeature {
1428 pub feature: Symbol,
1431 #[derive(Diagnostic)]
1432 #[diag(passes_implied_feature_not_exist)]
1433 pub struct ImpliedFeatureNotExist {
1436 pub feature: Symbol,
1437 pub implied_by: Symbol,
1440 #[derive(Diagnostic)]
1441 #[diag(passes_duplicate_feature_err, code = "E0636")]
1442 pub struct DuplicateFeatureErr {
1445 pub feature: Symbol,
1447 #[derive(Diagnostic)]
1448 #[diag(passes_missing_const_err)]
1449 pub struct MissingConstErr {
1452 pub fn_sig_span: Span,
1454 pub const_span: Span,
1457 #[derive(LintDiagnostic)]
1458 pub enum MultipleDeadCodes<'tcx> {
1459 #[diag(passes_dead_codes)]
1464 participle: &'tcx str,
1465 name_list: DiagnosticSymbolList,
1467 parent_info: Option<ParentInfo<'tcx>>,
1469 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1471 #[diag(passes_dead_codes)]
1472 UnusedTupleStructFields {
1476 participle: &'tcx str,
1477 name_list: DiagnosticSymbolList,
1479 change_fields_suggestion: ChangeFieldsToBeOfUnitType,
1481 parent_info: Option<ParentInfo<'tcx>>,
1483 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1487 #[derive(Subdiagnostic)]
1488 #[label(passes_parent_info)]
1489 pub struct ParentInfo<'tcx> {
1491 pub descr: &'tcx str,
1492 pub parent_descr: &'tcx str,
1497 #[derive(Subdiagnostic)]
1498 #[note(passes_ignored_derived_impls)]
1499 pub struct IgnoredDerivedImpls {
1501 pub trait_list: DiagnosticSymbolList,
1502 pub trait_list_len: usize,
1505 pub struct ChangeFieldsToBeOfUnitType {
1507 pub spans: Vec<Span>,
1510 // FIXME: Replace this impl with a derive.
1511 impl AddToDiagnostic for ChangeFieldsToBeOfUnitType {
1512 fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
1514 F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
1516 diag.multipart_suggestion(
1518 "consider changing the field{s} to be of unit type to \
1519 suppress this warning while preserving the field \
1520 numbering, or remove the field{s}",
1521 s = pluralize!(self.num)
1523 self.spans.iter().map(|sp| (*sp, "()".to_string())).collect(),
1524 // "HasPlaceholders" because applying this fix by itself isn't
1525 // enough: All constructor calls have to be adjusted as well
1526 Applicability::HasPlaceholders,