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 {
87 #[diag(passes_naked_tracked_caller, code = "E0736")]
88 pub struct NakedTrackedCaller {
94 #[diag(passes_should_be_applied_to_fn, code = "E0739")]
95 pub struct TrackedCallerWrongLocation {
102 #[derive(Diagnostic)]
103 #[diag(passes_should_be_applied_to_struct_enum, code = "E0701")]
104 pub struct NonExhaustiveWrongLocation {
111 #[derive(Diagnostic)]
112 #[diag(passes_should_be_applied_to_trait)]
113 pub struct AttrShouldBeAppliedToTrait {
120 #[derive(LintDiagnostic)]
121 #[diag(passes_target_feature_on_statement)]
122 pub struct TargetFeatureOnStatement;
124 #[derive(Diagnostic)]
125 #[diag(passes_should_be_applied_to_static)]
126 pub struct AttrShouldBeAppliedToStatic {
133 #[derive(Diagnostic)]
134 #[diag(passes_doc_expect_str)]
135 pub struct DocExpectStr<'a> {
138 pub attr_name: &'a str,
141 #[derive(Diagnostic)]
142 #[diag(passes_doc_alias_empty)]
143 pub struct DocAliasEmpty<'a> {
146 pub attr_str: &'a str,
149 #[derive(Diagnostic)]
150 #[diag(passes_doc_alias_bad_char)]
151 pub struct DocAliasBadChar<'a> {
154 pub attr_str: &'a str,
158 #[derive(Diagnostic)]
159 #[diag(passes_doc_alias_start_end)]
160 pub struct DocAliasStartEnd<'a> {
163 pub attr_str: &'a str,
166 #[derive(Diagnostic)]
167 #[diag(passes_doc_alias_bad_location)]
168 pub struct DocAliasBadLocation<'a> {
171 pub attr_str: &'a str,
172 pub location: &'a str,
175 #[derive(Diagnostic)]
176 #[diag(passes_doc_alias_not_an_alias)]
177 pub struct DocAliasNotAnAlias<'a> {
180 pub attr_str: &'a str,
183 #[derive(LintDiagnostic)]
184 #[diag(passes_doc_alias_duplicated)]
185 pub struct DocAliasDuplicated {
187 pub first_defn: Span,
190 #[derive(Diagnostic)]
191 #[diag(passes_doc_alias_not_string_literal)]
192 pub struct DocAliasNotStringLiteral {
197 #[derive(Diagnostic)]
198 #[diag(passes_doc_alias_malformed)]
199 pub struct DocAliasMalformed {
204 #[derive(Diagnostic)]
205 #[diag(passes_doc_keyword_empty_mod)]
206 pub struct DocKeywordEmptyMod {
211 #[derive(Diagnostic)]
212 #[diag(passes_doc_keyword_not_mod)]
213 pub struct DocKeywordNotMod {
218 #[derive(Diagnostic)]
219 #[diag(passes_doc_keyword_invalid_ident)]
220 pub struct DocKeywordInvalidIdent {
223 pub doc_keyword: Symbol,
226 #[derive(Diagnostic)]
227 #[diag(passes_doc_fake_variadic_not_valid)]
228 pub struct DocFakeVariadicNotValid {
233 #[derive(Diagnostic)]
234 #[diag(passes_doc_keyword_only_impl)]
235 pub struct DocKeywordOnlyImpl {
240 #[derive(Diagnostic)]
241 #[diag(passes_doc_inline_conflict)]
243 pub struct DocKeywordConflict {
245 pub spans: MultiSpan,
248 #[derive(LintDiagnostic)]
249 #[diag(passes_doc_inline_only_use)]
251 pub struct DocInlineOnlyUse {
254 #[label(not_a_use_item_label)]
255 pub item_span: Option<Span>,
258 #[derive(Diagnostic)]
259 #[diag(passes_doc_attr_not_crate_level)]
260 pub struct DocAttrNotCrateLevel<'a> {
263 pub attr_name: &'a str,
266 #[derive(LintDiagnostic)]
267 #[diag(passes_doc_test_unknown)]
268 pub struct DocTestUnknown {
272 #[derive(LintDiagnostic)]
273 #[diag(passes_doc_test_takes_list)]
274 pub struct DocTestTakesList;
276 #[derive(LintDiagnostic)]
277 #[diag(passes_doc_cfg_hide_takes_list)]
278 pub struct DocCfgHideTakesList;
280 #[derive(LintDiagnostic)]
281 #[diag(passes_doc_primitive)]
282 pub struct DocPrimitive;
284 #[derive(LintDiagnostic)]
285 #[diag(passes_doc_test_unknown_any)]
286 pub struct DocTestUnknownAny {
290 #[derive(LintDiagnostic)]
291 #[diag(passes_doc_test_unknown_spotlight)]
294 pub struct DocTestUnknownSpotlight {
296 #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")]
300 #[derive(LintDiagnostic)]
301 #[diag(passes_doc_test_unknown_include)]
302 pub struct DocTestUnknownInclude {
305 pub inner: &'static str,
306 #[suggestion(code = "#{inner}[doc = include_str!(\"{value}\")]")]
307 pub sugg: (Span, Applicability),
310 #[derive(LintDiagnostic)]
311 #[diag(passes_doc_invalid)]
312 pub struct DocInvalid;
314 #[derive(Diagnostic)]
315 #[diag(passes_pass_by_value)]
316 pub struct PassByValue {
323 #[derive(Diagnostic)]
324 #[diag(passes_allow_incoherent_impl)]
325 pub struct AllowIncoherentImpl {
332 #[derive(Diagnostic)]
333 #[diag(passes_has_incoherent_inherent_impl)]
334 pub struct HasIncoherentInherentImpl {
341 #[derive(LintDiagnostic)]
342 #[diag(passes_must_use_async)]
343 pub struct MustUseAsync {
348 #[derive(LintDiagnostic)]
349 #[diag(passes_must_use_no_effect)]
350 pub struct MustUseNoEffect {
351 pub article: &'static str,
352 pub target: rustc_hir::Target,
355 #[derive(Diagnostic)]
356 #[diag(passes_must_not_suspend)]
357 pub struct MustNotSuspend {
364 #[derive(LintDiagnostic)]
372 #[derive(LintDiagnostic)]
377 pub span: Option<Span>,
380 #[derive(LintDiagnostic)]
381 #[diag(passes_link_name)]
383 pub struct LinkName<'a> {
385 pub attr_span: Option<Span>,
391 #[derive(Diagnostic)]
392 #[diag(passes_no_link)]
400 #[derive(Diagnostic)]
401 #[diag(passes_export_name)]
402 pub struct ExportName {
409 #[derive(Diagnostic)]
410 #[diag(passes_rustc_layout_scalar_valid_range_not_struct)]
411 pub struct RustcLayoutScalarValidRangeNotStruct {
418 #[derive(Diagnostic)]
419 #[diag(passes_rustc_layout_scalar_valid_range_arg)]
420 pub struct RustcLayoutScalarValidRangeArg {
425 #[derive(Diagnostic)]
426 #[diag(passes_rustc_legacy_const_generics_only)]
427 pub struct RustcLegacyConstGenericsOnly {
431 pub param_span: Span,
434 #[derive(Diagnostic)]
435 #[diag(passes_rustc_legacy_const_generics_index)]
436 pub struct RustcLegacyConstGenericsIndex {
440 pub generics_span: Span,
443 #[derive(Diagnostic)]
444 #[diag(passes_rustc_legacy_const_generics_index_exceed)]
445 pub struct RustcLegacyConstGenericsIndexExceed {
449 pub arg_count: usize,
452 #[derive(Diagnostic)]
453 #[diag(passes_rustc_legacy_const_generics_index_negative)]
454 pub struct RustcLegacyConstGenericsIndexNegative {
456 pub invalid_args: Vec<Span>,
459 #[derive(Diagnostic)]
460 #[diag(passes_rustc_dirty_clean)]
461 pub struct RustcDirtyClean {
466 #[derive(LintDiagnostic)]
467 #[diag(passes_link_section)]
469 pub struct LinkSection {
474 #[derive(LintDiagnostic)]
475 #[diag(passes_no_mangle_foreign)]
478 pub struct NoMangleForeign {
481 #[suggestion(code = "", applicability = "machine-applicable")]
483 pub foreign_item_kind: &'static str,
486 #[derive(LintDiagnostic)]
487 #[diag(passes_no_mangle)]
489 pub struct NoMangle {
494 #[derive(Diagnostic)]
495 #[diag(passes_repr_ident, code = "E0565")]
496 pub struct ReprIdent {
501 #[derive(LintDiagnostic)]
502 #[diag(passes_repr_conflicting, code = "E0566")]
503 pub struct ReprConflicting;
505 #[derive(Diagnostic)]
506 #[diag(passes_used_static)]
507 pub struct UsedStatic {
512 #[derive(Diagnostic)]
513 #[diag(passes_used_compiler_linker)]
514 pub struct UsedCompilerLinker {
516 pub spans: Vec<Span>,
519 #[derive(Diagnostic)]
520 #[diag(passes_allow_internal_unstable)]
521 pub struct AllowInternalUnstable {
528 #[derive(Diagnostic)]
529 #[diag(passes_debug_visualizer_placement)]
530 pub struct DebugVisualizerPlacement {
535 #[derive(Diagnostic)]
536 #[diag(passes_debug_visualizer_invalid)]
540 pub struct DebugVisualizerInvalid {
545 #[derive(Diagnostic)]
546 #[diag(passes_debug_visualizer_unreadable)]
547 pub struct DebugVisualizerUnreadable<'a> {
554 #[derive(Diagnostic)]
555 #[diag(passes_rustc_allow_const_fn_unstable)]
556 pub struct RustcAllowConstFnUnstable {
563 #[derive(Diagnostic)]
564 #[diag(passes_rustc_std_internal_symbol)]
565 pub struct RustcStdInternalSymbol {
572 #[derive(Diagnostic)]
573 #[diag(passes_const_trait)]
574 pub struct ConstTrait {
579 #[derive(Diagnostic)]
580 #[diag(passes_link_ordinal)]
581 pub struct LinkOrdinal {
586 #[derive(Diagnostic)]
587 #[diag(passes_stability_promotable)]
588 pub struct StabilityPromotable {
593 #[derive(LintDiagnostic)]
594 #[diag(passes_deprecated)]
595 pub struct Deprecated;
597 #[derive(LintDiagnostic)]
598 #[diag(passes_macro_use)]
599 pub struct MacroUse {
603 #[derive(LintDiagnostic)]
604 #[diag(passes_macro_export)]
605 pub struct MacroExport;
607 #[derive(LintDiagnostic)]
608 #[diag(passes_plugin_registrar)]
609 pub struct PluginRegistrar;
611 #[derive(Subdiagnostic)]
612 pub enum UnusedNote {
613 #[note(passes_unused_empty_lints_note)]
614 EmptyList { name: Symbol },
615 #[note(passes_unused_no_lints_note)]
616 NoLints { name: Symbol },
617 #[note(passes_unused_default_method_body_const_note)]
618 DefaultMethodBodyConst,
621 #[derive(LintDiagnostic)]
622 #[diag(passes_unused)]
624 #[suggestion(code = "", applicability = "machine-applicable")]
627 pub note: UnusedNote,
630 #[derive(Diagnostic)]
631 #[diag(passes_non_exported_macro_invalid_attrs, code = "E0518")]
632 pub struct NonExportedMacroInvalidAttrs {
638 #[derive(LintDiagnostic)]
639 #[diag(passes_unused_duplicate)]
640 pub struct UnusedDuplicate {
641 #[suggestion(code = "", applicability = "machine-applicable")]
646 pub warning: Option<()>,
649 #[derive(Diagnostic)]
650 #[diag(passes_unused_multiple)]
651 pub struct UnusedMultiple {
653 #[suggestion(code = "", applicability = "machine-applicable")]
660 #[derive(Diagnostic)]
661 #[diag(passes_rustc_lint_opt_ty)]
662 pub struct RustcLintOptTy {
669 #[derive(Diagnostic)]
670 #[diag(passes_rustc_lint_opt_deny_field_access)]
671 pub struct RustcLintOptDenyFieldAccess {
678 #[derive(Diagnostic)]
679 #[diag(passes_collapse_debuginfo)]
680 pub struct CollapseDebuginfo {
687 #[derive(LintDiagnostic)]
688 #[diag(passes_deprecated_annotation_has_no_effect)]
689 pub struct DeprecatedAnnotationHasNoEffect {
690 #[suggestion(applicability = "machine-applicable", code = "")]
694 #[derive(Diagnostic)]
695 #[diag(passes_unknown_external_lang_item, code = "E0264")]
696 pub struct UnknownExternLangItem {
699 pub lang_item: Symbol,
702 #[derive(Diagnostic)]
703 #[diag(passes_missing_panic_handler)]
704 pub struct MissingPanicHandler;
706 #[derive(Diagnostic)]
707 #[diag(passes_missing_lang_item)]
710 pub struct MissingLangItem {
714 #[derive(Diagnostic)]
715 #[diag(passes_lang_item_on_incorrect_target, code = "E0718")]
716 pub struct LangItemOnIncorrectTarget {
721 pub expected_target: Target,
722 pub actual_target: Target,
725 #[derive(Diagnostic)]
726 #[diag(passes_unknown_lang_item, code = "E0522")]
727 pub struct UnknownLangItem {
734 pub struct InvalidAttrAtCrateLevel {
736 pub snippet: Option<String>,
740 impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel {
744 handler: &'_ rustc_errors::Handler,
745 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
746 let mut diag = handler.struct_err(rustc_errors::fluent::passes_invalid_attr_at_crate_level);
747 diag.set_span(self.span);
748 diag.set_arg("name", self.name);
749 // Only emit an error with a suggestion if we can create a string out
750 // of the attribute span
751 if let Some(src) = self.snippet {
752 let replacement = src.replace("#!", "#");
753 diag.span_suggestion_verbose(
755 rustc_errors::fluent::suggestion,
757 rustc_errors::Applicability::MachineApplicable,
764 #[derive(Diagnostic)]
765 #[diag(passes_duplicate_diagnostic_item)]
766 pub struct DuplicateDiagnosticItem {
772 #[derive(Diagnostic)]
773 #[diag(passes_duplicate_diagnostic_item_in_crate)]
774 pub struct DuplicateDiagnosticItemInCrate {
775 #[note(passes_diagnostic_item_first_defined)]
776 pub span: Option<Span>,
777 pub orig_crate_name: Symbol,
779 pub have_orig_crate_name: Option<()>,
780 pub crate_name: Symbol,
784 #[derive(Diagnostic)]
792 #[derive(Diagnostic)]
793 #[diag(passes_align)]
800 #[derive(Diagnostic)]
808 #[derive(Diagnostic)]
809 #[diag(passes_homogeneous_aggregate)]
810 pub struct HomogeneousAggregate {
813 pub homogeneous_aggregate: String,
816 #[derive(Diagnostic)]
817 #[diag(passes_layout_of)]
818 pub struct LayoutOf {
821 pub normalized_ty: String,
822 pub ty_layout: String,
825 #[derive(Diagnostic)]
826 #[diag(passes_unrecognized_field)]
827 pub struct UnrecognizedField {
833 #[derive(Diagnostic)]
834 #[diag(passes_feature_stable_twice, code = "E0711")]
835 pub struct FeatureStableTwice {
840 pub prev_since: Symbol,
843 #[derive(Diagnostic)]
844 #[diag(passes_feature_previously_declared, code = "E0711")]
845 pub struct FeaturePreviouslyDeclared<'a, 'b> {
849 pub declared: &'a str,
850 pub prev_declared: &'b str,
853 #[derive(Diagnostic)]
854 #[diag(passes_expr_not_allowed_in_context, code = "E0744")]
855 pub struct ExprNotAllowedInContext<'a> {
859 pub context: &'a str,
862 pub struct BreakNonLoop<'a> {
864 pub head: Option<Span>,
866 pub suggestion: String,
867 pub loop_label: Option<Label>,
868 pub break_label: Option<Label>,
869 pub break_expr_kind: &'a ExprKind<'a>,
870 pub break_expr_span: Span,
873 impl<'a> IntoDiagnostic<'_> for BreakNonLoop<'a> {
877 handler: &rustc_errors::Handler,
878 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
879 let mut diag = handler.struct_span_err_with_code(
881 rustc_errors::fluent::passes_break_non_loop,
884 diag.set_arg("kind", self.kind);
885 diag.span_label(self.span, rustc_errors::fluent::label);
886 if let Some(head) = self.head {
887 diag.span_label(head, rustc_errors::fluent::label2);
889 diag.span_suggestion(
891 rustc_errors::fluent::suggestion,
893 Applicability::MaybeIncorrect,
895 if let (Some(label), None) = (self.loop_label, self.break_label) {
896 match self.break_expr_kind {
897 ExprKind::Path(hir::QPath::Resolved(
899 hir::Path { segments: [segment], res: hir::def::Res::Err, .. },
900 )) if label.ident.to_string() == format!("'{}", segment.ident) => {
901 // This error is redundant, we will have already emitted a
902 // suggestion to use the label when `segment` wasn't found
903 // (hence the `Res::Err` check).
907 diag.span_suggestion(
908 self.break_expr_span,
909 rustc_errors::fluent::break_expr_suggestion,
911 Applicability::MaybeIncorrect,
920 #[derive(Diagnostic)]
921 #[diag(passes_continue_labeled_block, code = "E0696")]
922 pub struct ContinueLabeledBlock {
926 #[label(block_label)]
927 pub block_span: Span,
930 #[derive(Diagnostic)]
931 #[diag(passes_break_inside_closure, code = "E0267")]
932 pub struct BreakInsideClosure<'a> {
936 #[label(closure_label)]
937 pub closure_span: Span,
941 #[derive(Diagnostic)]
942 #[diag(passes_break_inside_async_block, code = "E0267")]
943 pub struct BreakInsideAsyncBlock<'a> {
947 #[label(async_block_label)]
948 pub closure_span: Span,
952 #[derive(Diagnostic)]
953 #[diag(passes_outside_loop, code = "E0268")]
954 pub struct OutsideLoop<'a> {
962 #[derive(Diagnostic)]
963 #[diag(passes_unlabeled_in_labeled_block, code = "E0695")]
964 pub struct UnlabeledInLabeledBlock<'a> {
968 pub cf_type: &'a str,
971 #[derive(Diagnostic)]
972 #[diag(passes_unlabeled_cf_in_while_condition, code = "E0590")]
973 pub struct UnlabeledCfInWhileCondition<'a> {
977 pub cf_type: &'a str,
980 #[derive(Diagnostic)]
981 #[diag(passes_cannot_inline_naked_function)]
982 pub struct CannotInlineNakedFunction {
987 #[derive(LintDiagnostic)]
988 #[diag(passes_undefined_naked_function_abi)]
989 pub struct UndefinedNakedFunctionAbi;
991 #[derive(Diagnostic)]
992 #[diag(passes_no_patterns)]
993 pub struct NoPatterns {
998 #[derive(Diagnostic)]
999 #[diag(passes_params_not_allowed)]
1001 pub struct ParamsNotAllowed {
1006 pub struct NakedFunctionsAsmBlock {
1008 pub multiple_asms: Vec<Span>,
1009 pub non_asms: Vec<Span>,
1012 impl IntoDiagnostic<'_> for NakedFunctionsAsmBlock {
1016 handler: &rustc_errors::Handler,
1017 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
1018 let mut diag = handler.struct_span_err_with_code(
1020 rustc_errors::fluent::passes_naked_functions_asm_block,
1023 for span in self.multiple_asms.iter() {
1024 diag.span_label(*span, rustc_errors::fluent::label_multiple_asm);
1026 for span in self.non_asms.iter() {
1027 diag.span_label(*span, rustc_errors::fluent::label_non_asm);
1033 #[derive(Diagnostic)]
1034 #[diag(passes_naked_functions_operands, code = "E0787")]
1035 pub struct NakedFunctionsOperands {
1037 pub unsupported_operands: Vec<Span>,
1040 #[derive(Diagnostic)]
1041 #[diag(passes_naked_functions_asm_options, code = "E0787")]
1042 pub struct NakedFunctionsAsmOptions {
1045 pub unsupported_options: String,
1048 #[derive(Diagnostic)]
1049 #[diag(passes_naked_functions_must_use_noreturn, code = "E0787")]
1050 pub struct NakedFunctionsMustUseNoreturn {
1053 #[suggestion(code = ", options(noreturn)", applicability = "machine-applicable")]
1054 pub last_span: Span,
1057 #[derive(Diagnostic)]
1058 #[diag(passes_attr_only_on_main)]
1059 pub struct AttrOnlyOnMain {
1065 #[derive(Diagnostic)]
1066 #[diag(passes_attr_only_on_root_main)]
1067 pub struct AttrOnlyOnRootMain {
1073 #[derive(Diagnostic)]
1074 #[diag(passes_attr_only_in_functions)]
1075 pub struct AttrOnlyInFunctions {
1081 #[derive(Diagnostic)]
1082 #[diag(passes_multiple_rustc_main, code = "E0137")]
1083 pub struct MultipleRustcMain {
1088 #[label(additional)]
1089 pub additional: Span,
1092 #[derive(Diagnostic)]
1093 #[diag(passes_multiple_start_functions, code = "E0138")]
1094 pub struct MultipleStartFunctions {
1103 #[derive(Diagnostic)]
1104 #[diag(passes_extern_main)]
1105 pub struct ExternMain {
1110 #[derive(Diagnostic)]
1111 #[diag(passes_unix_sigpipe_values)]
1112 pub struct UnixSigpipeValues {
1117 #[derive(Diagnostic)]
1118 #[diag(passes_no_main_function, code = "E0601")]
1119 pub struct NoMainFunction {
1122 pub crate_name: String,
1125 pub struct NoMainErr {
1127 pub crate_name: Symbol,
1128 pub has_filename: bool,
1129 pub filename: PathBuf,
1130 pub file_empty: bool,
1131 pub non_main_fns: Vec<Span>,
1132 pub main_def_opt: Option<MainDefinition>,
1133 pub add_teach_note: bool,
1136 impl<'a> IntoDiagnostic<'a> for NoMainErr {
1140 handler: &'a rustc_errors::Handler,
1141 ) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> {
1142 let mut diag = handler.struct_span_err_with_code(
1144 rustc_errors::fluent::passes_no_main_function,
1147 diag.set_arg("crate_name", self.crate_name);
1148 diag.set_arg("filename", self.filename);
1149 diag.set_arg("has_filename", self.has_filename);
1150 let note = if !self.non_main_fns.is_empty() {
1151 for &span in &self.non_main_fns {
1152 diag.span_note(span, rustc_errors::fluent::here_is_main);
1154 diag.note(rustc_errors::fluent::one_or_more_possible_main);
1155 diag.help(rustc_errors::fluent::consider_moving_main);
1156 // There were some functions named `main` though. Try to give the user a hint.
1157 rustc_errors::fluent::main_must_be_defined_at_crate
1158 } else if self.has_filename {
1159 rustc_errors::fluent::consider_adding_main_to_file
1161 rustc_errors::fluent::consider_adding_main_at_crate
1163 if self.file_empty {
1166 diag.set_span(self.sp.shrink_to_hi());
1167 diag.span_label(self.sp.shrink_to_hi(), note);
1170 if let Some(main_def) = self.main_def_opt && main_def.opt_fn_def_id().is_none(){
1171 // There is something at `crate::main`, but it is not a function definition.
1172 diag.span_label(main_def.span, rustc_errors::fluent::non_function_main);
1175 if self.add_teach_note {
1176 diag.note(rustc_errors::fluent::teach_note);
1182 pub struct DuplicateLangItem {
1183 pub local_span: Option<Span>,
1184 pub lang_item_name: Symbol,
1185 pub crate_name: Symbol,
1186 pub dependency_of: Symbol,
1189 pub first_defined_span: Option<Span>,
1190 pub orig_crate_name: Symbol,
1191 pub orig_dependency_of: Symbol,
1192 pub orig_is_local: bool,
1193 pub orig_path: String,
1194 pub(crate) duplicate: Duplicate,
1197 impl IntoDiagnostic<'_> for DuplicateLangItem {
1201 handler: &rustc_errors::Handler,
1202 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
1203 let mut diag = handler.struct_err_with_code(
1204 match self.duplicate {
1205 Duplicate::Plain => rustc_errors::fluent::passes_duplicate_lang_item,
1207 Duplicate::Crate => rustc_errors::fluent::passes_duplicate_lang_item_crate,
1208 Duplicate::CrateDepends => {
1209 rustc_errors::fluent::passes_duplicate_lang_item_crate_depends
1214 diag.set_arg("lang_item_name", self.lang_item_name);
1215 diag.set_arg("crate_name", self.crate_name);
1216 diag.set_arg("dependency_of", self.dependency_of);
1217 diag.set_arg("path", self.path);
1218 diag.set_arg("orig_crate_name", self.orig_crate_name);
1219 diag.set_arg("orig_dependency_of", self.orig_dependency_of);
1220 diag.set_arg("orig_path", self.orig_path);
1221 if let Some(span) = self.local_span {
1222 diag.set_span(span);
1224 if let Some(span) = self.first_defined_span {
1225 diag.span_note(span, rustc_errors::fluent::first_defined_span);
1227 if self.orig_dependency_of.is_empty() {
1228 diag.note(rustc_errors::fluent::first_defined_crate);
1230 diag.note(rustc_errors::fluent::first_defined_crate_depends);
1233 if self.orig_is_local {
1234 diag.note(rustc_errors::fluent::first_definition_local);
1236 diag.note(rustc_errors::fluent::first_definition_path);
1240 diag.note(rustc_errors::fluent::second_definition_local);
1242 diag.note(rustc_errors::fluent::second_definition_path);
1249 #[derive(Diagnostic)]
1250 #[diag(passes_incorrect_target, code = "E0718")]
1251 pub struct IncorrectTarget<'a> {
1255 pub generics_span: Span,
1256 pub name: &'a str, // cannot be symbol because it renders e.g. `r#fn` instead of `fn`
1257 pub kind: &'static str,
1259 pub actual_num: usize,
1263 #[derive(LintDiagnostic)]
1264 #[diag(passes_useless_assignment)]
1265 pub struct UselessAssignment<'a> {
1266 pub is_field_assign: bool,
1270 #[derive(LintDiagnostic)]
1271 #[diag(passes_only_has_effect_on)]
1272 pub struct OnlyHasEffectOn {
1273 pub attr_name: Symbol,
1274 pub target_name: String,
1277 #[derive(Diagnostic)]
1278 #[diag(passes_object_lifetime_err)]
1279 pub struct ObjectLifetimeErr {
1285 #[derive(Diagnostic)]
1286 #[diag(passes_unrecognized_repr_hint, code = "E0552")]
1288 pub struct UnrecognizedReprHint {
1293 #[derive(Diagnostic)]
1294 pub enum AttrApplication {
1295 #[diag(passes_attr_application_enum, code = "E0517")]
1302 #[diag(passes_attr_application_struct, code = "E0517")]
1309 #[diag(passes_attr_application_struct_union, code = "E0517")]
1316 #[diag(passes_attr_application_struct_enum_union, code = "E0517")]
1323 #[diag(passes_attr_application_struct_enum_function_union, code = "E0517")]
1324 StructEnumFunctionUnion {
1332 #[derive(Diagnostic)]
1333 #[diag(passes_transparent_incompatible, code = "E0692")]
1334 pub struct TransparentIncompatible {
1336 pub hint_spans: Vec<Span>,
1340 #[derive(Diagnostic)]
1341 #[diag(passes_deprecated_attribute, code = "E0549")]
1342 pub struct DeprecatedAttribute {
1347 #[derive(Diagnostic)]
1348 #[diag(passes_useless_stability)]
1349 pub struct UselessStability {
1357 #[derive(Diagnostic)]
1358 #[diag(passes_invalid_stability)]
1359 pub struct InvalidStability {
1367 #[derive(Diagnostic)]
1368 #[diag(passes_cannot_stabilize_deprecated)]
1369 pub struct CannotStabilizeDeprecated {
1377 #[derive(Diagnostic)]
1378 #[diag(passes_invalid_deprecation_version)]
1379 pub struct InvalidDeprecationVersion {
1387 #[derive(Diagnostic)]
1388 #[diag(passes_missing_stability_attr)]
1389 pub struct MissingStabilityAttr<'a> {
1395 #[derive(Diagnostic)]
1396 #[diag(passes_missing_const_stab_attr)]
1397 pub struct MissingConstStabAttr<'a> {
1403 #[derive(Diagnostic)]
1404 #[diag(passes_trait_impl_const_stable)]
1406 pub struct TraitImplConstStable {
1411 #[derive(Diagnostic)]
1412 #[diag(passes_feature_only_on_nightly, code = "E0554")]
1413 pub struct FeatureOnlyOnNightly {
1416 pub release_channel: &'static str,
1419 #[derive(Diagnostic)]
1420 #[diag(passes_unknown_feature, code = "E0635")]
1421 pub struct UnknownFeature {
1424 pub feature: Symbol,
1427 #[derive(Diagnostic)]
1428 #[diag(passes_implied_feature_not_exist)]
1429 pub struct ImpliedFeatureNotExist {
1432 pub feature: Symbol,
1433 pub implied_by: Symbol,
1436 #[derive(Diagnostic)]
1437 #[diag(passes_duplicate_feature_err, code = "E0636")]
1438 pub struct DuplicateFeatureErr {
1441 pub feature: Symbol,
1443 #[derive(Diagnostic)]
1444 #[diag(passes_missing_const_err)]
1445 pub struct MissingConstErr {
1448 pub fn_sig_span: Span,
1450 pub const_span: Span,
1453 #[derive(LintDiagnostic)]
1454 pub enum MultipleDeadCodes<'tcx> {
1455 #[diag(passes_dead_codes)]
1460 participle: &'tcx str,
1461 name_list: DiagnosticSymbolList,
1463 parent_info: Option<ParentInfo<'tcx>>,
1465 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1467 #[diag(passes_dead_codes)]
1468 UnusedTupleStructFields {
1472 participle: &'tcx str,
1473 name_list: DiagnosticSymbolList,
1475 change_fields_suggestion: ChangeFieldsToBeOfUnitType,
1477 parent_info: Option<ParentInfo<'tcx>>,
1479 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1483 #[derive(Subdiagnostic)]
1484 #[label(passes_parent_info)]
1485 pub struct ParentInfo<'tcx> {
1487 pub descr: &'tcx str,
1488 pub parent_descr: &'tcx str,
1493 #[derive(Subdiagnostic)]
1494 #[note(passes_ignored_derived_impls)]
1495 pub struct IgnoredDerivedImpls {
1497 pub trait_list: DiagnosticSymbolList,
1498 pub trait_list_len: usize,
1501 #[derive(Subdiagnostic)]
1502 #[multipart_suggestion(passes_change_fields_to_be_of_unit_type, applicability = "has-placeholders")]
1503 pub struct ChangeFieldsToBeOfUnitType {
1505 #[suggestion_part(code = "()")]
1506 pub spans: Vec<Span>,