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;
18 #[diag(passes_incorrect_do_not_recommend_location)]
19 pub struct IncorrectDoNotRecommendLocation {
24 #[derive(LintDiagnostic)]
25 #[diag(passes_outer_crate_level_attr)]
26 pub struct OuterCrateLevelAttr;
28 #[derive(LintDiagnostic)]
29 #[diag(passes_inner_crate_level_attr)]
30 pub struct InnerCrateLevelAttr;
32 #[derive(LintDiagnostic)]
33 #[diag(passes_ignored_attr_with_macro)]
34 pub struct IgnoredAttrWithMacro<'a> {
38 #[derive(LintDiagnostic)]
39 #[diag(passes_ignored_attr)]
40 pub struct IgnoredAttr<'a> {
44 #[derive(LintDiagnostic)]
45 #[diag(passes_inline_ignored_function_prototype)]
46 pub struct IgnoredInlineAttrFnProto;
48 #[derive(LintDiagnostic)]
49 #[diag(passes_inline_ignored_constants)]
52 pub struct IgnoredInlineAttrConstants;
55 #[diag(passes_inline_not_fn_or_closure, code = "E0518")]
56 pub struct InlineNotFnOrClosure {
63 #[derive(LintDiagnostic)]
64 #[diag(passes_no_coverage_ignored_function_prototype)]
65 pub struct IgnoredNoCoverageFnProto;
67 #[derive(LintDiagnostic)]
68 #[diag(passes_no_coverage_propagate)]
69 pub struct IgnoredNoCoveragePropagate;
71 #[derive(LintDiagnostic)]
72 #[diag(passes_no_coverage_fn_defn)]
73 pub struct IgnoredNoCoverageFnDefn;
76 #[diag(passes_no_coverage_not_coverable, code = "E0788")]
77 pub struct IgnoredNoCoverageNotCoverable {
85 #[diag(passes_should_be_applied_to_fn)]
86 pub struct AttrShouldBeAppliedToFn {
95 #[diag(passes_naked_tracked_caller, code = "E0736")]
96 pub struct NakedTrackedCaller {
101 #[derive(Diagnostic)]
102 #[diag(passes_should_be_applied_to_fn, code = "E0739")]
103 pub struct TrackedCallerWrongLocation {
111 #[derive(Diagnostic)]
112 #[diag(passes_should_be_applied_to_struct_enum, code = "E0701")]
113 pub struct NonExhaustiveWrongLocation {
120 #[derive(Diagnostic)]
121 #[diag(passes_should_be_applied_to_trait)]
122 pub struct AttrShouldBeAppliedToTrait {
129 #[derive(LintDiagnostic)]
130 #[diag(passes_target_feature_on_statement)]
131 pub struct TargetFeatureOnStatement;
133 #[derive(Diagnostic)]
134 #[diag(passes_should_be_applied_to_static)]
135 pub struct AttrShouldBeAppliedToStatic {
142 #[derive(Diagnostic)]
143 #[diag(passes_doc_expect_str)]
144 pub struct DocExpectStr<'a> {
147 pub attr_name: &'a str,
150 #[derive(Diagnostic)]
151 #[diag(passes_doc_alias_empty)]
152 pub struct DocAliasEmpty<'a> {
155 pub attr_str: &'a str,
158 #[derive(Diagnostic)]
159 #[diag(passes_doc_alias_bad_char)]
160 pub struct DocAliasBadChar<'a> {
163 pub attr_str: &'a str,
167 #[derive(Diagnostic)]
168 #[diag(passes_doc_alias_start_end)]
169 pub struct DocAliasStartEnd<'a> {
172 pub attr_str: &'a str,
175 #[derive(Diagnostic)]
176 #[diag(passes_doc_alias_bad_location)]
177 pub struct DocAliasBadLocation<'a> {
180 pub attr_str: &'a str,
181 pub location: &'a str,
184 #[derive(Diagnostic)]
185 #[diag(passes_doc_alias_not_an_alias)]
186 pub struct DocAliasNotAnAlias<'a> {
189 pub attr_str: &'a str,
192 #[derive(LintDiagnostic)]
193 #[diag(passes_doc_alias_duplicated)]
194 pub struct DocAliasDuplicated {
196 pub first_defn: Span,
199 #[derive(Diagnostic)]
200 #[diag(passes_doc_alias_not_string_literal)]
201 pub struct DocAliasNotStringLiteral {
206 #[derive(Diagnostic)]
207 #[diag(passes_doc_alias_malformed)]
208 pub struct DocAliasMalformed {
213 #[derive(Diagnostic)]
214 #[diag(passes_doc_keyword_empty_mod)]
215 pub struct DocKeywordEmptyMod {
220 #[derive(Diagnostic)]
221 #[diag(passes_doc_keyword_not_mod)]
222 pub struct DocKeywordNotMod {
227 #[derive(Diagnostic)]
228 #[diag(passes_doc_keyword_invalid_ident)]
229 pub struct DocKeywordInvalidIdent {
232 pub doc_keyword: Symbol,
235 #[derive(Diagnostic)]
236 #[diag(passes_doc_fake_variadic_not_valid)]
237 pub struct DocFakeVariadicNotValid {
242 #[derive(Diagnostic)]
243 #[diag(passes_doc_keyword_only_impl)]
244 pub struct DocKeywordOnlyImpl {
249 #[derive(Diagnostic)]
250 #[diag(passes_doc_inline_conflict)]
252 pub struct DocKeywordConflict {
254 pub spans: MultiSpan,
257 #[derive(LintDiagnostic)]
258 #[diag(passes_doc_inline_only_use)]
260 pub struct DocInlineOnlyUse {
263 #[label(not_a_use_item_label)]
264 pub item_span: Option<Span>,
267 #[derive(Diagnostic)]
268 #[diag(passes_doc_attr_not_crate_level)]
269 pub struct DocAttrNotCrateLevel<'a> {
272 pub attr_name: &'a str,
275 #[derive(LintDiagnostic)]
276 #[diag(passes_doc_test_unknown)]
277 pub struct DocTestUnknown {
281 #[derive(LintDiagnostic)]
282 #[diag(passes_doc_test_takes_list)]
283 pub struct DocTestTakesList;
285 #[derive(LintDiagnostic)]
286 #[diag(passes_doc_cfg_hide_takes_list)]
287 pub struct DocCfgHideTakesList;
289 #[derive(LintDiagnostic)]
290 #[diag(passes_doc_primitive)]
291 pub struct DocPrimitive;
293 #[derive(LintDiagnostic)]
294 #[diag(passes_doc_test_unknown_any)]
295 pub struct DocTestUnknownAny {
299 #[derive(LintDiagnostic)]
300 #[diag(passes_doc_test_unknown_spotlight)]
303 pub struct DocTestUnknownSpotlight {
305 #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")]
309 #[derive(LintDiagnostic)]
310 #[diag(passes_doc_test_unknown_include)]
311 pub struct DocTestUnknownInclude {
314 pub inner: &'static str,
315 #[suggestion(code = "#{inner}[doc = include_str!(\"{value}\")]")]
316 pub sugg: (Span, Applicability),
319 #[derive(LintDiagnostic)]
320 #[diag(passes_doc_invalid)]
321 pub struct DocInvalid;
323 #[derive(Diagnostic)]
324 #[diag(passes_pass_by_value)]
325 pub struct PassByValue {
332 #[derive(Diagnostic)]
333 #[diag(passes_allow_incoherent_impl)]
334 pub struct AllowIncoherentImpl {
341 #[derive(Diagnostic)]
342 #[diag(passes_has_incoherent_inherent_impl)]
343 pub struct HasIncoherentInherentImpl {
350 #[derive(LintDiagnostic)]
351 #[diag(passes_must_use_async)]
352 pub struct MustUseAsync {
357 #[derive(LintDiagnostic)]
358 #[diag(passes_must_use_no_effect)]
359 pub struct MustUseNoEffect {
360 pub article: &'static str,
361 pub target: rustc_hir::Target,
364 #[derive(Diagnostic)]
365 #[diag(passes_must_not_suspend)]
366 pub struct MustNotSuspend {
373 #[derive(LintDiagnostic)]
382 #[derive(LintDiagnostic)]
387 pub span: Option<Span>,
390 #[derive(LintDiagnostic)]
391 #[diag(passes_link_name)]
393 pub struct LinkName<'a> {
395 pub attr_span: Option<Span>,
401 #[derive(Diagnostic)]
402 #[diag(passes_no_link)]
410 #[derive(Diagnostic)]
411 #[diag(passes_export_name)]
412 pub struct ExportName {
419 #[derive(Diagnostic)]
420 #[diag(passes_rustc_layout_scalar_valid_range_not_struct)]
421 pub struct RustcLayoutScalarValidRangeNotStruct {
428 #[derive(Diagnostic)]
429 #[diag(passes_rustc_layout_scalar_valid_range_arg)]
430 pub struct RustcLayoutScalarValidRangeArg {
435 #[derive(Diagnostic)]
436 #[diag(passes_rustc_legacy_const_generics_only)]
437 pub struct RustcLegacyConstGenericsOnly {
441 pub param_span: Span,
444 #[derive(Diagnostic)]
445 #[diag(passes_rustc_legacy_const_generics_index)]
446 pub struct RustcLegacyConstGenericsIndex {
450 pub generics_span: Span,
453 #[derive(Diagnostic)]
454 #[diag(passes_rustc_legacy_const_generics_index_exceed)]
455 pub struct RustcLegacyConstGenericsIndexExceed {
459 pub arg_count: usize,
462 #[derive(Diagnostic)]
463 #[diag(passes_rustc_legacy_const_generics_index_negative)]
464 pub struct RustcLegacyConstGenericsIndexNegative {
466 pub invalid_args: Vec<Span>,
469 #[derive(Diagnostic)]
470 #[diag(passes_rustc_dirty_clean)]
471 pub struct RustcDirtyClean {
476 #[derive(LintDiagnostic)]
477 #[diag(passes_link_section)]
479 pub struct LinkSection {
484 #[derive(LintDiagnostic)]
485 #[diag(passes_no_mangle_foreign)]
488 pub struct NoMangleForeign {
491 #[suggestion(code = "", applicability = "machine-applicable")]
493 pub foreign_item_kind: &'static str,
496 #[derive(LintDiagnostic)]
497 #[diag(passes_no_mangle)]
499 pub struct NoMangle {
504 #[derive(Diagnostic)]
505 #[diag(passes_repr_ident, code = "E0565")]
506 pub struct ReprIdent {
511 #[derive(LintDiagnostic)]
512 #[diag(passes_repr_conflicting, code = "E0566")]
513 pub struct ReprConflicting;
515 #[derive(Diagnostic)]
516 #[diag(passes_used_static)]
517 pub struct UsedStatic {
522 #[derive(Diagnostic)]
523 #[diag(passes_used_compiler_linker)]
524 pub struct UsedCompilerLinker {
526 pub spans: Vec<Span>,
529 #[derive(Diagnostic)]
530 #[diag(passes_allow_internal_unstable)]
531 pub struct AllowInternalUnstable {
538 #[derive(Diagnostic)]
539 #[diag(passes_debug_visualizer_placement)]
540 pub struct DebugVisualizerPlacement {
545 #[derive(Diagnostic)]
546 #[diag(passes_debug_visualizer_invalid)]
550 pub struct DebugVisualizerInvalid {
555 #[derive(Diagnostic)]
556 #[diag(passes_debug_visualizer_unreadable)]
557 pub struct DebugVisualizerUnreadable<'a> {
564 #[derive(Diagnostic)]
565 #[diag(passes_rustc_allow_const_fn_unstable)]
566 pub struct RustcAllowConstFnUnstable {
573 #[derive(Diagnostic)]
574 #[diag(passes_rustc_std_internal_symbol)]
575 pub struct RustcStdInternalSymbol {
582 #[derive(Diagnostic)]
583 #[diag(passes_const_trait)]
584 pub struct ConstTrait {
589 #[derive(Diagnostic)]
590 #[diag(passes_link_ordinal)]
591 pub struct LinkOrdinal {
596 #[derive(Diagnostic)]
597 #[diag(passes_stability_promotable)]
598 pub struct StabilityPromotable {
603 #[derive(LintDiagnostic)]
604 #[diag(passes_deprecated)]
605 pub struct Deprecated;
607 #[derive(LintDiagnostic)]
608 #[diag(passes_macro_use)]
609 pub struct MacroUse {
613 #[derive(LintDiagnostic)]
614 #[diag(passes_macro_export)]
615 pub struct MacroExport;
617 #[derive(LintDiagnostic)]
618 #[diag(passes_plugin_registrar)]
619 pub struct PluginRegistrar;
621 #[derive(Subdiagnostic)]
622 pub enum UnusedNote {
623 #[note(passes_unused_empty_lints_note)]
624 EmptyList { name: Symbol },
625 #[note(passes_unused_no_lints_note)]
626 NoLints { name: Symbol },
627 #[note(passes_unused_default_method_body_const_note)]
628 DefaultMethodBodyConst,
631 #[derive(LintDiagnostic)]
632 #[diag(passes_unused)]
634 #[suggestion(code = "", applicability = "machine-applicable")]
637 pub note: UnusedNote,
640 #[derive(Diagnostic)]
641 #[diag(passes_non_exported_macro_invalid_attrs, code = "E0518")]
642 pub struct NonExportedMacroInvalidAttrs {
648 #[derive(LintDiagnostic)]
649 #[diag(passes_unused_duplicate)]
650 pub struct UnusedDuplicate {
651 #[suggestion(code = "", applicability = "machine-applicable")]
656 pub warning: Option<()>,
659 #[derive(Diagnostic)]
660 #[diag(passes_unused_multiple)]
661 pub struct UnusedMultiple {
663 #[suggestion(code = "", applicability = "machine-applicable")]
670 #[derive(Diagnostic)]
671 #[diag(passes_rustc_lint_opt_ty)]
672 pub struct RustcLintOptTy {
679 #[derive(Diagnostic)]
680 #[diag(passes_rustc_lint_opt_deny_field_access)]
681 pub struct RustcLintOptDenyFieldAccess {
688 #[derive(Diagnostic)]
689 #[diag(passes_collapse_debuginfo)]
690 pub struct CollapseDebuginfo {
697 #[derive(LintDiagnostic)]
698 #[diag(passes_deprecated_annotation_has_no_effect)]
699 pub struct DeprecatedAnnotationHasNoEffect {
700 #[suggestion(applicability = "machine-applicable", code = "")]
704 #[derive(Diagnostic)]
705 #[diag(passes_unknown_external_lang_item, code = "E0264")]
706 pub struct UnknownExternLangItem {
709 pub lang_item: Symbol,
712 #[derive(Diagnostic)]
713 #[diag(passes_missing_panic_handler)]
714 pub struct MissingPanicHandler;
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 {
754 handler: &'_ rustc_errors::Handler,
755 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
756 let mut diag = handler.struct_err(rustc_errors::fluent::passes_invalid_attr_at_crate_level);
757 diag.set_span(self.span);
758 diag.set_arg("name", self.name);
759 // Only emit an error with a suggestion if we can create a string out
760 // of the attribute span
761 if let Some(src) = self.snippet {
762 let replacement = src.replace("#!", "#");
763 diag.span_suggestion_verbose(
765 rustc_errors::fluent::suggestion,
767 rustc_errors::Applicability::MachineApplicable,
774 #[derive(Diagnostic)]
775 #[diag(passes_duplicate_diagnostic_item)]
776 pub struct DuplicateDiagnosticItem {
782 #[derive(Diagnostic)]
783 #[diag(passes_duplicate_diagnostic_item_in_crate)]
784 pub struct DuplicateDiagnosticItemInCrate {
785 #[note(passes_diagnostic_item_first_defined)]
786 pub span: Option<Span>,
787 pub orig_crate_name: Symbol,
789 pub have_orig_crate_name: Option<()>,
790 pub crate_name: Symbol,
794 #[derive(Diagnostic)]
802 #[derive(Diagnostic)]
803 #[diag(passes_align)]
810 #[derive(Diagnostic)]
818 #[derive(Diagnostic)]
819 #[diag(passes_homogeneous_aggregate)]
820 pub struct HomogeneousAggregate {
823 pub homogeneous_aggregate: String,
826 #[derive(Diagnostic)]
827 #[diag(passes_layout_of)]
828 pub struct LayoutOf {
831 pub normalized_ty: String,
832 pub ty_layout: String,
835 #[derive(Diagnostic)]
836 #[diag(passes_unrecognized_field)]
837 pub struct UnrecognizedField {
843 #[derive(Diagnostic)]
844 #[diag(passes_feature_stable_twice, code = "E0711")]
845 pub struct FeatureStableTwice {
850 pub prev_since: Symbol,
853 #[derive(Diagnostic)]
854 #[diag(passes_feature_previously_declared, code = "E0711")]
855 pub struct FeaturePreviouslyDeclared<'a, 'b> {
859 pub declared: &'a str,
860 pub prev_declared: &'b str,
863 #[derive(Diagnostic)]
864 #[diag(passes_expr_not_allowed_in_context, code = "E0744")]
865 pub struct ExprNotAllowedInContext<'a> {
869 pub context: &'a str,
872 pub struct BreakNonLoop<'a> {
874 pub head: Option<Span>,
876 pub suggestion: String,
877 pub loop_label: Option<Label>,
878 pub break_label: Option<Label>,
879 pub break_expr_kind: &'a ExprKind<'a>,
880 pub break_expr_span: Span,
883 impl<'a> IntoDiagnostic<'_> for BreakNonLoop<'a> {
887 handler: &rustc_errors::Handler,
888 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
889 let mut diag = handler.struct_span_err_with_code(
891 rustc_errors::fluent::passes_break_non_loop,
894 diag.set_arg("kind", self.kind);
895 diag.span_label(self.span, rustc_errors::fluent::label);
896 if let Some(head) = self.head {
897 diag.span_label(head, rustc_errors::fluent::label2);
899 diag.span_suggestion(
901 rustc_errors::fluent::suggestion,
903 Applicability::MaybeIncorrect,
905 if let (Some(label), None) = (self.loop_label, self.break_label) {
906 match self.break_expr_kind {
907 ExprKind::Path(hir::QPath::Resolved(
909 hir::Path { segments: [segment], res: hir::def::Res::Err, .. },
910 )) if label.ident.to_string() == format!("'{}", segment.ident) => {
911 // This error is redundant, we will have already emitted a
912 // suggestion to use the label when `segment` wasn't found
913 // (hence the `Res::Err` check).
917 diag.span_suggestion(
918 self.break_expr_span,
919 rustc_errors::fluent::break_expr_suggestion,
921 Applicability::MaybeIncorrect,
930 #[derive(Diagnostic)]
931 #[diag(passes_continue_labeled_block, code = "E0696")]
932 pub struct ContinueLabeledBlock {
936 #[label(block_label)]
937 pub block_span: Span,
940 #[derive(Diagnostic)]
941 #[diag(passes_break_inside_closure, code = "E0267")]
942 pub struct BreakInsideClosure<'a> {
946 #[label(closure_label)]
947 pub closure_span: Span,
951 #[derive(Diagnostic)]
952 #[diag(passes_break_inside_async_block, code = "E0267")]
953 pub struct BreakInsideAsyncBlock<'a> {
957 #[label(async_block_label)]
958 pub closure_span: Span,
962 #[derive(Diagnostic)]
963 #[diag(passes_outside_loop, code = "E0268")]
964 pub struct OutsideLoop<'a> {
972 #[derive(Diagnostic)]
973 #[diag(passes_unlabeled_in_labeled_block, code = "E0695")]
974 pub struct UnlabeledInLabeledBlock<'a> {
978 pub cf_type: &'a str,
981 #[derive(Diagnostic)]
982 #[diag(passes_unlabeled_cf_in_while_condition, code = "E0590")]
983 pub struct UnlabeledCfInWhileCondition<'a> {
987 pub cf_type: &'a str,
990 #[derive(Diagnostic)]
991 #[diag(passes_cannot_inline_naked_function)]
992 pub struct CannotInlineNakedFunction {
997 #[derive(LintDiagnostic)]
998 #[diag(passes_undefined_naked_function_abi)]
999 pub struct UndefinedNakedFunctionAbi;
1001 #[derive(Diagnostic)]
1002 #[diag(passes_no_patterns)]
1003 pub struct NoPatterns {
1008 #[derive(Diagnostic)]
1009 #[diag(passes_params_not_allowed)]
1011 pub struct ParamsNotAllowed {
1016 pub struct NakedFunctionsAsmBlock {
1018 pub multiple_asms: Vec<Span>,
1019 pub non_asms: Vec<Span>,
1022 impl IntoDiagnostic<'_> for NakedFunctionsAsmBlock {
1026 handler: &rustc_errors::Handler,
1027 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
1028 let mut diag = handler.struct_span_err_with_code(
1030 rustc_errors::fluent::passes_naked_functions_asm_block,
1033 for span in self.multiple_asms.iter() {
1034 diag.span_label(*span, rustc_errors::fluent::label_multiple_asm);
1036 for span in self.non_asms.iter() {
1037 diag.span_label(*span, rustc_errors::fluent::label_non_asm);
1043 #[derive(Diagnostic)]
1044 #[diag(passes_naked_functions_operands, code = "E0787")]
1045 pub struct NakedFunctionsOperands {
1047 pub unsupported_operands: Vec<Span>,
1050 #[derive(Diagnostic)]
1051 #[diag(passes_naked_functions_asm_options, code = "E0787")]
1052 pub struct NakedFunctionsAsmOptions {
1055 pub unsupported_options: String,
1058 #[derive(Diagnostic)]
1059 #[diag(passes_naked_functions_must_use_noreturn, code = "E0787")]
1060 pub struct NakedFunctionsMustUseNoreturn {
1063 #[suggestion(code = ", options(noreturn)", applicability = "machine-applicable")]
1064 pub last_span: Span,
1067 #[derive(Diagnostic)]
1068 #[diag(passes_attr_only_on_main)]
1069 pub struct AttrOnlyOnMain {
1075 #[derive(Diagnostic)]
1076 #[diag(passes_attr_only_on_root_main)]
1077 pub struct AttrOnlyOnRootMain {
1083 #[derive(Diagnostic)]
1084 #[diag(passes_attr_only_in_functions)]
1085 pub struct AttrOnlyInFunctions {
1091 #[derive(Diagnostic)]
1092 #[diag(passes_multiple_rustc_main, code = "E0137")]
1093 pub struct MultipleRustcMain {
1098 #[label(additional)]
1099 pub additional: Span,
1102 #[derive(Diagnostic)]
1103 #[diag(passes_multiple_start_functions, code = "E0138")]
1104 pub struct MultipleStartFunctions {
1113 #[derive(Diagnostic)]
1114 #[diag(passes_extern_main)]
1115 pub struct ExternMain {
1120 #[derive(Diagnostic)]
1121 #[diag(passes_unix_sigpipe_values)]
1122 pub struct UnixSigpipeValues {
1127 #[derive(Diagnostic)]
1128 #[diag(passes_no_main_function, code = "E0601")]
1129 pub struct NoMainFunction {
1132 pub crate_name: String,
1135 pub struct NoMainErr {
1137 pub crate_name: Symbol,
1138 pub has_filename: bool,
1139 pub filename: PathBuf,
1140 pub file_empty: bool,
1141 pub non_main_fns: Vec<Span>,
1142 pub main_def_opt: Option<MainDefinition>,
1143 pub add_teach_note: bool,
1146 impl<'a> IntoDiagnostic<'a> for NoMainErr {
1150 handler: &'a rustc_errors::Handler,
1151 ) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> {
1152 let mut diag = handler.struct_span_err_with_code(
1154 rustc_errors::fluent::passes_no_main_function,
1157 diag.set_arg("crate_name", self.crate_name);
1158 diag.set_arg("filename", self.filename);
1159 diag.set_arg("has_filename", self.has_filename);
1160 let note = if !self.non_main_fns.is_empty() {
1161 for &span in &self.non_main_fns {
1162 diag.span_note(span, rustc_errors::fluent::here_is_main);
1164 diag.note(rustc_errors::fluent::one_or_more_possible_main);
1165 diag.help(rustc_errors::fluent::consider_moving_main);
1166 // There were some functions named `main` though. Try to give the user a hint.
1167 rustc_errors::fluent::main_must_be_defined_at_crate
1168 } else if self.has_filename {
1169 rustc_errors::fluent::consider_adding_main_to_file
1171 rustc_errors::fluent::consider_adding_main_at_crate
1173 if self.file_empty {
1176 diag.set_span(self.sp.shrink_to_hi());
1177 diag.span_label(self.sp.shrink_to_hi(), note);
1180 if let Some(main_def) = self.main_def_opt && main_def.opt_fn_def_id().is_none(){
1181 // There is something at `crate::main`, but it is not a function definition.
1182 diag.span_label(main_def.span, rustc_errors::fluent::non_function_main);
1185 if self.add_teach_note {
1186 diag.note(rustc_errors::fluent::teach_note);
1192 pub struct DuplicateLangItem {
1193 pub local_span: Option<Span>,
1194 pub lang_item_name: Symbol,
1195 pub crate_name: Symbol,
1196 pub dependency_of: Symbol,
1199 pub first_defined_span: Option<Span>,
1200 pub orig_crate_name: Symbol,
1201 pub orig_dependency_of: Symbol,
1202 pub orig_is_local: bool,
1203 pub orig_path: String,
1204 pub(crate) duplicate: Duplicate,
1207 impl IntoDiagnostic<'_> for DuplicateLangItem {
1211 handler: &rustc_errors::Handler,
1212 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
1213 let mut diag = handler.struct_err_with_code(
1214 match self.duplicate {
1215 Duplicate::Plain => rustc_errors::fluent::passes_duplicate_lang_item,
1217 Duplicate::Crate => rustc_errors::fluent::passes_duplicate_lang_item_crate,
1218 Duplicate::CrateDepends => {
1219 rustc_errors::fluent::passes_duplicate_lang_item_crate_depends
1224 diag.set_arg("lang_item_name", self.lang_item_name);
1225 diag.set_arg("crate_name", self.crate_name);
1226 diag.set_arg("dependency_of", self.dependency_of);
1227 diag.set_arg("path", self.path);
1228 diag.set_arg("orig_crate_name", self.orig_crate_name);
1229 diag.set_arg("orig_dependency_of", self.orig_dependency_of);
1230 diag.set_arg("orig_path", self.orig_path);
1231 if let Some(span) = self.local_span {
1232 diag.set_span(span);
1234 if let Some(span) = self.first_defined_span {
1235 diag.span_note(span, rustc_errors::fluent::first_defined_span);
1237 if self.orig_dependency_of.is_empty() {
1238 diag.note(rustc_errors::fluent::first_defined_crate);
1240 diag.note(rustc_errors::fluent::first_defined_crate_depends);
1243 if self.orig_is_local {
1244 diag.note(rustc_errors::fluent::first_definition_local);
1246 diag.note(rustc_errors::fluent::first_definition_path);
1250 diag.note(rustc_errors::fluent::second_definition_local);
1252 diag.note(rustc_errors::fluent::second_definition_path);
1259 #[derive(Diagnostic)]
1260 #[diag(passes_incorrect_target, code = "E0718")]
1261 pub struct IncorrectTarget<'a> {
1265 pub generics_span: Span,
1266 pub name: &'a str, // cannot be symbol because it renders e.g. `r#fn` instead of `fn`
1267 pub kind: &'static str,
1269 pub actual_num: usize,
1273 #[derive(LintDiagnostic)]
1274 #[diag(passes_useless_assignment)]
1275 pub struct UselessAssignment<'a> {
1276 pub is_field_assign: bool,
1280 #[derive(LintDiagnostic)]
1281 #[diag(passes_only_has_effect_on)]
1282 pub struct OnlyHasEffectOn {
1283 pub attr_name: Symbol,
1284 pub target_name: String,
1287 #[derive(Diagnostic)]
1288 #[diag(passes_object_lifetime_err)]
1289 pub struct ObjectLifetimeErr {
1295 #[derive(Diagnostic)]
1296 #[diag(passes_unrecognized_repr_hint, code = "E0552")]
1298 pub struct UnrecognizedReprHint {
1303 #[derive(Diagnostic)]
1304 pub enum AttrApplication {
1305 #[diag(passes_attr_application_enum, code = "E0517")]
1312 #[diag(passes_attr_application_struct, code = "E0517")]
1319 #[diag(passes_attr_application_struct_union, code = "E0517")]
1326 #[diag(passes_attr_application_struct_enum_union, code = "E0517")]
1333 #[diag(passes_attr_application_struct_enum_function_union, code = "E0517")]
1334 StructEnumFunctionUnion {
1342 #[derive(Diagnostic)]
1343 #[diag(passes_transparent_incompatible, code = "E0692")]
1344 pub struct TransparentIncompatible {
1346 pub hint_spans: Vec<Span>,
1350 #[derive(Diagnostic)]
1351 #[diag(passes_deprecated_attribute, code = "E0549")]
1352 pub struct DeprecatedAttribute {
1357 #[derive(Diagnostic)]
1358 #[diag(passes_useless_stability)]
1359 pub struct UselessStability {
1367 #[derive(Diagnostic)]
1368 #[diag(passes_invalid_stability)]
1369 pub struct InvalidStability {
1377 #[derive(Diagnostic)]
1378 #[diag(passes_cannot_stabilize_deprecated)]
1379 pub struct CannotStabilizeDeprecated {
1387 #[derive(Diagnostic)]
1388 #[diag(passes_invalid_deprecation_version)]
1389 pub struct InvalidDeprecationVersion {
1397 #[derive(Diagnostic)]
1398 #[diag(passes_missing_stability_attr)]
1399 pub struct MissingStabilityAttr<'a> {
1405 #[derive(Diagnostic)]
1406 #[diag(passes_missing_const_stab_attr)]
1407 pub struct MissingConstStabAttr<'a> {
1413 #[derive(Diagnostic)]
1414 #[diag(passes_trait_impl_const_stable)]
1416 pub struct TraitImplConstStable {
1421 #[derive(Diagnostic)]
1422 #[diag(passes_feature_only_on_nightly, code = "E0554")]
1423 pub struct FeatureOnlyOnNightly {
1426 pub release_channel: &'static str,
1429 #[derive(Diagnostic)]
1430 #[diag(passes_unknown_feature, code = "E0635")]
1431 pub struct UnknownFeature {
1434 pub feature: Symbol,
1437 #[derive(Diagnostic)]
1438 #[diag(passes_implied_feature_not_exist)]
1439 pub struct ImpliedFeatureNotExist {
1442 pub feature: Symbol,
1443 pub implied_by: Symbol,
1446 #[derive(Diagnostic)]
1447 #[diag(passes_duplicate_feature_err, code = "E0636")]
1448 pub struct DuplicateFeatureErr {
1451 pub feature: Symbol,
1453 #[derive(Diagnostic)]
1454 #[diag(passes_missing_const_err)]
1455 pub struct MissingConstErr {
1458 pub fn_sig_span: Span,
1460 pub const_span: Span,
1463 #[derive(LintDiagnostic)]
1464 pub enum MultipleDeadCodes<'tcx> {
1465 #[diag(passes_dead_codes)]
1470 participle: &'tcx str,
1471 name_list: DiagnosticSymbolList,
1473 parent_info: Option<ParentInfo<'tcx>>,
1475 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1477 #[diag(passes_dead_codes)]
1478 UnusedTupleStructFields {
1482 participle: &'tcx str,
1483 name_list: DiagnosticSymbolList,
1485 change_fields_suggestion: ChangeFieldsToBeOfUnitType,
1487 parent_info: Option<ParentInfo<'tcx>>,
1489 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1493 #[derive(Subdiagnostic)]
1494 #[label(passes_parent_info)]
1495 pub struct ParentInfo<'tcx> {
1497 pub descr: &'tcx str,
1498 pub parent_descr: &'tcx str,
1503 #[derive(Subdiagnostic)]
1504 #[note(passes_ignored_derived_impls)]
1505 pub struct IgnoredDerivedImpls {
1507 pub trait_list: DiagnosticSymbolList,
1508 pub trait_list_len: usize,
1511 #[derive(Subdiagnostic)]
1512 #[multipart_suggestion(passes_change_fields_to_be_of_unit_type, applicability = "has-placeholders")]
1513 pub struct ChangeFieldsToBeOfUnitType {
1515 #[suggestion_part(code = "()")]
1516 pub spans: Vec<Span>,