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;
18 #[derive(LintDiagnostic)]
19 #[diag(passes_outer_crate_level_attr)]
20 pub struct OuterCrateLevelAttr;
22 #[derive(LintDiagnostic)]
23 #[diag(passes_inner_crate_level_attr)]
24 pub struct InnerCrateLevelAttr;
26 #[derive(LintDiagnostic)]
27 #[diag(passes_ignored_attr_with_macro)]
28 pub struct IgnoredAttrWithMacro<'a> {
32 #[derive(LintDiagnostic)]
33 #[diag(passes_ignored_attr)]
34 pub struct IgnoredAttr<'a> {
38 #[derive(LintDiagnostic)]
39 #[diag(passes_inline_ignored_function_prototype)]
40 pub struct IgnoredInlineAttrFnProto;
42 #[derive(LintDiagnostic)]
43 #[diag(passes_inline_ignored_constants)]
46 pub struct IgnoredInlineAttrConstants;
49 #[diag(passes_inline_not_fn_or_closure, code = "E0518")]
50 pub struct InlineNotFnOrClosure {
57 #[derive(LintDiagnostic)]
58 #[diag(passes_no_coverage_ignored_function_prototype)]
59 pub struct IgnoredNoCoverageFnProto;
61 #[derive(LintDiagnostic)]
62 #[diag(passes_no_coverage_propagate)]
63 pub struct IgnoredNoCoveragePropagate;
65 #[derive(LintDiagnostic)]
66 #[diag(passes_no_coverage_fn_defn)]
67 pub struct IgnoredNoCoverageFnDefn;
70 #[diag(passes_no_coverage_not_coverable, code = "E0788")]
71 pub struct IgnoredNoCoverageNotCoverable {
79 #[diag(passes_should_be_applied_to_fn)]
80 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 {
105 #[derive(Diagnostic)]
106 #[diag(passes_should_be_applied_to_struct_enum, code = "E0701")]
107 pub struct NonExhaustiveWrongLocation {
114 #[derive(Diagnostic)]
115 #[diag(passes_should_be_applied_to_trait)]
116 pub struct AttrShouldBeAppliedToTrait {
123 #[derive(LintDiagnostic)]
124 #[diag(passes_target_feature_on_statement)]
125 pub struct TargetFeatureOnStatement;
127 #[derive(Diagnostic)]
128 #[diag(passes_should_be_applied_to_static)]
129 pub struct AttrShouldBeAppliedToStatic {
136 #[derive(Diagnostic)]
137 #[diag(passes_doc_expect_str)]
138 pub struct DocExpectStr<'a> {
141 pub attr_name: &'a str,
144 #[derive(Diagnostic)]
145 #[diag(passes_doc_alias_empty)]
146 pub struct DocAliasEmpty<'a> {
149 pub attr_str: &'a str,
152 #[derive(Diagnostic)]
153 #[diag(passes_doc_alias_bad_char)]
154 pub struct DocAliasBadChar<'a> {
157 pub attr_str: &'a str,
161 #[derive(Diagnostic)]
162 #[diag(passes_doc_alias_start_end)]
163 pub struct DocAliasStartEnd<'a> {
166 pub attr_str: &'a str,
169 #[derive(Diagnostic)]
170 #[diag(passes_doc_alias_bad_location)]
171 pub struct DocAliasBadLocation<'a> {
174 pub attr_str: &'a str,
175 pub location: &'a str,
178 #[derive(Diagnostic)]
179 #[diag(passes_doc_alias_not_an_alias)]
180 pub struct DocAliasNotAnAlias<'a> {
183 pub attr_str: &'a str,
186 #[derive(LintDiagnostic)]
187 #[diag(passes_doc_alias_duplicated)]
188 pub struct DocAliasDuplicated {
190 pub first_defn: Span,
193 #[derive(Diagnostic)]
194 #[diag(passes_doc_alias_not_string_literal)]
195 pub struct DocAliasNotStringLiteral {
200 #[derive(Diagnostic)]
201 #[diag(passes_doc_alias_malformed)]
202 pub struct DocAliasMalformed {
207 #[derive(Diagnostic)]
208 #[diag(passes_doc_keyword_empty_mod)]
209 pub struct DocKeywordEmptyMod {
214 #[derive(Diagnostic)]
215 #[diag(passes_doc_keyword_not_mod)]
216 pub struct DocKeywordNotMod {
221 #[derive(Diagnostic)]
222 #[diag(passes_doc_keyword_invalid_ident)]
223 pub struct DocKeywordInvalidIdent {
226 pub doc_keyword: Symbol,
229 #[derive(Diagnostic)]
230 #[diag(passes_doc_fake_variadic_not_valid)]
231 pub struct DocFakeVariadicNotValid {
236 #[derive(Diagnostic)]
237 #[diag(passes_doc_keyword_only_impl)]
238 pub struct DocKeywordOnlyImpl {
243 #[derive(Diagnostic)]
244 #[diag(passes_doc_inline_conflict)]
246 pub struct DocKeywordConflict {
248 pub spans: MultiSpan,
251 #[derive(LintDiagnostic)]
252 #[diag(passes_doc_inline_only_use)]
254 pub struct DocInlineOnlyUse {
257 #[label(not_a_use_item_label)]
258 pub item_span: Option<Span>,
261 #[derive(Diagnostic)]
262 #[diag(passes_doc_attr_not_crate_level)]
263 pub struct DocAttrNotCrateLevel<'a> {
266 pub attr_name: &'a str,
269 #[derive(LintDiagnostic)]
270 #[diag(passes_doc_test_unknown)]
271 pub struct DocTestUnknown {
275 #[derive(LintDiagnostic)]
276 #[diag(passes_doc_test_takes_list)]
277 pub struct DocTestTakesList;
279 #[derive(LintDiagnostic)]
280 #[diag(passes_doc_cfg_hide_takes_list)]
281 pub struct DocCfgHideTakesList;
283 #[derive(LintDiagnostic)]
284 #[diag(passes_doc_primitive)]
285 pub struct DocPrimitive;
287 #[derive(LintDiagnostic)]
288 #[diag(passes_doc_test_unknown_any)]
289 pub struct DocTestUnknownAny {
293 #[derive(LintDiagnostic)]
294 #[diag(passes_doc_test_unknown_spotlight)]
297 pub struct DocTestUnknownSpotlight {
299 #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")]
303 #[derive(LintDiagnostic)]
304 #[diag(passes_doc_test_unknown_include)]
305 pub struct DocTestUnknownInclude {
308 pub inner: &'static str,
309 #[suggestion(code = "#{inner}[doc = include_str!(\"{value}\")]")]
310 pub sugg: (Span, Applicability),
313 #[derive(LintDiagnostic)]
314 #[diag(passes_doc_invalid)]
315 pub struct DocInvalid;
317 #[derive(Diagnostic)]
318 #[diag(passes_pass_by_value)]
319 pub struct PassByValue {
326 #[derive(Diagnostic)]
327 #[diag(passes_allow_incoherent_impl)]
328 pub struct AllowIncoherentImpl {
335 #[derive(Diagnostic)]
336 #[diag(passes_has_incoherent_inherent_impl)]
337 pub struct HasIncoherentInherentImpl {
344 #[derive(LintDiagnostic)]
345 #[diag(passes_must_use_async)]
346 pub struct MustUseAsync {
351 #[derive(LintDiagnostic)]
352 #[diag(passes_must_use_no_effect)]
353 pub struct MustUseNoEffect {
354 pub article: &'static str,
355 pub target: rustc_hir::Target,
358 #[derive(Diagnostic)]
359 #[diag(passes_must_not_suspend)]
360 pub struct MustNotSuspend {
367 #[derive(LintDiagnostic)]
376 #[derive(LintDiagnostic)]
381 pub span: Option<Span>,
384 #[derive(LintDiagnostic)]
385 #[diag(passes_link_name)]
387 pub struct LinkName<'a> {
389 pub attr_span: Option<Span>,
395 #[derive(Diagnostic)]
396 #[diag(passes_no_link)]
404 #[derive(Diagnostic)]
405 #[diag(passes_export_name)]
406 pub struct ExportName {
413 #[derive(Diagnostic)]
414 #[diag(passes_rustc_layout_scalar_valid_range_not_struct)]
415 pub struct RustcLayoutScalarValidRangeNotStruct {
422 #[derive(Diagnostic)]
423 #[diag(passes_rustc_layout_scalar_valid_range_arg)]
424 pub struct RustcLayoutScalarValidRangeArg {
429 #[derive(Diagnostic)]
430 #[diag(passes_rustc_legacy_const_generics_only)]
431 pub struct RustcLegacyConstGenericsOnly {
435 pub param_span: Span,
438 #[derive(Diagnostic)]
439 #[diag(passes_rustc_legacy_const_generics_index)]
440 pub struct RustcLegacyConstGenericsIndex {
444 pub generics_span: Span,
447 #[derive(Diagnostic)]
448 #[diag(passes_rustc_legacy_const_generics_index_exceed)]
449 pub struct RustcLegacyConstGenericsIndexExceed {
453 pub arg_count: usize,
456 #[derive(Diagnostic)]
457 #[diag(passes_rustc_legacy_const_generics_index_negative)]
458 pub struct RustcLegacyConstGenericsIndexNegative {
460 pub invalid_args: Vec<Span>,
463 #[derive(Diagnostic)]
464 #[diag(passes_rustc_dirty_clean)]
465 pub struct RustcDirtyClean {
470 #[derive(LintDiagnostic)]
471 #[diag(passes_link_section)]
473 pub struct LinkSection {
478 #[derive(LintDiagnostic)]
479 #[diag(passes_no_mangle_foreign)]
482 pub struct NoMangleForeign {
485 #[suggestion(code = "", applicability = "machine-applicable")]
487 pub foreign_item_kind: &'static str,
490 #[derive(LintDiagnostic)]
491 #[diag(passes_no_mangle)]
493 pub struct NoMangle {
498 #[derive(Diagnostic)]
499 #[diag(passes_repr_ident, code = "E0565")]
500 pub struct ReprIdent {
505 #[derive(LintDiagnostic)]
506 #[diag(passes_repr_conflicting, code = "E0566")]
507 pub struct ReprConflicting;
509 #[derive(Diagnostic)]
510 #[diag(passes_used_static)]
511 pub struct UsedStatic {
516 #[derive(Diagnostic)]
517 #[diag(passes_used_compiler_linker)]
518 pub struct UsedCompilerLinker {
520 pub spans: Vec<Span>,
523 #[derive(Diagnostic)]
524 #[diag(passes_allow_internal_unstable)]
525 pub struct AllowInternalUnstable {
532 #[derive(Diagnostic)]
533 #[diag(passes_debug_visualizer_placement)]
534 pub struct DebugVisualizerPlacement {
539 #[derive(Diagnostic)]
540 #[diag(passes_debug_visualizer_invalid)]
544 pub struct DebugVisualizerInvalid {
549 #[derive(Diagnostic)]
550 #[diag(passes_debug_visualizer_unreadable)]
551 pub struct DebugVisualizerUnreadable<'a> {
558 #[derive(Diagnostic)]
559 #[diag(passes_rustc_allow_const_fn_unstable)]
560 pub struct RustcAllowConstFnUnstable {
567 #[derive(Diagnostic)]
568 #[diag(passes_rustc_std_internal_symbol)]
569 pub struct RustcStdInternalSymbol {
576 #[derive(Diagnostic)]
577 #[diag(passes_const_trait)]
578 pub struct ConstTrait {
583 #[derive(Diagnostic)]
584 #[diag(passes_link_ordinal)]
585 pub struct LinkOrdinal {
590 #[derive(Diagnostic)]
591 #[diag(passes_stability_promotable)]
592 pub struct StabilityPromotable {
597 #[derive(LintDiagnostic)]
598 #[diag(passes_deprecated)]
599 pub struct Deprecated;
601 #[derive(LintDiagnostic)]
602 #[diag(passes_macro_use)]
603 pub struct MacroUse {
607 #[derive(LintDiagnostic)]
608 #[diag(passes_macro_export)]
609 pub struct MacroExport;
611 #[derive(LintDiagnostic)]
612 #[diag(passes_plugin_registrar)]
613 pub struct PluginRegistrar;
615 #[derive(Subdiagnostic)]
616 pub enum UnusedNote {
617 #[note(passes_unused_empty_lints_note)]
618 EmptyList { name: Symbol },
619 #[note(passes_unused_no_lints_note)]
620 NoLints { name: Symbol },
621 #[note(passes_unused_default_method_body_const_note)]
622 DefaultMethodBodyConst,
625 #[derive(LintDiagnostic)]
626 #[diag(passes_unused)]
628 #[suggestion(code = "", applicability = "machine-applicable")]
631 pub note: UnusedNote,
634 #[derive(Diagnostic)]
635 #[diag(passes_non_exported_macro_invalid_attrs, code = "E0518")]
636 pub struct NonExportedMacroInvalidAttrs {
642 #[derive(LintDiagnostic)]
643 #[diag(passes_unused_duplicate)]
644 pub struct UnusedDuplicate {
645 #[suggestion(code = "", applicability = "machine-applicable")]
650 pub warning: Option<()>,
653 #[derive(Diagnostic)]
654 #[diag(passes_unused_multiple)]
655 pub struct UnusedMultiple {
657 #[suggestion(code = "", applicability = "machine-applicable")]
664 #[derive(Diagnostic)]
665 #[diag(passes_rustc_lint_opt_ty)]
666 pub struct RustcLintOptTy {
673 #[derive(Diagnostic)]
674 #[diag(passes_rustc_lint_opt_deny_field_access)]
675 pub struct RustcLintOptDenyFieldAccess {
682 #[derive(Diagnostic)]
683 #[diag(passes_collapse_debuginfo)]
684 pub struct CollapseDebuginfo {
691 #[derive(LintDiagnostic)]
692 #[diag(passes_deprecated_annotation_has_no_effect)]
693 pub struct DeprecatedAnnotationHasNoEffect {
694 #[suggestion(applicability = "machine-applicable", code = "")]
698 #[derive(Diagnostic)]
699 #[diag(passes_unknown_external_lang_item, code = "E0264")]
700 pub struct UnknownExternLangItem {
703 pub lang_item: Symbol,
706 #[derive(Diagnostic)]
707 #[diag(passes_missing_panic_handler)]
708 pub struct MissingPanicHandler;
710 #[derive(Diagnostic)]
711 #[diag(passes_missing_lang_item)]
714 pub struct MissingLangItem {
718 #[derive(Diagnostic)]
719 #[diag(passes_lang_item_on_incorrect_target, code = "E0718")]
720 pub struct LangItemOnIncorrectTarget {
725 pub expected_target: Target,
726 pub actual_target: Target,
729 #[derive(Diagnostic)]
730 #[diag(passes_unknown_lang_item, code = "E0522")]
731 pub struct UnknownLangItem {
738 pub struct InvalidAttrAtCrateLevel {
740 pub snippet: Option<String>,
744 impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel {
748 handler: &'_ rustc_errors::Handler,
749 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
750 let mut diag = handler.struct_err(rustc_errors::fluent::passes_invalid_attr_at_crate_level);
751 diag.set_span(self.span);
752 diag.set_arg("name", self.name);
753 // Only emit an error with a suggestion if we can create a string out
754 // of the attribute span
755 if let Some(src) = self.snippet {
756 let replacement = src.replace("#!", "#");
757 diag.span_suggestion_verbose(
759 rustc_errors::fluent::suggestion,
761 rustc_errors::Applicability::MachineApplicable,
768 #[derive(Diagnostic)]
769 #[diag(passes_duplicate_diagnostic_item)]
770 pub struct DuplicateDiagnosticItem {
776 #[derive(Diagnostic)]
777 #[diag(passes_duplicate_diagnostic_item_in_crate)]
778 pub struct DuplicateDiagnosticItemInCrate {
779 #[note(passes_diagnostic_item_first_defined)]
780 pub span: Option<Span>,
781 pub orig_crate_name: Symbol,
783 pub have_orig_crate_name: Option<()>,
784 pub crate_name: Symbol,
788 #[derive(Diagnostic)]
796 #[derive(Diagnostic)]
797 #[diag(passes_align)]
804 #[derive(Diagnostic)]
812 #[derive(Diagnostic)]
813 #[diag(passes_homogeneous_aggregate)]
814 pub struct HomogeneousAggregate {
817 pub homogeneous_aggregate: String,
820 #[derive(Diagnostic)]
821 #[diag(passes_layout_of)]
822 pub struct LayoutOf {
825 pub normalized_ty: String,
826 pub ty_layout: String,
829 #[derive(Diagnostic)]
830 #[diag(passes_unrecognized_field)]
831 pub struct UnrecognizedField {
837 #[derive(Diagnostic)]
838 #[diag(passes_feature_stable_twice, code = "E0711")]
839 pub struct FeatureStableTwice {
844 pub prev_since: Symbol,
847 #[derive(Diagnostic)]
848 #[diag(passes_feature_previously_declared, code = "E0711")]
849 pub struct FeaturePreviouslyDeclared<'a, 'b> {
853 pub declared: &'a str,
854 pub prev_declared: &'b str,
857 #[derive(Diagnostic)]
858 #[diag(passes_expr_not_allowed_in_context, code = "E0744")]
859 pub struct ExprNotAllowedInContext<'a> {
863 pub context: &'a str,
866 pub struct BreakNonLoop<'a> {
868 pub head: Option<Span>,
870 pub suggestion: String,
871 pub loop_label: Option<Label>,
872 pub break_label: Option<Label>,
873 pub break_expr_kind: &'a ExprKind<'a>,
874 pub break_expr_span: Span,
877 impl<'a> IntoDiagnostic<'_> for BreakNonLoop<'a> {
881 handler: &rustc_errors::Handler,
882 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
883 let mut diag = handler.struct_span_err_with_code(
885 rustc_errors::fluent::passes_break_non_loop,
888 diag.set_arg("kind", self.kind);
889 diag.span_label(self.span, rustc_errors::fluent::label);
890 if let Some(head) = self.head {
891 diag.span_label(head, rustc_errors::fluent::label2);
893 diag.span_suggestion(
895 rustc_errors::fluent::suggestion,
897 Applicability::MaybeIncorrect,
899 if let (Some(label), None) = (self.loop_label, self.break_label) {
900 match self.break_expr_kind {
901 ExprKind::Path(hir::QPath::Resolved(
903 hir::Path { segments: [segment], res: hir::def::Res::Err, .. },
904 )) if label.ident.to_string() == format!("'{}", segment.ident) => {
905 // This error is redundant, we will have already emitted a
906 // suggestion to use the label when `segment` wasn't found
907 // (hence the `Res::Err` check).
911 diag.span_suggestion(
912 self.break_expr_span,
913 rustc_errors::fluent::break_expr_suggestion,
915 Applicability::MaybeIncorrect,
924 #[derive(Diagnostic)]
925 #[diag(passes_continue_labeled_block, code = "E0696")]
926 pub struct ContinueLabeledBlock {
930 #[label(block_label)]
931 pub block_span: Span,
934 #[derive(Diagnostic)]
935 #[diag(passes_break_inside_closure, code = "E0267")]
936 pub struct BreakInsideClosure<'a> {
940 #[label(closure_label)]
941 pub closure_span: Span,
945 #[derive(Diagnostic)]
946 #[diag(passes_break_inside_async_block, code = "E0267")]
947 pub struct BreakInsideAsyncBlock<'a> {
951 #[label(async_block_label)]
952 pub closure_span: Span,
956 #[derive(Diagnostic)]
957 #[diag(passes_outside_loop, code = "E0268")]
958 pub struct OutsideLoop<'a> {
966 #[derive(Diagnostic)]
967 #[diag(passes_unlabeled_in_labeled_block, code = "E0695")]
968 pub struct UnlabeledInLabeledBlock<'a> {
972 pub cf_type: &'a str,
975 #[derive(Diagnostic)]
976 #[diag(passes_unlabeled_cf_in_while_condition, code = "E0590")]
977 pub struct UnlabeledCfInWhileCondition<'a> {
981 pub cf_type: &'a str,
984 #[derive(Diagnostic)]
985 #[diag(passes_cannot_inline_naked_function)]
986 pub struct CannotInlineNakedFunction {
991 #[derive(LintDiagnostic)]
992 #[diag(passes_undefined_naked_function_abi)]
993 pub struct UndefinedNakedFunctionAbi;
995 #[derive(Diagnostic)]
996 #[diag(passes_no_patterns)]
997 pub struct NoPatterns {
1002 #[derive(Diagnostic)]
1003 #[diag(passes_params_not_allowed)]
1005 pub struct ParamsNotAllowed {
1010 pub struct NakedFunctionsAsmBlock {
1012 pub multiple_asms: Vec<Span>,
1013 pub non_asms: Vec<Span>,
1016 impl IntoDiagnostic<'_> for NakedFunctionsAsmBlock {
1020 handler: &rustc_errors::Handler,
1021 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
1022 let mut diag = handler.struct_span_err_with_code(
1024 rustc_errors::fluent::passes_naked_functions_asm_block,
1027 for span in self.multiple_asms.iter() {
1028 diag.span_label(*span, rustc_errors::fluent::label_multiple_asm);
1030 for span in self.non_asms.iter() {
1031 diag.span_label(*span, rustc_errors::fluent::label_non_asm);
1037 #[derive(Diagnostic)]
1038 #[diag(passes_naked_functions_operands, code = "E0787")]
1039 pub struct NakedFunctionsOperands {
1041 pub unsupported_operands: Vec<Span>,
1044 #[derive(Diagnostic)]
1045 #[diag(passes_naked_functions_asm_options, code = "E0787")]
1046 pub struct NakedFunctionsAsmOptions {
1049 pub unsupported_options: String,
1052 #[derive(Diagnostic)]
1053 #[diag(passes_naked_functions_must_use_noreturn, code = "E0787")]
1054 pub struct NakedFunctionsMustUseNoreturn {
1057 #[suggestion(code = ", options(noreturn)", applicability = "machine-applicable")]
1058 pub last_span: Span,
1061 #[derive(Diagnostic)]
1062 #[diag(passes_attr_only_on_main)]
1063 pub struct AttrOnlyOnMain {
1069 #[derive(Diagnostic)]
1070 #[diag(passes_attr_only_on_root_main)]
1071 pub struct AttrOnlyOnRootMain {
1077 #[derive(Diagnostic)]
1078 #[diag(passes_attr_only_in_functions)]
1079 pub struct AttrOnlyInFunctions {
1085 #[derive(Diagnostic)]
1086 #[diag(passes_multiple_rustc_main, code = "E0137")]
1087 pub struct MultipleRustcMain {
1092 #[label(additional)]
1093 pub additional: Span,
1096 #[derive(Diagnostic)]
1097 #[diag(passes_multiple_start_functions, code = "E0138")]
1098 pub struct MultipleStartFunctions {
1107 #[derive(Diagnostic)]
1108 #[diag(passes_extern_main)]
1109 pub struct ExternMain {
1114 #[derive(Diagnostic)]
1115 #[diag(passes_unix_sigpipe_values)]
1116 pub struct UnixSigpipeValues {
1121 #[derive(Diagnostic)]
1122 #[diag(passes_no_main_function, code = "E0601")]
1123 pub struct NoMainFunction {
1126 pub crate_name: String,
1129 pub struct NoMainErr {
1131 pub crate_name: Symbol,
1132 pub has_filename: bool,
1133 pub filename: PathBuf,
1134 pub file_empty: bool,
1135 pub non_main_fns: Vec<Span>,
1136 pub main_def_opt: Option<MainDefinition>,
1137 pub add_teach_note: bool,
1140 impl<'a> IntoDiagnostic<'a> for NoMainErr {
1144 handler: &'a rustc_errors::Handler,
1145 ) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> {
1146 let mut diag = handler.struct_span_err_with_code(
1148 rustc_errors::fluent::passes_no_main_function,
1151 diag.set_arg("crate_name", self.crate_name);
1152 diag.set_arg("filename", self.filename);
1153 diag.set_arg("has_filename", self.has_filename);
1154 let note = if !self.non_main_fns.is_empty() {
1155 for &span in &self.non_main_fns {
1156 diag.span_note(span, rustc_errors::fluent::here_is_main);
1158 diag.note(rustc_errors::fluent::one_or_more_possible_main);
1159 diag.help(rustc_errors::fluent::consider_moving_main);
1160 // There were some functions named `main` though. Try to give the user a hint.
1161 rustc_errors::fluent::main_must_be_defined_at_crate
1162 } else if self.has_filename {
1163 rustc_errors::fluent::consider_adding_main_to_file
1165 rustc_errors::fluent::consider_adding_main_at_crate
1167 if self.file_empty {
1170 diag.set_span(self.sp.shrink_to_hi());
1171 diag.span_label(self.sp.shrink_to_hi(), note);
1174 if let Some(main_def) = self.main_def_opt && main_def.opt_fn_def_id().is_none(){
1175 // There is something at `crate::main`, but it is not a function definition.
1176 diag.span_label(main_def.span, rustc_errors::fluent::non_function_main);
1179 if self.add_teach_note {
1180 diag.note(rustc_errors::fluent::teach_note);
1186 pub struct DuplicateLangItem {
1187 pub local_span: Option<Span>,
1188 pub lang_item_name: Symbol,
1189 pub crate_name: Symbol,
1190 pub dependency_of: Symbol,
1193 pub first_defined_span: Option<Span>,
1194 pub orig_crate_name: Symbol,
1195 pub orig_dependency_of: Symbol,
1196 pub orig_is_local: bool,
1197 pub orig_path: String,
1198 pub(crate) duplicate: Duplicate,
1201 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 #[derive(Subdiagnostic)]
1506 #[multipart_suggestion(passes_change_fields_to_be_of_unit_type, applicability = "has-placeholders")]
1507 pub struct ChangeFieldsToBeOfUnitType {
1509 #[suggestion_part(code = "()")]
1510 pub spans: Vec<Span>,
1513 #[derive(Diagnostic)]
1514 #[diag(passes_proc_macro_typeerror)]
1516 pub(crate) struct ProcMacroTypeError<'tcx> {
1520 pub found: Ty<'tcx>,
1521 pub kind: ProcMacroKind,
1522 pub expected_signature: &'static str,
1525 #[derive(Diagnostic)]
1526 #[diag(passes_proc_macro_diff_arg_count)]
1527 pub(crate) struct ProcMacroDiffArguments {
1532 pub kind: ProcMacroKind,
1533 pub expected_signature: &'static str,
1536 #[derive(Diagnostic)]
1537 #[diag(passes_proc_macro_missing_args)]
1538 pub(crate) struct ProcMacroMissingArguments {
1542 pub expected_input_count: usize,
1543 pub kind: ProcMacroKind,
1544 pub expected_signature: &'static str,
1547 #[derive(Diagnostic)]
1548 #[diag(passes_proc_macro_invalid_abi)]
1549 pub(crate) struct ProcMacroInvalidAbi {
1552 pub abi: &'static str,
1555 #[derive(Diagnostic)]
1556 #[diag(passes_proc_macro_unsafe)]
1557 pub(crate) struct ProcMacroUnsafe {