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::lang_items::Duplicate;
17 #[derive(LintDiagnostic)]
18 #[diag(passes_outer_crate_level_attr)]
19 pub struct OuterCrateLevelAttr;
21 #[derive(LintDiagnostic)]
22 #[diag(passes_inner_crate_level_attr)]
23 pub struct InnerCrateLevelAttr;
25 #[derive(LintDiagnostic)]
26 #[diag(passes_ignored_attr_with_macro)]
27 pub struct IgnoredAttrWithMacro<'a> {
31 #[derive(LintDiagnostic)]
32 #[diag(passes_ignored_attr)]
33 pub struct IgnoredAttr<'a> {
37 #[derive(LintDiagnostic)]
38 #[diag(passes_inline_ignored_function_prototype)]
39 pub struct IgnoredInlineAttrFnProto;
41 #[derive(LintDiagnostic)]
42 #[diag(passes_inline_ignored_constants)]
45 pub struct IgnoredInlineAttrConstants;
48 #[diag(passes_inline_not_fn_or_closure, code = "E0518")]
49 pub struct InlineNotFnOrClosure {
56 #[derive(LintDiagnostic)]
57 #[diag(passes_no_coverage_ignored_function_prototype)]
58 pub struct IgnoredNoCoverageFnProto;
60 #[derive(LintDiagnostic)]
61 #[diag(passes_no_coverage_propagate)]
62 pub struct IgnoredNoCoveragePropagate;
64 #[derive(LintDiagnostic)]
65 #[diag(passes_no_coverage_fn_defn)]
66 pub struct IgnoredNoCoverageFnDefn;
69 #[diag(passes_no_coverage_not_coverable, code = "E0788")]
70 pub struct IgnoredNoCoverageNotCoverable {
78 #[diag(passes_should_be_applied_to_fn)]
79 pub struct AttrShouldBeAppliedToFn {
88 #[diag(passes_naked_tracked_caller, code = "E0736")]
89 pub struct NakedTrackedCaller {
95 #[diag(passes_should_be_applied_to_fn, code = "E0739")]
96 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(style = "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)]
375 #[derive(LintDiagnostic)]
380 pub span: Option<Span>,
383 #[derive(LintDiagnostic)]
384 #[diag(passes_link_name)]
386 pub struct LinkName<'a> {
388 pub attr_span: Option<Span>,
394 #[derive(Diagnostic)]
395 #[diag(passes_no_link)]
403 #[derive(Diagnostic)]
404 #[diag(passes_export_name)]
405 pub struct ExportName {
412 #[derive(Diagnostic)]
413 #[diag(passes_rustc_layout_scalar_valid_range_not_struct)]
414 pub struct RustcLayoutScalarValidRangeNotStruct {
421 #[derive(Diagnostic)]
422 #[diag(passes_rustc_layout_scalar_valid_range_arg)]
423 pub struct RustcLayoutScalarValidRangeArg {
428 #[derive(Diagnostic)]
429 #[diag(passes_rustc_legacy_const_generics_only)]
430 pub struct RustcLegacyConstGenericsOnly {
434 pub param_span: Span,
437 #[derive(Diagnostic)]
438 #[diag(passes_rustc_legacy_const_generics_index)]
439 pub struct RustcLegacyConstGenericsIndex {
443 pub generics_span: Span,
446 #[derive(Diagnostic)]
447 #[diag(passes_rustc_legacy_const_generics_index_exceed)]
448 pub struct RustcLegacyConstGenericsIndexExceed {
452 pub arg_count: usize,
455 #[derive(Diagnostic)]
456 #[diag(passes_rustc_legacy_const_generics_index_negative)]
457 pub struct RustcLegacyConstGenericsIndexNegative {
459 pub invalid_args: Vec<Span>,
462 #[derive(Diagnostic)]
463 #[diag(passes_rustc_dirty_clean)]
464 pub struct RustcDirtyClean {
469 #[derive(LintDiagnostic)]
470 #[diag(passes_link_section)]
472 pub struct LinkSection {
477 #[derive(LintDiagnostic)]
478 #[diag(passes_no_mangle_foreign)]
481 pub struct NoMangleForeign {
484 #[suggestion(code = "", applicability = "machine-applicable")]
486 pub foreign_item_kind: &'static str,
489 #[derive(LintDiagnostic)]
490 #[diag(passes_no_mangle)]
492 pub struct NoMangle {
497 #[derive(Diagnostic)]
498 #[diag(passes_repr_ident, code = "E0565")]
499 pub struct ReprIdent {
504 #[derive(LintDiagnostic)]
505 #[diag(passes_repr_conflicting, code = "E0566")]
506 pub struct ReprConflicting;
508 #[derive(Diagnostic)]
509 #[diag(passes_used_static)]
510 pub struct UsedStatic {
515 #[derive(Diagnostic)]
516 #[diag(passes_used_compiler_linker)]
517 pub struct UsedCompilerLinker {
519 pub spans: Vec<Span>,
522 #[derive(Diagnostic)]
523 #[diag(passes_allow_internal_unstable)]
524 pub struct AllowInternalUnstable {
531 #[derive(Diagnostic)]
532 #[diag(passes_debug_visualizer_placement)]
533 pub struct DebugVisualizerPlacement {
538 #[derive(Diagnostic)]
539 #[diag(passes_debug_visualizer_invalid)]
543 pub struct DebugVisualizerInvalid {
548 #[derive(Diagnostic)]
549 #[diag(passes_debug_visualizer_unreadable)]
550 pub struct DebugVisualizerUnreadable<'a> {
557 #[derive(Diagnostic)]
558 #[diag(passes_rustc_allow_const_fn_unstable)]
559 pub struct RustcAllowConstFnUnstable {
566 #[derive(Diagnostic)]
567 #[diag(passes_rustc_std_internal_symbol)]
568 pub struct RustcStdInternalSymbol {
575 #[derive(Diagnostic)]
576 #[diag(passes_const_trait)]
577 pub struct ConstTrait {
582 #[derive(Diagnostic)]
583 #[diag(passes_link_ordinal)]
584 pub struct LinkOrdinal {
589 #[derive(Diagnostic)]
590 #[diag(passes_stability_promotable)]
591 pub struct StabilityPromotable {
596 #[derive(LintDiagnostic)]
597 #[diag(passes_deprecated)]
598 pub struct Deprecated;
600 #[derive(LintDiagnostic)]
601 #[diag(passes_macro_use)]
602 pub struct MacroUse {
606 #[derive(LintDiagnostic)]
607 #[diag(passes_macro_export)]
608 pub struct MacroExport;
610 #[derive(LintDiagnostic)]
611 #[diag(passes_plugin_registrar)]
612 pub struct PluginRegistrar;
614 #[derive(Subdiagnostic)]
615 pub enum UnusedNote {
616 #[note(passes_unused_empty_lints_note)]
617 EmptyList { name: Symbol },
618 #[note(passes_unused_no_lints_note)]
619 NoLints { name: Symbol },
620 #[note(passes_unused_default_method_body_const_note)]
621 DefaultMethodBodyConst,
624 #[derive(LintDiagnostic)]
625 #[diag(passes_unused)]
627 #[suggestion(code = "", applicability = "machine-applicable")]
630 pub note: UnusedNote,
633 #[derive(Diagnostic)]
634 #[diag(passes_non_exported_macro_invalid_attrs, code = "E0518")]
635 pub struct NonExportedMacroInvalidAttrs {
641 #[derive(LintDiagnostic)]
642 #[diag(passes_unused_duplicate)]
643 pub struct UnusedDuplicate {
644 #[suggestion(code = "", applicability = "machine-applicable")]
649 pub warning: Option<()>,
652 #[derive(Diagnostic)]
653 #[diag(passes_unused_multiple)]
654 pub struct UnusedMultiple {
656 #[suggestion(code = "", applicability = "machine-applicable")]
663 #[derive(Diagnostic)]
664 #[diag(passes_rustc_lint_opt_ty)]
665 pub struct RustcLintOptTy {
672 #[derive(Diagnostic)]
673 #[diag(passes_rustc_lint_opt_deny_field_access)]
674 pub struct RustcLintOptDenyFieldAccess {
681 #[derive(Diagnostic)]
682 #[diag(passes_collapse_debuginfo)]
683 pub struct CollapseDebuginfo {
690 #[derive(LintDiagnostic)]
691 #[diag(passes_deprecated_annotation_has_no_effect)]
692 pub struct DeprecatedAnnotationHasNoEffect {
693 #[suggestion(applicability = "machine-applicable", code = "")]
697 #[derive(Diagnostic)]
698 #[diag(passes_unknown_external_lang_item, code = "E0264")]
699 pub struct UnknownExternLangItem {
702 pub lang_item: Symbol,
705 #[derive(Diagnostic)]
706 #[diag(passes_missing_panic_handler)]
707 pub struct MissingPanicHandler;
709 #[derive(Diagnostic)]
710 #[diag(passes_missing_lang_item)]
713 pub struct MissingLangItem {
717 #[derive(Diagnostic)]
718 #[diag(passes_lang_item_on_incorrect_target, code = "E0718")]
719 pub struct LangItemOnIncorrectTarget {
724 pub expected_target: Target,
725 pub actual_target: Target,
728 #[derive(Diagnostic)]
729 #[diag(passes_unknown_lang_item, code = "E0522")]
730 pub struct UnknownLangItem {
737 pub struct InvalidAttrAtCrateLevel {
739 pub snippet: Option<String>,
743 impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel {
747 handler: &'_ rustc_errors::Handler,
748 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
749 let mut diag = handler.struct_err(rustc_errors::fluent::passes_invalid_attr_at_crate_level);
750 diag.set_span(self.span);
751 diag.set_arg("name", self.name);
752 // Only emit an error with a suggestion if we can create a string out
753 // of the attribute span
754 if let Some(src) = self.snippet {
755 let replacement = src.replace("#!", "#");
756 diag.span_suggestion_verbose(
758 rustc_errors::fluent::suggestion,
760 rustc_errors::Applicability::MachineApplicable,
767 #[derive(Diagnostic)]
768 #[diag(passes_duplicate_diagnostic_item)]
769 pub struct DuplicateDiagnosticItem {
775 #[derive(Diagnostic)]
776 #[diag(passes_duplicate_diagnostic_item_in_crate)]
777 pub struct DuplicateDiagnosticItemInCrate {
778 #[note(passes_diagnostic_item_first_defined)]
779 pub span: Option<Span>,
780 pub orig_crate_name: Symbol,
782 pub have_orig_crate_name: Option<()>,
783 pub crate_name: Symbol,
787 #[derive(Diagnostic)]
795 #[derive(Diagnostic)]
796 #[diag(passes_align)]
803 #[derive(Diagnostic)]
811 #[derive(Diagnostic)]
812 #[diag(passes_homogeneous_aggregate)]
813 pub struct HomogeneousAggregate {
816 pub homogeneous_aggregate: String,
819 #[derive(Diagnostic)]
820 #[diag(passes_layout_of)]
821 pub struct LayoutOf {
824 pub normalized_ty: String,
825 pub ty_layout: String,
828 #[derive(Diagnostic)]
829 #[diag(passes_unrecognized_field)]
830 pub struct UnrecognizedField {
836 #[derive(Diagnostic)]
837 #[diag(passes_feature_stable_twice, code = "E0711")]
838 pub struct FeatureStableTwice {
843 pub prev_since: Symbol,
846 #[derive(Diagnostic)]
847 #[diag(passes_feature_previously_declared, code = "E0711")]
848 pub struct FeaturePreviouslyDeclared<'a, 'b> {
852 pub declared: &'a str,
853 pub prev_declared: &'b str,
856 #[derive(Diagnostic)]
857 #[diag(passes_expr_not_allowed_in_context, code = "E0744")]
858 pub struct ExprNotAllowedInContext<'a> {
862 pub context: &'a str,
865 pub struct BreakNonLoop<'a> {
867 pub head: Option<Span>,
869 pub suggestion: String,
870 pub loop_label: Option<Label>,
871 pub break_label: Option<Label>,
872 pub break_expr_kind: &'a ExprKind<'a>,
873 pub break_expr_span: Span,
876 impl<'a> IntoDiagnostic<'_> for BreakNonLoop<'a> {
880 handler: &rustc_errors::Handler,
881 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
882 let mut diag = handler.struct_span_err_with_code(
884 rustc_errors::fluent::passes_break_non_loop,
887 diag.set_arg("kind", self.kind);
888 diag.span_label(self.span, rustc_errors::fluent::label);
889 if let Some(head) = self.head {
890 diag.span_label(head, rustc_errors::fluent::label2);
892 diag.span_suggestion(
894 rustc_errors::fluent::suggestion,
896 Applicability::MaybeIncorrect,
898 if let (Some(label), None) = (self.loop_label, self.break_label) {
899 match self.break_expr_kind {
900 ExprKind::Path(hir::QPath::Resolved(
902 hir::Path { segments: [segment], res: hir::def::Res::Err, .. },
903 )) if label.ident.to_string() == format!("'{}", segment.ident) => {
904 // This error is redundant, we will have already emitted a
905 // suggestion to use the label when `segment` wasn't found
906 // (hence the `Res::Err` check).
910 diag.span_suggestion(
911 self.break_expr_span,
912 rustc_errors::fluent::break_expr_suggestion,
914 Applicability::MaybeIncorrect,
923 #[derive(Diagnostic)]
924 #[diag(passes_continue_labeled_block, code = "E0696")]
925 pub struct ContinueLabeledBlock {
929 #[label(block_label)]
930 pub block_span: Span,
933 #[derive(Diagnostic)]
934 #[diag(passes_break_inside_closure, code = "E0267")]
935 pub struct BreakInsideClosure<'a> {
939 #[label(closure_label)]
940 pub closure_span: Span,
944 #[derive(Diagnostic)]
945 #[diag(passes_break_inside_async_block, code = "E0267")]
946 pub struct BreakInsideAsyncBlock<'a> {
950 #[label(async_block_label)]
951 pub closure_span: Span,
955 #[derive(Diagnostic)]
956 #[diag(passes_outside_loop, code = "E0268")]
957 pub struct OutsideLoop<'a> {
965 #[derive(Diagnostic)]
966 #[diag(passes_unlabeled_in_labeled_block, code = "E0695")]
967 pub struct UnlabeledInLabeledBlock<'a> {
971 pub cf_type: &'a str,
974 #[derive(Diagnostic)]
975 #[diag(passes_unlabeled_cf_in_while_condition, code = "E0590")]
976 pub struct UnlabeledCfInWhileCondition<'a> {
980 pub cf_type: &'a str,
983 #[derive(Diagnostic)]
984 #[diag(passes_cannot_inline_naked_function)]
985 pub struct CannotInlineNakedFunction {
990 #[derive(LintDiagnostic)]
991 #[diag(passes_undefined_naked_function_abi)]
992 pub struct UndefinedNakedFunctionAbi;
994 #[derive(Diagnostic)]
995 #[diag(passes_no_patterns)]
996 pub struct NoPatterns {
1001 #[derive(Diagnostic)]
1002 #[diag(passes_params_not_allowed)]
1004 pub struct ParamsNotAllowed {
1009 pub struct NakedFunctionsAsmBlock {
1011 pub multiple_asms: Vec<Span>,
1012 pub non_asms: Vec<Span>,
1015 impl IntoDiagnostic<'_> for NakedFunctionsAsmBlock {
1019 handler: &rustc_errors::Handler,
1020 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
1021 let mut diag = handler.struct_span_err_with_code(
1023 rustc_errors::fluent::passes_naked_functions_asm_block,
1026 for span in self.multiple_asms.iter() {
1027 diag.span_label(*span, rustc_errors::fluent::label_multiple_asm);
1029 for span in self.non_asms.iter() {
1030 diag.span_label(*span, rustc_errors::fluent::label_non_asm);
1036 #[derive(Diagnostic)]
1037 #[diag(passes_naked_functions_operands, code = "E0787")]
1038 pub struct NakedFunctionsOperands {
1040 pub unsupported_operands: Vec<Span>,
1043 #[derive(Diagnostic)]
1044 #[diag(passes_naked_functions_asm_options, code = "E0787")]
1045 pub struct NakedFunctionsAsmOptions {
1048 pub unsupported_options: String,
1051 #[derive(Diagnostic)]
1052 #[diag(passes_naked_functions_must_use_noreturn, code = "E0787")]
1053 pub struct NakedFunctionsMustUseNoreturn {
1056 #[suggestion(code = ", options(noreturn)", applicability = "machine-applicable")]
1057 pub last_span: Span,
1060 #[derive(Diagnostic)]
1061 #[diag(passes_attr_only_on_main)]
1062 pub struct AttrOnlyOnMain {
1068 #[derive(Diagnostic)]
1069 #[diag(passes_attr_only_on_root_main)]
1070 pub struct AttrOnlyOnRootMain {
1076 #[derive(Diagnostic)]
1077 #[diag(passes_attr_only_in_functions)]
1078 pub struct AttrOnlyInFunctions {
1084 #[derive(Diagnostic)]
1085 #[diag(passes_multiple_rustc_main, code = "E0137")]
1086 pub struct MultipleRustcMain {
1091 #[label(additional)]
1092 pub additional: Span,
1095 #[derive(Diagnostic)]
1096 #[diag(passes_multiple_start_functions, code = "E0138")]
1097 pub struct MultipleStartFunctions {
1106 #[derive(Diagnostic)]
1107 #[diag(passes_extern_main)]
1108 pub struct ExternMain {
1113 #[derive(Diagnostic)]
1114 #[diag(passes_unix_sigpipe_values)]
1115 pub struct UnixSigpipeValues {
1120 #[derive(Diagnostic)]
1121 #[diag(passes_no_main_function, code = "E0601")]
1122 pub struct NoMainFunction {
1125 pub crate_name: String,
1128 pub struct NoMainErr {
1130 pub crate_name: Symbol,
1131 pub has_filename: bool,
1132 pub filename: PathBuf,
1133 pub file_empty: bool,
1134 pub non_main_fns: Vec<Span>,
1135 pub main_def_opt: Option<MainDefinition>,
1136 pub add_teach_note: bool,
1139 impl<'a> IntoDiagnostic<'a> for NoMainErr {
1143 handler: &'a rustc_errors::Handler,
1144 ) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> {
1145 let mut diag = handler.struct_span_err_with_code(
1147 rustc_errors::fluent::passes_no_main_function,
1150 diag.set_arg("crate_name", self.crate_name);
1151 diag.set_arg("filename", self.filename);
1152 diag.set_arg("has_filename", self.has_filename);
1153 let note = if !self.non_main_fns.is_empty() {
1154 for &span in &self.non_main_fns {
1155 diag.span_note(span, rustc_errors::fluent::here_is_main);
1157 diag.note(rustc_errors::fluent::one_or_more_possible_main);
1158 diag.help(rustc_errors::fluent::consider_moving_main);
1159 // There were some functions named `main` though. Try to give the user a hint.
1160 rustc_errors::fluent::main_must_be_defined_at_crate
1161 } else if self.has_filename {
1162 rustc_errors::fluent::consider_adding_main_to_file
1164 rustc_errors::fluent::consider_adding_main_at_crate
1166 if self.file_empty {
1169 diag.set_span(self.sp.shrink_to_hi());
1170 diag.span_label(self.sp.shrink_to_hi(), note);
1173 if let Some(main_def) = self.main_def_opt && main_def.opt_fn_def_id().is_none(){
1174 // There is something at `crate::main`, but it is not a function definition.
1175 diag.span_label(main_def.span, rustc_errors::fluent::non_function_main);
1178 if self.add_teach_note {
1179 diag.note(rustc_errors::fluent::teach_note);
1185 pub struct DuplicateLangItem {
1186 pub local_span: Option<Span>,
1187 pub lang_item_name: Symbol,
1188 pub crate_name: Symbol,
1189 pub dependency_of: Symbol,
1192 pub first_defined_span: Option<Span>,
1193 pub orig_crate_name: Symbol,
1194 pub orig_dependency_of: Symbol,
1195 pub orig_is_local: bool,
1196 pub orig_path: String,
1197 pub(crate) duplicate: Duplicate,
1200 impl IntoDiagnostic<'_> for DuplicateLangItem {
1204 handler: &rustc_errors::Handler,
1205 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
1206 let mut diag = handler.struct_err_with_code(
1207 match self.duplicate {
1208 Duplicate::Plain => rustc_errors::fluent::passes_duplicate_lang_item,
1210 Duplicate::Crate => rustc_errors::fluent::passes_duplicate_lang_item_crate,
1211 Duplicate::CrateDepends => {
1212 rustc_errors::fluent::passes_duplicate_lang_item_crate_depends
1217 diag.set_arg("lang_item_name", self.lang_item_name);
1218 diag.set_arg("crate_name", self.crate_name);
1219 diag.set_arg("dependency_of", self.dependency_of);
1220 diag.set_arg("path", self.path);
1221 diag.set_arg("orig_crate_name", self.orig_crate_name);
1222 diag.set_arg("orig_dependency_of", self.orig_dependency_of);
1223 diag.set_arg("orig_path", self.orig_path);
1224 if let Some(span) = self.local_span {
1225 diag.set_span(span);
1227 if let Some(span) = self.first_defined_span {
1228 diag.span_note(span, rustc_errors::fluent::first_defined_span);
1230 if self.orig_dependency_of.is_empty() {
1231 diag.note(rustc_errors::fluent::first_defined_crate);
1233 diag.note(rustc_errors::fluent::first_defined_crate_depends);
1236 if self.orig_is_local {
1237 diag.note(rustc_errors::fluent::first_definition_local);
1239 diag.note(rustc_errors::fluent::first_definition_path);
1243 diag.note(rustc_errors::fluent::second_definition_local);
1245 diag.note(rustc_errors::fluent::second_definition_path);
1252 #[derive(Diagnostic)]
1253 #[diag(passes_incorrect_target, code = "E0718")]
1254 pub struct IncorrectTarget<'a> {
1258 pub generics_span: Span,
1259 pub name: &'a str, // cannot be symbol because it renders e.g. `r#fn` instead of `fn`
1260 pub kind: &'static str,
1262 pub actual_num: usize,
1266 #[derive(LintDiagnostic)]
1267 #[diag(passes_useless_assignment)]
1268 pub struct UselessAssignment<'a> {
1269 pub is_field_assign: bool,
1273 #[derive(LintDiagnostic)]
1274 #[diag(passes_only_has_effect_on)]
1275 pub struct OnlyHasEffectOn {
1276 pub attr_name: Symbol,
1277 pub target_name: String,
1280 #[derive(Diagnostic)]
1281 #[diag(passes_object_lifetime_err)]
1282 pub struct ObjectLifetimeErr {
1288 #[derive(Diagnostic)]
1289 #[diag(passes_unrecognized_repr_hint, code = "E0552")]
1291 pub struct UnrecognizedReprHint {
1296 #[derive(Diagnostic)]
1297 pub enum AttrApplication {
1298 #[diag(passes_attr_application_enum, code = "E0517")]
1305 #[diag(passes_attr_application_struct, code = "E0517")]
1312 #[diag(passes_attr_application_struct_union, code = "E0517")]
1319 #[diag(passes_attr_application_struct_enum_union, code = "E0517")]
1326 #[diag(passes_attr_application_struct_enum_function_union, code = "E0517")]
1327 StructEnumFunctionUnion {
1335 #[derive(Diagnostic)]
1336 #[diag(passes_transparent_incompatible, code = "E0692")]
1337 pub struct TransparentIncompatible {
1339 pub hint_spans: Vec<Span>,
1343 #[derive(Diagnostic)]
1344 #[diag(passes_deprecated_attribute, code = "E0549")]
1345 pub struct DeprecatedAttribute {
1350 #[derive(Diagnostic)]
1351 #[diag(passes_useless_stability)]
1352 pub struct UselessStability {
1360 #[derive(Diagnostic)]
1361 #[diag(passes_invalid_stability)]
1362 pub struct InvalidStability {
1370 #[derive(Diagnostic)]
1371 #[diag(passes_cannot_stabilize_deprecated)]
1372 pub struct CannotStabilizeDeprecated {
1380 #[derive(Diagnostic)]
1381 #[diag(passes_invalid_deprecation_version)]
1382 pub struct InvalidDeprecationVersion {
1390 #[derive(Diagnostic)]
1391 #[diag(passes_missing_stability_attr)]
1392 pub struct MissingStabilityAttr<'a> {
1398 #[derive(Diagnostic)]
1399 #[diag(passes_missing_const_stab_attr)]
1400 pub struct MissingConstStabAttr<'a> {
1406 #[derive(Diagnostic)]
1407 #[diag(passes_trait_impl_const_stable)]
1409 pub struct TraitImplConstStable {
1414 #[derive(Diagnostic)]
1415 #[diag(passes_feature_only_on_nightly, code = "E0554")]
1416 pub struct FeatureOnlyOnNightly {
1419 pub release_channel: &'static str,
1422 #[derive(Diagnostic)]
1423 #[diag(passes_unknown_feature, code = "E0635")]
1424 pub struct UnknownFeature {
1427 pub feature: Symbol,
1430 #[derive(Diagnostic)]
1431 #[diag(passes_implied_feature_not_exist)]
1432 pub struct ImpliedFeatureNotExist {
1435 pub feature: Symbol,
1436 pub implied_by: Symbol,
1439 #[derive(Diagnostic)]
1440 #[diag(passes_duplicate_feature_err, code = "E0636")]
1441 pub struct DuplicateFeatureErr {
1444 pub feature: Symbol,
1446 #[derive(Diagnostic)]
1447 #[diag(passes_missing_const_err)]
1448 pub struct MissingConstErr {
1451 pub fn_sig_span: Span,
1453 pub const_span: Span,
1456 #[derive(LintDiagnostic)]
1457 pub enum MultipleDeadCodes<'tcx> {
1458 #[diag(passes_dead_codes)]
1463 participle: &'tcx str,
1464 name_list: DiagnosticSymbolList,
1466 parent_info: Option<ParentInfo<'tcx>>,
1468 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1470 #[diag(passes_dead_codes)]
1471 UnusedTupleStructFields {
1475 participle: &'tcx str,
1476 name_list: DiagnosticSymbolList,
1478 change_fields_suggestion: ChangeFieldsToBeOfUnitType,
1480 parent_info: Option<ParentInfo<'tcx>>,
1482 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1486 #[derive(Subdiagnostic)]
1487 #[label(passes_parent_info)]
1488 pub struct ParentInfo<'tcx> {
1490 pub descr: &'tcx str,
1491 pub parent_descr: &'tcx str,
1496 #[derive(Subdiagnostic)]
1497 #[note(passes_ignored_derived_impls)]
1498 pub struct IgnoredDerivedImpls {
1500 pub trait_list: DiagnosticSymbolList,
1501 pub trait_list_len: usize,
1504 #[derive(Subdiagnostic)]
1505 #[multipart_suggestion(passes_change_fields_to_be_of_unit_type, applicability = "has-placeholders")]
1506 pub struct ChangeFieldsToBeOfUnitType {
1508 #[suggestion_part(code = "()")]
1509 pub spans: Vec<Span>,