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;
19 #[diag(passes_incorrect_do_not_recommend_location)]
20 pub struct IncorrectDoNotRecommendLocation {
25 #[derive(LintDiagnostic)]
26 #[diag(passes_outer_crate_level_attr)]
27 pub struct OuterCrateLevelAttr;
29 #[derive(LintDiagnostic)]
30 #[diag(passes_inner_crate_level_attr)]
31 pub struct InnerCrateLevelAttr;
33 #[derive(LintDiagnostic)]
34 #[diag(passes_ignored_attr_with_macro)]
35 pub struct IgnoredAttrWithMacro<'a> {
39 #[derive(LintDiagnostic)]
40 #[diag(passes_ignored_attr)]
41 pub struct IgnoredAttr<'a> {
45 #[derive(LintDiagnostic)]
46 #[diag(passes_inline_ignored_function_prototype)]
47 pub struct IgnoredInlineAttrFnProto;
49 #[derive(LintDiagnostic)]
50 #[diag(passes_inline_ignored_constants)]
53 pub struct IgnoredInlineAttrConstants;
56 #[diag(passes_inline_not_fn_or_closure, code = "E0518")]
57 pub struct InlineNotFnOrClosure {
64 #[derive(LintDiagnostic)]
65 #[diag(passes_no_coverage_ignored_function_prototype)]
66 pub struct IgnoredNoCoverageFnProto;
68 #[derive(LintDiagnostic)]
69 #[diag(passes_no_coverage_propagate)]
70 pub struct IgnoredNoCoveragePropagate;
72 #[derive(LintDiagnostic)]
73 #[diag(passes_no_coverage_fn_defn)]
74 pub struct IgnoredNoCoverageFnDefn;
77 #[diag(passes_no_coverage_not_coverable, code = "E0788")]
78 pub struct IgnoredNoCoverageNotCoverable {
86 #[diag(passes_should_be_applied_to_fn)]
87 pub struct AttrShouldBeAppliedToFn {
96 #[diag(passes_naked_tracked_caller, code = "E0736")]
97 pub struct NakedTrackedCaller {
102 #[derive(Diagnostic)]
103 #[diag(passes_should_be_applied_to_fn, code = "E0739")]
104 pub struct TrackedCallerWrongLocation {
112 #[derive(Diagnostic)]
113 #[diag(passes_should_be_applied_to_struct_enum, code = "E0701")]
114 pub struct NonExhaustiveWrongLocation {
121 #[derive(Diagnostic)]
122 #[diag(passes_should_be_applied_to_trait)]
123 pub struct AttrShouldBeAppliedToTrait {
130 #[derive(LintDiagnostic)]
131 #[diag(passes_target_feature_on_statement)]
132 pub struct TargetFeatureOnStatement;
134 #[derive(Diagnostic)]
135 #[diag(passes_should_be_applied_to_static)]
136 pub struct AttrShouldBeAppliedToStatic {
143 #[derive(Diagnostic)]
144 #[diag(passes_doc_expect_str)]
145 pub struct DocExpectStr<'a> {
148 pub attr_name: &'a str,
151 #[derive(Diagnostic)]
152 #[diag(passes_doc_alias_empty)]
153 pub struct DocAliasEmpty<'a> {
156 pub attr_str: &'a str,
159 #[derive(Diagnostic)]
160 #[diag(passes_doc_alias_bad_char)]
161 pub struct DocAliasBadChar<'a> {
164 pub attr_str: &'a str,
168 #[derive(Diagnostic)]
169 #[diag(passes_doc_alias_start_end)]
170 pub struct DocAliasStartEnd<'a> {
173 pub attr_str: &'a str,
176 #[derive(Diagnostic)]
177 #[diag(passes_doc_alias_bad_location)]
178 pub struct DocAliasBadLocation<'a> {
181 pub attr_str: &'a str,
182 pub location: &'a str,
185 #[derive(Diagnostic)]
186 #[diag(passes_doc_alias_not_an_alias)]
187 pub struct DocAliasNotAnAlias<'a> {
190 pub attr_str: &'a str,
193 #[derive(LintDiagnostic)]
194 #[diag(passes_doc_alias_duplicated)]
195 pub struct DocAliasDuplicated {
197 pub first_defn: Span,
200 #[derive(Diagnostic)]
201 #[diag(passes_doc_alias_not_string_literal)]
202 pub struct DocAliasNotStringLiteral {
207 #[derive(Diagnostic)]
208 #[diag(passes_doc_alias_malformed)]
209 pub struct DocAliasMalformed {
214 #[derive(Diagnostic)]
215 #[diag(passes_doc_keyword_empty_mod)]
216 pub struct DocKeywordEmptyMod {
221 #[derive(Diagnostic)]
222 #[diag(passes_doc_keyword_not_mod)]
223 pub struct DocKeywordNotMod {
228 #[derive(Diagnostic)]
229 #[diag(passes_doc_keyword_invalid_ident)]
230 pub struct DocKeywordInvalidIdent {
233 pub doc_keyword: Symbol,
236 #[derive(Diagnostic)]
237 #[diag(passes_doc_fake_variadic_not_valid)]
238 pub struct DocFakeVariadicNotValid {
243 #[derive(Diagnostic)]
244 #[diag(passes_doc_keyword_only_impl)]
245 pub struct DocKeywordOnlyImpl {
250 #[derive(Diagnostic)]
251 #[diag(passes_doc_inline_conflict)]
253 pub struct DocKeywordConflict {
255 pub spans: MultiSpan,
258 #[derive(LintDiagnostic)]
259 #[diag(passes_doc_inline_only_use)]
261 pub struct DocInlineOnlyUse {
264 #[label(not_a_use_item_label)]
265 pub item_span: Option<Span>,
268 #[derive(Diagnostic)]
269 #[diag(passes_doc_attr_not_crate_level)]
270 pub struct DocAttrNotCrateLevel<'a> {
273 pub attr_name: &'a str,
276 #[derive(LintDiagnostic)]
277 #[diag(passes_doc_test_unknown)]
278 pub struct DocTestUnknown {
282 #[derive(LintDiagnostic)]
283 #[diag(passes_doc_test_takes_list)]
284 pub struct DocTestTakesList;
286 #[derive(LintDiagnostic)]
287 #[diag(passes_doc_cfg_hide_takes_list)]
288 pub struct DocCfgHideTakesList;
290 #[derive(LintDiagnostic)]
291 #[diag(passes_doc_primitive)]
292 pub struct DocPrimitive;
294 #[derive(LintDiagnostic)]
295 #[diag(passes_doc_test_unknown_any)]
296 pub struct DocTestUnknownAny {
300 #[derive(LintDiagnostic)]
301 #[diag(passes_doc_test_unknown_spotlight)]
304 pub struct DocTestUnknownSpotlight {
306 #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")]
310 #[derive(LintDiagnostic)]
311 #[diag(passes_doc_test_unknown_include)]
312 pub struct DocTestUnknownInclude {
315 pub inner: &'static str,
316 #[suggestion(code = "#{inner}[doc = include_str!(\"{value}\")]")]
317 pub sugg: (Span, Applicability),
320 #[derive(LintDiagnostic)]
321 #[diag(passes_doc_invalid)]
322 pub struct DocInvalid;
324 #[derive(Diagnostic)]
325 #[diag(passes_pass_by_value)]
326 pub struct PassByValue {
333 #[derive(Diagnostic)]
334 #[diag(passes_allow_incoherent_impl)]
335 pub struct AllowIncoherentImpl {
342 #[derive(Diagnostic)]
343 #[diag(passes_has_incoherent_inherent_impl)]
344 pub struct HasIncoherentInherentImpl {
351 #[derive(LintDiagnostic)]
352 #[diag(passes_must_use_async)]
353 pub struct MustUseAsync {
358 #[derive(LintDiagnostic)]
359 #[diag(passes_must_use_no_effect)]
360 pub struct MustUseNoEffect {
361 pub article: &'static str,
362 pub target: rustc_hir::Target,
365 #[derive(Diagnostic)]
366 #[diag(passes_must_not_suspend)]
367 pub struct MustNotSuspend {
374 #[derive(LintDiagnostic)]
383 #[derive(LintDiagnostic)]
388 pub span: Option<Span>,
391 #[derive(LintDiagnostic)]
392 #[diag(passes_link_name)]
394 pub struct LinkName<'a> {
396 pub attr_span: Option<Span>,
402 #[derive(Diagnostic)]
403 #[diag(passes_no_link)]
411 #[derive(Diagnostic)]
412 #[diag(passes_export_name)]
413 pub struct ExportName {
420 #[derive(Diagnostic)]
421 #[diag(passes_rustc_layout_scalar_valid_range_not_struct)]
422 pub struct RustcLayoutScalarValidRangeNotStruct {
429 #[derive(Diagnostic)]
430 #[diag(passes_rustc_layout_scalar_valid_range_arg)]
431 pub struct RustcLayoutScalarValidRangeArg {
436 #[derive(Diagnostic)]
437 #[diag(passes_rustc_legacy_const_generics_only)]
438 pub struct RustcLegacyConstGenericsOnly {
442 pub param_span: Span,
445 #[derive(Diagnostic)]
446 #[diag(passes_rustc_legacy_const_generics_index)]
447 pub struct RustcLegacyConstGenericsIndex {
451 pub generics_span: Span,
454 #[derive(Diagnostic)]
455 #[diag(passes_rustc_legacy_const_generics_index_exceed)]
456 pub struct RustcLegacyConstGenericsIndexExceed {
460 pub arg_count: usize,
463 #[derive(Diagnostic)]
464 #[diag(passes_rustc_legacy_const_generics_index_negative)]
465 pub struct RustcLegacyConstGenericsIndexNegative {
467 pub invalid_args: Vec<Span>,
470 #[derive(Diagnostic)]
471 #[diag(passes_rustc_dirty_clean)]
472 pub struct RustcDirtyClean {
477 #[derive(LintDiagnostic)]
478 #[diag(passes_link_section)]
480 pub struct LinkSection {
485 #[derive(LintDiagnostic)]
486 #[diag(passes_no_mangle_foreign)]
489 pub struct NoMangleForeign {
492 #[suggestion(code = "", applicability = "machine-applicable")]
494 pub foreign_item_kind: &'static str,
497 #[derive(LintDiagnostic)]
498 #[diag(passes_no_mangle)]
500 pub struct NoMangle {
505 #[derive(Diagnostic)]
506 #[diag(passes_repr_ident, code = "E0565")]
507 pub struct ReprIdent {
512 #[derive(LintDiagnostic)]
513 #[diag(passes_repr_conflicting, code = "E0566")]
514 pub struct ReprConflicting;
516 #[derive(Diagnostic)]
517 #[diag(passes_used_static)]
518 pub struct UsedStatic {
523 #[derive(Diagnostic)]
524 #[diag(passes_used_compiler_linker)]
525 pub struct UsedCompilerLinker {
527 pub spans: Vec<Span>,
530 #[derive(Diagnostic)]
531 #[diag(passes_allow_internal_unstable)]
532 pub struct AllowInternalUnstable {
539 #[derive(Diagnostic)]
540 #[diag(passes_debug_visualizer_placement)]
541 pub struct DebugVisualizerPlacement {
546 #[derive(Diagnostic)]
547 #[diag(passes_debug_visualizer_invalid)]
551 pub struct DebugVisualizerInvalid {
556 #[derive(Diagnostic)]
557 #[diag(passes_debug_visualizer_unreadable)]
558 pub struct DebugVisualizerUnreadable<'a> {
565 #[derive(Diagnostic)]
566 #[diag(passes_rustc_allow_const_fn_unstable)]
567 pub struct RustcAllowConstFnUnstable {
574 #[derive(Diagnostic)]
575 #[diag(passes_rustc_std_internal_symbol)]
576 pub struct RustcStdInternalSymbol {
583 #[derive(Diagnostic)]
584 #[diag(passes_const_trait)]
585 pub struct ConstTrait {
590 #[derive(Diagnostic)]
591 #[diag(passes_link_ordinal)]
592 pub struct LinkOrdinal {
597 #[derive(Diagnostic)]
598 #[diag(passes_stability_promotable)]
599 pub struct StabilityPromotable {
604 #[derive(LintDiagnostic)]
605 #[diag(passes_deprecated)]
606 pub struct Deprecated;
608 #[derive(LintDiagnostic)]
609 #[diag(passes_macro_use)]
610 pub struct MacroUse {
614 #[derive(LintDiagnostic)]
615 #[diag(passes_macro_export)]
616 pub struct MacroExport;
618 #[derive(LintDiagnostic)]
619 #[diag(passes_plugin_registrar)]
620 pub struct PluginRegistrar;
622 #[derive(Subdiagnostic)]
623 pub enum UnusedNote {
624 #[note(passes_unused_empty_lints_note)]
625 EmptyList { name: Symbol },
626 #[note(passes_unused_no_lints_note)]
627 NoLints { name: Symbol },
628 #[note(passes_unused_default_method_body_const_note)]
629 DefaultMethodBodyConst,
632 #[derive(LintDiagnostic)]
633 #[diag(passes_unused)]
635 #[suggestion(code = "", applicability = "machine-applicable")]
638 pub note: UnusedNote,
641 #[derive(Diagnostic)]
642 #[diag(passes_non_exported_macro_invalid_attrs, code = "E0518")]
643 pub struct NonExportedMacroInvalidAttrs {
649 #[derive(LintDiagnostic)]
650 #[diag(passes_unused_duplicate)]
651 pub struct UnusedDuplicate {
652 #[suggestion(code = "", applicability = "machine-applicable")]
657 pub warning: Option<()>,
660 #[derive(Diagnostic)]
661 #[diag(passes_unused_multiple)]
662 pub struct UnusedMultiple {
664 #[suggestion(code = "", applicability = "machine-applicable")]
671 #[derive(Diagnostic)]
672 #[diag(passes_rustc_lint_opt_ty)]
673 pub struct RustcLintOptTy {
680 #[derive(Diagnostic)]
681 #[diag(passes_rustc_lint_opt_deny_field_access)]
682 pub struct RustcLintOptDenyFieldAccess {
689 #[derive(Diagnostic)]
690 #[diag(passes_collapse_debuginfo)]
691 pub struct CollapseDebuginfo {
698 #[derive(LintDiagnostic)]
699 #[diag(passes_deprecated_annotation_has_no_effect)]
700 pub struct DeprecatedAnnotationHasNoEffect {
701 #[suggestion(applicability = "machine-applicable", code = "")]
705 #[derive(Diagnostic)]
706 #[diag(passes_unknown_external_lang_item, code = "E0264")]
707 pub struct UnknownExternLangItem {
710 pub lang_item: Symbol,
713 #[derive(Diagnostic)]
714 #[diag(passes_missing_panic_handler)]
715 pub struct MissingPanicHandler;
717 #[derive(Diagnostic)]
718 #[diag(passes_missing_lang_item)]
721 pub struct MissingLangItem {
725 #[derive(Diagnostic)]
726 #[diag(passes_lang_item_on_incorrect_target, code = "E0718")]
727 pub struct LangItemOnIncorrectTarget {
732 pub expected_target: Target,
733 pub actual_target: Target,
736 #[derive(Diagnostic)]
737 #[diag(passes_unknown_lang_item, code = "E0522")]
738 pub struct UnknownLangItem {
745 pub struct InvalidAttrAtCrateLevel {
747 pub snippet: Option<String>,
751 impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel {
755 handler: &'_ rustc_errors::Handler,
756 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
757 let mut diag = handler.struct_err(rustc_errors::fluent::passes_invalid_attr_at_crate_level);
758 diag.set_span(self.span);
759 diag.set_arg("name", self.name);
760 // Only emit an error with a suggestion if we can create a string out
761 // of the attribute span
762 if let Some(src) = self.snippet {
763 let replacement = src.replace("#!", "#");
764 diag.span_suggestion_verbose(
766 rustc_errors::fluent::suggestion,
768 rustc_errors::Applicability::MachineApplicable,
775 #[derive(Diagnostic)]
776 #[diag(passes_duplicate_diagnostic_item)]
777 pub struct DuplicateDiagnosticItem {
783 #[derive(Diagnostic)]
784 #[diag(passes_duplicate_diagnostic_item_in_crate)]
785 pub struct DuplicateDiagnosticItemInCrate {
786 #[note(passes_diagnostic_item_first_defined)]
787 pub span: Option<Span>,
788 pub orig_crate_name: Symbol,
790 pub have_orig_crate_name: Option<()>,
791 pub crate_name: Symbol,
795 #[derive(Diagnostic)]
803 #[derive(Diagnostic)]
804 #[diag(passes_align)]
811 #[derive(Diagnostic)]
819 #[derive(Diagnostic)]
820 #[diag(passes_homogeneous_aggregate)]
821 pub struct HomogeneousAggregate {
824 pub homogeneous_aggregate: String,
827 #[derive(Diagnostic)]
828 #[diag(passes_layout_of)]
829 pub struct LayoutOf {
832 pub normalized_ty: String,
833 pub ty_layout: String,
836 #[derive(Diagnostic)]
837 #[diag(passes_unrecognized_field)]
838 pub struct UnrecognizedField {
844 #[derive(Diagnostic)]
845 #[diag(passes_feature_stable_twice, code = "E0711")]
846 pub struct FeatureStableTwice {
851 pub prev_since: Symbol,
854 #[derive(Diagnostic)]
855 #[diag(passes_feature_previously_declared, code = "E0711")]
856 pub struct FeaturePreviouslyDeclared<'a, 'b> {
860 pub declared: &'a str,
861 pub prev_declared: &'b str,
864 #[derive(Diagnostic)]
865 #[diag(passes_expr_not_allowed_in_context, code = "E0744")]
866 pub struct ExprNotAllowedInContext<'a> {
870 pub context: &'a str,
873 pub struct BreakNonLoop<'a> {
875 pub head: Option<Span>,
877 pub suggestion: String,
878 pub loop_label: Option<Label>,
879 pub break_label: Option<Label>,
880 pub break_expr_kind: &'a ExprKind<'a>,
881 pub break_expr_span: Span,
884 impl<'a> IntoDiagnostic<'_> for BreakNonLoop<'a> {
888 handler: &rustc_errors::Handler,
889 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
890 let mut diag = handler.struct_span_err_with_code(
892 rustc_errors::fluent::passes_break_non_loop,
895 diag.set_arg("kind", self.kind);
896 diag.span_label(self.span, rustc_errors::fluent::label);
897 if let Some(head) = self.head {
898 diag.span_label(head, rustc_errors::fluent::label2);
900 diag.span_suggestion(
902 rustc_errors::fluent::suggestion,
904 Applicability::MaybeIncorrect,
906 if let (Some(label), None) = (self.loop_label, self.break_label) {
907 match self.break_expr_kind {
908 ExprKind::Path(hir::QPath::Resolved(
910 hir::Path { segments: [segment], res: hir::def::Res::Err, .. },
911 )) if label.ident.to_string() == format!("'{}", segment.ident) => {
912 // This error is redundant, we will have already emitted a
913 // suggestion to use the label when `segment` wasn't found
914 // (hence the `Res::Err` check).
918 diag.span_suggestion(
919 self.break_expr_span,
920 rustc_errors::fluent::break_expr_suggestion,
922 Applicability::MaybeIncorrect,
931 #[derive(Diagnostic)]
932 #[diag(passes_continue_labeled_block, code = "E0696")]
933 pub struct ContinueLabeledBlock {
937 #[label(block_label)]
938 pub block_span: Span,
941 #[derive(Diagnostic)]
942 #[diag(passes_break_inside_closure, code = "E0267")]
943 pub struct BreakInsideClosure<'a> {
947 #[label(closure_label)]
948 pub closure_span: Span,
952 #[derive(Diagnostic)]
953 #[diag(passes_break_inside_async_block, code = "E0267")]
954 pub struct BreakInsideAsyncBlock<'a> {
958 #[label(async_block_label)]
959 pub closure_span: Span,
963 #[derive(Diagnostic)]
964 #[diag(passes_outside_loop, code = "E0268")]
965 pub struct OutsideLoop<'a> {
973 #[derive(Diagnostic)]
974 #[diag(passes_unlabeled_in_labeled_block, code = "E0695")]
975 pub struct UnlabeledInLabeledBlock<'a> {
979 pub cf_type: &'a str,
982 #[derive(Diagnostic)]
983 #[diag(passes_unlabeled_cf_in_while_condition, code = "E0590")]
984 pub struct UnlabeledCfInWhileCondition<'a> {
988 pub cf_type: &'a str,
991 #[derive(Diagnostic)]
992 #[diag(passes_cannot_inline_naked_function)]
993 pub struct CannotInlineNakedFunction {
998 #[derive(LintDiagnostic)]
999 #[diag(passes_undefined_naked_function_abi)]
1000 pub struct UndefinedNakedFunctionAbi;
1002 #[derive(Diagnostic)]
1003 #[diag(passes_no_patterns)]
1004 pub struct NoPatterns {
1009 #[derive(Diagnostic)]
1010 #[diag(passes_params_not_allowed)]
1012 pub struct ParamsNotAllowed {
1017 pub struct NakedFunctionsAsmBlock {
1019 pub multiple_asms: Vec<Span>,
1020 pub non_asms: Vec<Span>,
1023 impl IntoDiagnostic<'_> for NakedFunctionsAsmBlock {
1027 handler: &rustc_errors::Handler,
1028 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
1029 let mut diag = handler.struct_span_err_with_code(
1031 rustc_errors::fluent::passes_naked_functions_asm_block,
1034 for span in self.multiple_asms.iter() {
1035 diag.span_label(*span, rustc_errors::fluent::label_multiple_asm);
1037 for span in self.non_asms.iter() {
1038 diag.span_label(*span, rustc_errors::fluent::label_non_asm);
1044 #[derive(Diagnostic)]
1045 #[diag(passes_naked_functions_operands, code = "E0787")]
1046 pub struct NakedFunctionsOperands {
1048 pub unsupported_operands: Vec<Span>,
1051 #[derive(Diagnostic)]
1052 #[diag(passes_naked_functions_asm_options, code = "E0787")]
1053 pub struct NakedFunctionsAsmOptions {
1056 pub unsupported_options: String,
1059 #[derive(Diagnostic)]
1060 #[diag(passes_naked_functions_must_use_noreturn, code = "E0787")]
1061 pub struct NakedFunctionsMustUseNoreturn {
1064 #[suggestion(code = ", options(noreturn)", applicability = "machine-applicable")]
1065 pub last_span: Span,
1068 #[derive(Diagnostic)]
1069 #[diag(passes_attr_only_on_main)]
1070 pub struct AttrOnlyOnMain {
1076 #[derive(Diagnostic)]
1077 #[diag(passes_attr_only_on_root_main)]
1078 pub struct AttrOnlyOnRootMain {
1084 #[derive(Diagnostic)]
1085 #[diag(passes_attr_only_in_functions)]
1086 pub struct AttrOnlyInFunctions {
1092 #[derive(Diagnostic)]
1093 #[diag(passes_multiple_rustc_main, code = "E0137")]
1094 pub struct MultipleRustcMain {
1099 #[label(additional)]
1100 pub additional: Span,
1103 #[derive(Diagnostic)]
1104 #[diag(passes_multiple_start_functions, code = "E0138")]
1105 pub struct MultipleStartFunctions {
1114 #[derive(Diagnostic)]
1115 #[diag(passes_extern_main)]
1116 pub struct ExternMain {
1121 #[derive(Diagnostic)]
1122 #[diag(passes_unix_sigpipe_values)]
1123 pub struct UnixSigpipeValues {
1128 #[derive(Diagnostic)]
1129 #[diag(passes_no_main_function, code = "E0601")]
1130 pub struct NoMainFunction {
1133 pub crate_name: String,
1136 pub struct NoMainErr {
1138 pub crate_name: Symbol,
1139 pub has_filename: bool,
1140 pub filename: PathBuf,
1141 pub file_empty: bool,
1142 pub non_main_fns: Vec<Span>,
1143 pub main_def_opt: Option<MainDefinition>,
1144 pub add_teach_note: bool,
1147 impl<'a> IntoDiagnostic<'a> for NoMainErr {
1151 handler: &'a rustc_errors::Handler,
1152 ) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> {
1153 let mut diag = handler.struct_span_err_with_code(
1155 rustc_errors::fluent::passes_no_main_function,
1158 diag.set_arg("crate_name", self.crate_name);
1159 diag.set_arg("filename", self.filename);
1160 diag.set_arg("has_filename", self.has_filename);
1161 let note = if !self.non_main_fns.is_empty() {
1162 for &span in &self.non_main_fns {
1163 diag.span_note(span, rustc_errors::fluent::here_is_main);
1165 diag.note(rustc_errors::fluent::one_or_more_possible_main);
1166 diag.help(rustc_errors::fluent::consider_moving_main);
1167 // There were some functions named `main` though. Try to give the user a hint.
1168 rustc_errors::fluent::main_must_be_defined_at_crate
1169 } else if self.has_filename {
1170 rustc_errors::fluent::consider_adding_main_to_file
1172 rustc_errors::fluent::consider_adding_main_at_crate
1174 if self.file_empty {
1177 diag.set_span(self.sp.shrink_to_hi());
1178 diag.span_label(self.sp.shrink_to_hi(), note);
1181 if let Some(main_def) = self.main_def_opt && main_def.opt_fn_def_id().is_none(){
1182 // There is something at `crate::main`, but it is not a function definition.
1183 diag.span_label(main_def.span, rustc_errors::fluent::non_function_main);
1186 if self.add_teach_note {
1187 diag.note(rustc_errors::fluent::teach_note);
1193 pub struct DuplicateLangItem {
1194 pub local_span: Option<Span>,
1195 pub lang_item_name: Symbol,
1196 pub crate_name: Symbol,
1197 pub dependency_of: Symbol,
1200 pub first_defined_span: Option<Span>,
1201 pub orig_crate_name: Symbol,
1202 pub orig_dependency_of: Symbol,
1203 pub orig_is_local: bool,
1204 pub orig_path: String,
1205 pub(crate) duplicate: Duplicate,
1208 impl IntoDiagnostic<'_> for DuplicateLangItem {
1212 handler: &rustc_errors::Handler,
1213 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
1214 let mut diag = handler.struct_err_with_code(
1215 match self.duplicate {
1216 Duplicate::Plain => rustc_errors::fluent::passes_duplicate_lang_item,
1218 Duplicate::Crate => rustc_errors::fluent::passes_duplicate_lang_item_crate,
1219 Duplicate::CrateDepends => {
1220 rustc_errors::fluent::passes_duplicate_lang_item_crate_depends
1225 diag.set_arg("lang_item_name", self.lang_item_name);
1226 diag.set_arg("crate_name", self.crate_name);
1227 diag.set_arg("dependency_of", self.dependency_of);
1228 diag.set_arg("path", self.path);
1229 diag.set_arg("orig_crate_name", self.orig_crate_name);
1230 diag.set_arg("orig_dependency_of", self.orig_dependency_of);
1231 diag.set_arg("orig_path", self.orig_path);
1232 if let Some(span) = self.local_span {
1233 diag.set_span(span);
1235 if let Some(span) = self.first_defined_span {
1236 diag.span_note(span, rustc_errors::fluent::first_defined_span);
1238 if self.orig_dependency_of.is_empty() {
1239 diag.note(rustc_errors::fluent::first_defined_crate);
1241 diag.note(rustc_errors::fluent::first_defined_crate_depends);
1244 if self.orig_is_local {
1245 diag.note(rustc_errors::fluent::first_definition_local);
1247 diag.note(rustc_errors::fluent::first_definition_path);
1251 diag.note(rustc_errors::fluent::second_definition_local);
1253 diag.note(rustc_errors::fluent::second_definition_path);
1260 #[derive(Diagnostic)]
1261 #[diag(passes_incorrect_target, code = "E0718")]
1262 pub struct IncorrectTarget<'a> {
1266 pub generics_span: Span,
1267 pub name: &'a str, // cannot be symbol because it renders e.g. `r#fn` instead of `fn`
1268 pub kind: &'static str,
1270 pub actual_num: usize,
1274 #[derive(LintDiagnostic)]
1275 #[diag(passes_useless_assignment)]
1276 pub struct UselessAssignment<'a> {
1277 pub is_field_assign: bool,
1281 #[derive(LintDiagnostic)]
1282 #[diag(passes_only_has_effect_on)]
1283 pub struct OnlyHasEffectOn {
1284 pub attr_name: Symbol,
1285 pub target_name: String,
1288 #[derive(Diagnostic)]
1289 #[diag(passes_object_lifetime_err)]
1290 pub struct ObjectLifetimeErr {
1296 #[derive(Diagnostic)]
1297 #[diag(passes_unrecognized_repr_hint, code = "E0552")]
1299 pub struct UnrecognizedReprHint {
1304 #[derive(Diagnostic)]
1305 pub enum AttrApplication {
1306 #[diag(passes_attr_application_enum, code = "E0517")]
1313 #[diag(passes_attr_application_struct, code = "E0517")]
1320 #[diag(passes_attr_application_struct_union, code = "E0517")]
1327 #[diag(passes_attr_application_struct_enum_union, code = "E0517")]
1334 #[diag(passes_attr_application_struct_enum_function_union, code = "E0517")]
1335 StructEnumFunctionUnion {
1343 #[derive(Diagnostic)]
1344 #[diag(passes_transparent_incompatible, code = "E0692")]
1345 pub struct TransparentIncompatible {
1347 pub hint_spans: Vec<Span>,
1351 #[derive(Diagnostic)]
1352 #[diag(passes_deprecated_attribute, code = "E0549")]
1353 pub struct DeprecatedAttribute {
1358 #[derive(Diagnostic)]
1359 #[diag(passes_useless_stability)]
1360 pub struct UselessStability {
1368 #[derive(Diagnostic)]
1369 #[diag(passes_invalid_stability)]
1370 pub struct InvalidStability {
1378 #[derive(Diagnostic)]
1379 #[diag(passes_cannot_stabilize_deprecated)]
1380 pub struct CannotStabilizeDeprecated {
1388 #[derive(Diagnostic)]
1389 #[diag(passes_invalid_deprecation_version)]
1390 pub struct InvalidDeprecationVersion {
1398 #[derive(Diagnostic)]
1399 #[diag(passes_missing_stability_attr)]
1400 pub struct MissingStabilityAttr<'a> {
1406 #[derive(Diagnostic)]
1407 #[diag(passes_missing_const_stab_attr)]
1408 pub struct MissingConstStabAttr<'a> {
1414 #[derive(Diagnostic)]
1415 #[diag(passes_trait_impl_const_stable)]
1417 pub struct TraitImplConstStable {
1422 #[derive(Diagnostic)]
1423 #[diag(passes_feature_only_on_nightly, code = "E0554")]
1424 pub struct FeatureOnlyOnNightly {
1427 pub release_channel: &'static str,
1430 #[derive(Diagnostic)]
1431 #[diag(passes_unknown_feature, code = "E0635")]
1432 pub struct UnknownFeature {
1435 pub feature: Symbol,
1438 #[derive(Diagnostic)]
1439 #[diag(passes_implied_feature_not_exist)]
1440 pub struct ImpliedFeatureNotExist {
1443 pub feature: Symbol,
1444 pub implied_by: Symbol,
1447 #[derive(Diagnostic)]
1448 #[diag(passes_duplicate_feature_err, code = "E0636")]
1449 pub struct DuplicateFeatureErr {
1452 pub feature: Symbol,
1454 #[derive(Diagnostic)]
1455 #[diag(passes_missing_const_err)]
1456 pub struct MissingConstErr {
1459 pub fn_sig_span: Span,
1461 pub const_span: Span,
1464 #[derive(LintDiagnostic)]
1465 pub enum MultipleDeadCodes<'tcx> {
1466 #[diag(passes_dead_codes)]
1471 participle: &'tcx str,
1472 name_list: DiagnosticSymbolList,
1474 parent_info: Option<ParentInfo<'tcx>>,
1476 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1478 #[diag(passes_dead_codes)]
1479 UnusedTupleStructFields {
1483 participle: &'tcx str,
1484 name_list: DiagnosticSymbolList,
1486 change_fields_suggestion: ChangeFieldsToBeOfUnitType,
1488 parent_info: Option<ParentInfo<'tcx>>,
1490 ignored_derived_impls: Option<IgnoredDerivedImpls>,
1494 #[derive(Subdiagnostic)]
1495 #[label(passes_parent_info)]
1496 pub struct ParentInfo<'tcx> {
1498 pub descr: &'tcx str,
1499 pub parent_descr: &'tcx str,
1504 #[derive(Subdiagnostic)]
1505 #[note(passes_ignored_derived_impls)]
1506 pub struct IgnoredDerivedImpls {
1508 pub trait_list: DiagnosticSymbolList,
1509 pub trait_list_len: usize,
1512 #[derive(Subdiagnostic)]
1513 #[multipart_suggestion(passes_change_fields_to_be_of_unit_type, applicability = "has-placeholders")]
1514 pub struct ChangeFieldsToBeOfUnitType {
1516 #[suggestion_part(code = "()")]
1517 pub spans: Vec<Span>,
1520 #[derive(Diagnostic)]
1521 #[diag(passes_proc_macro_typeerror)]
1523 pub(crate) struct ProcMacroTypeError<'tcx> {
1527 pub found: Ty<'tcx>,
1528 pub kind: ProcMacroKind,
1529 pub expected_signature: &'static str,
1532 #[derive(Diagnostic)]
1533 #[diag(passes_proc_macro_diff_arg_count)]
1534 pub(crate) struct ProcMacroDiffArguments {
1539 pub kind: ProcMacroKind,
1540 pub expected_signature: &'static str,
1543 #[derive(Diagnostic)]
1544 #[diag(passes_proc_macro_missing_args)]
1545 pub(crate) struct ProcMacroMissingArguments {
1549 pub expected_input_count: usize,
1550 pub kind: ProcMacroKind,
1551 pub expected_signature: &'static str,
1554 #[derive(Diagnostic)]
1555 #[diag(passes_proc_macro_invalid_abi)]
1556 pub(crate) struct ProcMacroInvalidAbi {
1559 pub abi: &'static str,
1562 #[derive(Diagnostic)]
1563 #[diag(passes_proc_macro_unsafe)]
1564 pub(crate) struct ProcMacroUnsafe {