From 94a0819fe3a0d679c3042a77bfe6a2afc505daea Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:11:28 +0200 Subject: Adding upstream version 1.66.0+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_passes/src/errors.rs | 1120 ++++++++++++++++++++++++++++++----- 1 file changed, 963 insertions(+), 157 deletions(-) (limited to 'compiler/rustc_passes/src/errors.rs') diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 5feb0e295..adaaf5392 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -1,39 +1,49 @@ -use rustc_errors::{Applicability, MultiSpan}; -use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic}; -use rustc_span::{Span, Symbol}; +use std::{ + io::Error, + path::{Path, PathBuf}, +}; + +use rustc_ast::Label; +use rustc_errors::{error_code, Applicability, ErrorGuaranteed, IntoDiagnostic, MultiSpan}; +use rustc_hir::{self as hir, ExprKind, Target}; +use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; +use rustc_middle::ty::{MainDefinition, Ty}; +use rustc_span::{Span, Symbol, DUMMY_SP}; + +use crate::lang_items::Duplicate; #[derive(LintDiagnostic)] -#[lint(passes::outer_crate_level_attr)] +#[diag(passes_outer_crate_level_attr)] pub struct OuterCrateLevelAttr; #[derive(LintDiagnostic)] -#[lint(passes::inner_crate_level_attr)] +#[diag(passes_inner_crate_level_attr)] pub struct InnerCrateLevelAttr; #[derive(LintDiagnostic)] -#[lint(passes::ignored_attr_with_macro)] +#[diag(passes_ignored_attr_with_macro)] pub struct IgnoredAttrWithMacro<'a> { pub sym: &'a str, } #[derive(LintDiagnostic)] -#[lint(passes::ignored_attr)] +#[diag(passes_ignored_attr)] pub struct IgnoredAttr<'a> { pub sym: &'a str, } #[derive(LintDiagnostic)] -#[lint(passes::inline_ignored_function_prototype)] +#[diag(passes_inline_ignored_function_prototype)] pub struct IgnoredInlineAttrFnProto; #[derive(LintDiagnostic)] -#[lint(passes::inline_ignored_constants)] -#[warn_] +#[diag(passes_inline_ignored_constants)] +#[warning] #[note] pub struct IgnoredInlineAttrConstants; -#[derive(SessionDiagnostic)] -#[error(passes::inline_not_fn_or_closure, code = "E0518")] +#[derive(Diagnostic)] +#[diag(passes_inline_not_fn_or_closure, code = "E0518")] pub struct InlineNotFnOrClosure { #[primary_span] pub attr_span: Span, @@ -42,19 +52,19 @@ pub struct InlineNotFnOrClosure { } #[derive(LintDiagnostic)] -#[lint(passes::no_coverage_ignored_function_prototype)] +#[diag(passes_no_coverage_ignored_function_prototype)] pub struct IgnoredNoCoverageFnProto; #[derive(LintDiagnostic)] -#[lint(passes::no_coverage_propagate)] +#[diag(passes_no_coverage_propagate)] pub struct IgnoredNoCoveragePropagate; #[derive(LintDiagnostic)] -#[lint(passes::no_coverage_fn_defn)] +#[diag(passes_no_coverage_fn_defn)] pub struct IgnoredNoCoverageFnDefn; -#[derive(SessionDiagnostic)] -#[error(passes::no_coverage_not_coverable, code = "E0788")] +#[derive(Diagnostic)] +#[diag(passes_no_coverage_not_coverable, code = "E0788")] pub struct IgnoredNoCoverageNotCoverable { #[primary_span] pub attr_span: Span, @@ -62,8 +72,8 @@ pub struct IgnoredNoCoverageNotCoverable { pub defn_span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::should_be_applied_to_fn)] +#[derive(Diagnostic)] +#[diag(passes_should_be_applied_to_fn)] pub struct AttrShouldBeAppliedToFn { #[primary_span] pub attr_span: Span, @@ -71,15 +81,15 @@ pub struct AttrShouldBeAppliedToFn { pub defn_span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::naked_tracked_caller, code = "E0736")] +#[derive(Diagnostic)] +#[diag(passes_naked_tracked_caller, code = "E0736")] pub struct NakedTrackedCaller { #[primary_span] pub attr_span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::should_be_applied_to_fn, code = "E0739")] +#[derive(Diagnostic)] +#[diag(passes_should_be_applied_to_fn, code = "E0739")] pub struct TrackedCallerWrongLocation { #[primary_span] pub attr_span: Span, @@ -87,8 +97,8 @@ pub struct TrackedCallerWrongLocation { pub defn_span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::should_be_applied_to_struct_enum, code = "E0701")] +#[derive(Diagnostic)] +#[diag(passes_should_be_applied_to_struct_enum, code = "E0701")] pub struct NonExhaustiveWrongLocation { #[primary_span] pub attr_span: Span, @@ -96,8 +106,8 @@ pub struct NonExhaustiveWrongLocation { pub defn_span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::should_be_applied_to_trait)] +#[derive(Diagnostic)] +#[diag(passes_should_be_applied_to_trait)] pub struct AttrShouldBeAppliedToTrait { #[primary_span] pub attr_span: Span, @@ -106,11 +116,11 @@ pub struct AttrShouldBeAppliedToTrait { } #[derive(LintDiagnostic)] -#[lint(passes::target_feature_on_statement)] +#[diag(passes_target_feature_on_statement)] pub struct TargetFeatureOnStatement; -#[derive(SessionDiagnostic)] -#[error(passes::should_be_applied_to_static)] +#[derive(Diagnostic)] +#[diag(passes_should_be_applied_to_static)] pub struct AttrShouldBeAppliedToStatic { #[primary_span] pub attr_span: Span, @@ -118,24 +128,24 @@ pub struct AttrShouldBeAppliedToStatic { pub defn_span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::doc_expect_str)] +#[derive(Diagnostic)] +#[diag(passes_doc_expect_str)] pub struct DocExpectStr<'a> { #[primary_span] pub attr_span: Span, pub attr_name: &'a str, } -#[derive(SessionDiagnostic)] -#[error(passes::doc_alias_empty)] +#[derive(Diagnostic)] +#[diag(passes_doc_alias_empty)] pub struct DocAliasEmpty<'a> { #[primary_span] pub span: Span, pub attr_str: &'a str, } -#[derive(SessionDiagnostic)] -#[error(passes::doc_alias_bad_char)] +#[derive(Diagnostic)] +#[diag(passes_doc_alias_bad_char)] pub struct DocAliasBadChar<'a> { #[primary_span] pub span: Span, @@ -143,16 +153,16 @@ pub struct DocAliasBadChar<'a> { pub char_: char, } -#[derive(SessionDiagnostic)] -#[error(passes::doc_alias_start_end)] +#[derive(Diagnostic)] +#[diag(passes_doc_alias_start_end)] pub struct DocAliasStartEnd<'a> { #[primary_span] pub span: Span, pub attr_str: &'a str, } -#[derive(SessionDiagnostic)] -#[error(passes::doc_alias_bad_location)] +#[derive(Diagnostic)] +#[diag(passes_doc_alias_bad_location)] pub struct DocAliasBadLocation<'a> { #[primary_span] pub span: Span, @@ -160,8 +170,8 @@ pub struct DocAliasBadLocation<'a> { pub location: &'a str, } -#[derive(SessionDiagnostic)] -#[error(passes::doc_alias_not_an_alias)] +#[derive(Diagnostic)] +#[diag(passes_doc_alias_not_an_alias)] pub struct DocAliasNotAnAlias<'a> { #[primary_span] pub span: Span, @@ -169,64 +179,64 @@ pub struct DocAliasNotAnAlias<'a> { } #[derive(LintDiagnostic)] -#[lint(passes::doc_alias_duplicated)] +#[diag(passes_doc_alias_duplicated)] pub struct DocAliasDuplicated { #[label] pub first_defn: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::doc_alias_not_string_literal)] +#[derive(Diagnostic)] +#[diag(passes_doc_alias_not_string_literal)] pub struct DocAliasNotStringLiteral { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::doc_alias_malformed)] +#[derive(Diagnostic)] +#[diag(passes_doc_alias_malformed)] pub struct DocAliasMalformed { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::doc_keyword_empty_mod)] +#[derive(Diagnostic)] +#[diag(passes_doc_keyword_empty_mod)] pub struct DocKeywordEmptyMod { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::doc_keyword_not_mod)] +#[derive(Diagnostic)] +#[diag(passes_doc_keyword_not_mod)] pub struct DocKeywordNotMod { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::doc_keyword_invalid_ident)] +#[derive(Diagnostic)] +#[diag(passes_doc_keyword_invalid_ident)] pub struct DocKeywordInvalidIdent { #[primary_span] pub span: Span, pub doc_keyword: Symbol, } -#[derive(SessionDiagnostic)] -#[error(passes::doc_fake_variadic_not_valid)] +#[derive(Diagnostic)] +#[diag(passes_doc_fake_variadic_not_valid)] pub struct DocFakeVariadicNotValid { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::doc_keyword_only_impl)] +#[derive(Diagnostic)] +#[diag(passes_doc_keyword_only_impl)] pub struct DocKeywordOnlyImpl { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::doc_inline_conflict)] +#[derive(Diagnostic)] +#[diag(passes_doc_inline_conflict)] #[help] pub struct DocKeywordConflict { #[primary_span] @@ -234,17 +244,17 @@ pub struct DocKeywordConflict { } #[derive(LintDiagnostic)] -#[lint(passes::doc_inline_only_use)] +#[diag(passes_doc_inline_only_use)] #[note] pub struct DocInlineOnlyUse { #[label] pub attr_span: Span, - #[label(passes::not_a_use_item_label)] + #[label(not_a_use_item_label)] pub item_span: Option, } -#[derive(SessionDiagnostic)] -#[error(passes::doc_attr_not_crate_level)] +#[derive(Diagnostic)] +#[diag(passes_doc_attr_not_crate_level)] pub struct DocAttrNotCrateLevel<'a> { #[primary_span] pub span: Span, @@ -252,29 +262,33 @@ pub struct DocAttrNotCrateLevel<'a> { } #[derive(LintDiagnostic)] -#[lint(passes::doc_test_unknown)] +#[diag(passes_doc_test_unknown)] pub struct DocTestUnknown { pub path: String, } #[derive(LintDiagnostic)] -#[lint(passes::doc_test_takes_list)] +#[diag(passes_doc_test_takes_list)] pub struct DocTestTakesList; #[derive(LintDiagnostic)] -#[lint(passes::doc_primitive)] +#[diag(passes_doc_cfg_hide_takes_list)] +pub struct DocCfgHideTakesList; + +#[derive(LintDiagnostic)] +#[diag(passes_doc_primitive)] pub struct DocPrimitive; #[derive(LintDiagnostic)] -#[lint(passes::doc_test_unknown_any)] +#[diag(passes_doc_test_unknown_any)] pub struct DocTestUnknownAny { pub path: String, } #[derive(LintDiagnostic)] -#[lint(passes::doc_test_unknown_spotlight)] +#[diag(passes_doc_test_unknown_spotlight)] #[note] -#[note(passes::no_op_note)] +#[note(no_op_note)] pub struct DocTestUnknownSpotlight { pub path: String, #[suggestion_short(applicability = "machine-applicable", code = "notable_trait")] @@ -282,7 +296,7 @@ pub struct DocTestUnknownSpotlight { } #[derive(LintDiagnostic)] -#[lint(passes::doc_test_unknown_include)] +#[diag(passes_doc_test_unknown_include)] pub struct DocTestUnknownInclude { pub path: String, pub value: String, @@ -292,11 +306,11 @@ pub struct DocTestUnknownInclude { } #[derive(LintDiagnostic)] -#[lint(passes::doc_invalid)] +#[diag(passes_doc_invalid)] pub struct DocInvalid; -#[derive(SessionDiagnostic)] -#[error(passes::pass_by_value)] +#[derive(Diagnostic)] +#[diag(passes_pass_by_value)] pub struct PassByValue { #[primary_span] pub attr_span: Span, @@ -304,8 +318,8 @@ pub struct PassByValue { pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::allow_incoherent_impl)] +#[derive(Diagnostic)] +#[diag(passes_allow_incoherent_impl)] pub struct AllowIncoherentImpl { #[primary_span] pub attr_span: Span, @@ -313,8 +327,8 @@ pub struct AllowIncoherentImpl { pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::has_incoherent_inherent_impl)] +#[derive(Diagnostic)] +#[diag(passes_has_incoherent_inherent_impl)] pub struct HasIncoherentInherentImpl { #[primary_span] pub attr_span: Span, @@ -323,21 +337,21 @@ pub struct HasIncoherentInherentImpl { } #[derive(LintDiagnostic)] -#[lint(passes::must_use_async)] +#[diag(passes_must_use_async)] pub struct MustUseAsync { #[label] pub span: Span, } #[derive(LintDiagnostic)] -#[lint(passes::must_use_no_effect)] +#[diag(passes_must_use_no_effect)] pub struct MustUseNoEffect { pub article: &'static str, pub target: rustc_hir::Target, } -#[derive(SessionDiagnostic)] -#[error(passes::must_not_suspend)] +#[derive(Diagnostic)] +#[diag(passes_must_not_suspend)] pub struct MustNotSuspend { #[primary_span] pub attr_span: Span, @@ -346,24 +360,24 @@ pub struct MustNotSuspend { } #[derive(LintDiagnostic)] -#[lint(passes::cold)] -#[warn_] +#[diag(passes_cold)] +#[warning] pub struct Cold { #[label] pub span: Span, } #[derive(LintDiagnostic)] -#[lint(passes::link)] -#[warn_] +#[diag(passes_link)] +#[warning] pub struct Link { #[label] pub span: Option, } #[derive(LintDiagnostic)] -#[lint(passes::link_name)] -#[warn_] +#[diag(passes_link_name)] +#[warning] pub struct LinkName<'a> { #[help] pub attr_span: Option, @@ -372,8 +386,8 @@ pub struct LinkName<'a> { pub value: &'a str, } -#[derive(SessionDiagnostic)] -#[error(passes::no_link)] +#[derive(Diagnostic)] +#[diag(passes_no_link)] pub struct NoLink { #[primary_span] pub attr_span: Span, @@ -381,8 +395,8 @@ pub struct NoLink { pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::export_name)] +#[derive(Diagnostic)] +#[diag(passes_export_name)] pub struct ExportName { #[primary_span] pub attr_span: Span, @@ -390,8 +404,8 @@ pub struct ExportName { pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::rustc_layout_scalar_valid_range_not_struct)] +#[derive(Diagnostic)] +#[diag(passes_rustc_layout_scalar_valid_range_not_struct)] pub struct RustcLayoutScalarValidRangeNotStruct { #[primary_span] pub attr_span: Span, @@ -399,15 +413,15 @@ pub struct RustcLayoutScalarValidRangeNotStruct { pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::rustc_layout_scalar_valid_range_arg)] +#[derive(Diagnostic)] +#[diag(passes_rustc_layout_scalar_valid_range_arg)] pub struct RustcLayoutScalarValidRangeArg { #[primary_span] pub attr_span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::rustc_legacy_const_generics_only)] +#[derive(Diagnostic)] +#[diag(passes_rustc_legacy_const_generics_only)] pub struct RustcLegacyConstGenericsOnly { #[primary_span] pub attr_span: Span, @@ -415,8 +429,8 @@ pub struct RustcLegacyConstGenericsOnly { pub param_span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::rustc_legacy_const_generics_index)] +#[derive(Diagnostic)] +#[diag(passes_rustc_legacy_const_generics_index)] pub struct RustcLegacyConstGenericsIndex { #[primary_span] pub attr_span: Span, @@ -424,8 +438,8 @@ pub struct RustcLegacyConstGenericsIndex { pub generics_span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::rustc_legacy_const_generics_index_exceed)] +#[derive(Diagnostic)] +#[diag(passes_rustc_legacy_const_generics_index_exceed)] pub struct RustcLegacyConstGenericsIndexExceed { #[primary_span] #[label] @@ -433,75 +447,75 @@ pub struct RustcLegacyConstGenericsIndexExceed { pub arg_count: usize, } -#[derive(SessionDiagnostic)] -#[error(passes::rustc_legacy_const_generics_index_negative)] +#[derive(Diagnostic)] +#[diag(passes_rustc_legacy_const_generics_index_negative)] pub struct RustcLegacyConstGenericsIndexNegative { #[primary_span] pub invalid_args: Vec, } -#[derive(SessionDiagnostic)] -#[error(passes::rustc_dirty_clean)] +#[derive(Diagnostic)] +#[diag(passes_rustc_dirty_clean)] pub struct RustcDirtyClean { #[primary_span] pub span: Span, } #[derive(LintDiagnostic)] -#[lint(passes::link_section)] -#[warn_] +#[diag(passes_link_section)] +#[warning] pub struct LinkSection { #[label] pub span: Span, } #[derive(LintDiagnostic)] -#[lint(passes::no_mangle_foreign)] -#[warn_] +#[diag(passes_no_mangle_foreign)] +#[warning] #[note] pub struct NoMangleForeign { #[label] pub span: Span, - #[suggestion(applicability = "machine-applicable")] + #[suggestion(code = "", applicability = "machine-applicable")] pub attr_span: Span, pub foreign_item_kind: &'static str, } #[derive(LintDiagnostic)] -#[lint(passes::no_mangle)] -#[warn_] +#[diag(passes_no_mangle)] +#[warning] pub struct NoMangle { #[label] pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::repr_ident, code = "E0565")] +#[derive(Diagnostic)] +#[diag(passes_repr_ident, code = "E0565")] pub struct ReprIdent { #[primary_span] pub span: Span, } #[derive(LintDiagnostic)] -#[lint(passes::repr_conflicting, code = "E0566")] +#[diag(passes_repr_conflicting, code = "E0566")] pub struct ReprConflicting; -#[derive(SessionDiagnostic)] -#[error(passes::used_static)] +#[derive(Diagnostic)] +#[diag(passes_used_static)] pub struct UsedStatic { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::used_compiler_linker)] +#[derive(Diagnostic)] +#[diag(passes_used_compiler_linker)] pub struct UsedCompilerLinker { #[primary_span] pub spans: Vec, } -#[derive(SessionDiagnostic)] -#[error(passes::allow_internal_unstable)] +#[derive(Diagnostic)] +#[diag(passes_allow_internal_unstable)] pub struct AllowInternalUnstable { #[primary_span] pub attr_span: Span, @@ -509,25 +523,34 @@ pub struct AllowInternalUnstable { pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::debug_visualizer_placement)] +#[derive(Diagnostic)] +#[diag(passes_debug_visualizer_placement)] pub struct DebugVisualizerPlacement { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::debug_visualizer_invalid)] -#[note(passes::note_1)] -#[note(passes::note_2)] -#[note(passes::note_3)] +#[derive(Diagnostic)] +#[diag(passes_debug_visualizer_invalid)] +#[note(note_1)] +#[note(note_2)] +#[note(note_3)] pub struct DebugVisualizerInvalid { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::rustc_allow_const_fn_unstable)] +#[derive(Diagnostic)] +#[diag(passes_debug_visualizer_unreadable)] +pub struct DebugVisualizerUnreadable<'a> { + #[primary_span] + pub span: Span, + pub file: &'a Path, + pub error: Error, +} + +#[derive(Diagnostic)] +#[diag(passes_rustc_allow_const_fn_unstable)] pub struct RustcAllowConstFnUnstable { #[primary_span] pub attr_span: Span, @@ -535,8 +558,8 @@ pub struct RustcAllowConstFnUnstable { pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::rustc_std_internal_symbol)] +#[derive(Diagnostic)] +#[diag(passes_rustc_std_internal_symbol)] pub struct RustcStdInternalSymbol { #[primary_span] pub attr_span: Span, @@ -544,59 +567,66 @@ pub struct RustcStdInternalSymbol { pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::const_trait)] +#[derive(Diagnostic)] +#[diag(passes_const_trait)] pub struct ConstTrait { #[primary_span] pub attr_span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::stability_promotable)] +#[derive(Diagnostic)] +#[diag(passes_link_ordinal)] +pub struct LinkOrdinal { + #[primary_span] + pub attr_span: Span, +} + +#[derive(Diagnostic)] +#[diag(passes_stability_promotable)] pub struct StabilityPromotable { #[primary_span] pub attr_span: Span, } #[derive(LintDiagnostic)] -#[lint(passes::deprecated)] +#[diag(passes_deprecated)] pub struct Deprecated; #[derive(LintDiagnostic)] -#[lint(passes::macro_use)] +#[diag(passes_macro_use)] pub struct MacroUse { pub name: Symbol, } #[derive(LintDiagnostic)] -#[lint(passes::macro_export)] +#[diag(passes_macro_export)] pub struct MacroExport; #[derive(LintDiagnostic)] -#[lint(passes::plugin_registrar)] +#[diag(passes_plugin_registrar)] pub struct PluginRegistrar; -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum UnusedNote { - #[note(passes::unused_empty_lints_note)] + #[note(passes_unused_empty_lints_note)] EmptyList { name: Symbol }, - #[note(passes::unused_no_lints_note)] + #[note(passes_unused_no_lints_note)] NoLints { name: Symbol }, - #[note(passes::unused_default_method_body_const_note)] + #[note(passes_unused_default_method_body_const_note)] DefaultMethodBodyConst, } #[derive(LintDiagnostic)] -#[lint(passes::unused)] +#[diag(passes_unused)] pub struct Unused { - #[suggestion(applicability = "machine-applicable")] + #[suggestion(code = "", applicability = "machine-applicable")] pub attr_span: Span, #[subdiagnostic] pub note: UnusedNote, } -#[derive(SessionDiagnostic)] -#[error(passes::non_exported_macro_invalid_attrs, code = "E0518")] +#[derive(Diagnostic)] +#[diag(passes_non_exported_macro_invalid_attrs, code = "E0518")] pub struct NonExportedMacroInvalidAttrs { #[primary_span] #[label] @@ -604,19 +634,18 @@ pub struct NonExportedMacroInvalidAttrs { } #[derive(LintDiagnostic)] -#[lint(passes::unused_duplicate)] +#[diag(passes_unused_duplicate)] pub struct UnusedDuplicate { - #[primary_span] #[suggestion(code = "", applicability = "machine-applicable")] pub this: Span, #[note] pub other: Span, - #[warn_] + #[warning] pub warning: Option<()>, } -#[derive(SessionDiagnostic)] -#[error(passes::unused_multiple)] +#[derive(Diagnostic)] +#[diag(passes_unused_multiple)] pub struct UnusedMultiple { #[primary_span] #[suggestion(code = "", applicability = "machine-applicable")] @@ -626,8 +655,8 @@ pub struct UnusedMultiple { pub name: Symbol, } -#[derive(SessionDiagnostic)] -#[error(passes::rustc_lint_opt_ty)] +#[derive(Diagnostic)] +#[diag(passes_rustc_lint_opt_ty)] pub struct RustcLintOptTy { #[primary_span] pub attr_span: Span, @@ -635,11 +664,788 @@ pub struct RustcLintOptTy { pub span: Span, } -#[derive(SessionDiagnostic)] -#[error(passes::rustc_lint_opt_deny_field_access)] +#[derive(Diagnostic)] +#[diag(passes_rustc_lint_opt_deny_field_access)] pub struct RustcLintOptDenyFieldAccess { #[primary_span] pub attr_span: Span, #[label] pub span: Span, } + +#[derive(Diagnostic)] +#[diag(passes_collapse_debuginfo)] +pub struct CollapseDebuginfo { + #[primary_span] + pub attr_span: Span, + #[label] + pub defn_span: Span, +} + +#[derive(LintDiagnostic)] +#[diag(passes_deprecated_annotation_has_no_effect)] +pub struct DeprecatedAnnotationHasNoEffect { + #[suggestion(applicability = "machine-applicable", code = "")] + pub span: Span, +} + +#[derive(Diagnostic)] +#[diag(passes_unknown_external_lang_item, code = "E0264")] +pub struct UnknownExternLangItem { + #[primary_span] + pub span: Span, + pub lang_item: Symbol, +} + +#[derive(Diagnostic)] +#[diag(passes_missing_panic_handler)] +pub struct MissingPanicHandler; + +#[derive(Diagnostic)] +#[diag(passes_alloc_func_required)] +pub struct AllocFuncRequired; + +#[derive(Diagnostic)] +#[diag(passes_missing_alloc_error_handler)] +pub struct MissingAllocErrorHandler; + +#[derive(Diagnostic)] +#[diag(passes_missing_lang_item)] +#[note] +#[help] +pub struct MissingLangItem { + pub name: Symbol, +} + +#[derive(Diagnostic)] +#[diag(passes_lang_item_on_incorrect_target, code = "E0718")] +pub struct LangItemOnIncorrectTarget { + #[primary_span] + #[label] + pub span: Span, + pub name: Symbol, + pub expected_target: Target, + pub actual_target: Target, +} + +#[derive(Diagnostic)] +#[diag(passes_unknown_lang_item, code = "E0522")] +pub struct UnknownLangItem { + #[primary_span] + #[label] + pub span: Span, + pub name: Symbol, +} + +pub struct InvalidAttrAtCrateLevel { + pub span: Span, + pub snippet: Option, + pub name: Symbol, +} + +impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel { + fn into_diagnostic( + self, + handler: &'_ rustc_errors::Handler, + ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { + let mut diag = handler.struct_err(rustc_errors::fluent::passes_invalid_attr_at_crate_level); + diag.set_span(self.span); + diag.set_arg("name", self.name); + // Only emit an error with a suggestion if we can create a string out + // of the attribute span + if let Some(src) = self.snippet { + let replacement = src.replace("#!", "#"); + diag.span_suggestion_verbose( + self.span, + rustc_errors::fluent::suggestion, + replacement, + rustc_errors::Applicability::MachineApplicable, + ); + } + diag + } +} + +#[derive(Diagnostic)] +#[diag(passes_duplicate_diagnostic_item)] +pub struct DuplicateDiagnosticItem { + #[primary_span] + pub span: Span, + pub name: Symbol, +} + +#[derive(Diagnostic)] +#[diag(passes_duplicate_diagnostic_item_in_crate)] +pub struct DuplicateDiagnosticItemInCrate { + #[note(passes_diagnostic_item_first_defined)] + pub span: Option, + pub orig_crate_name: Symbol, + #[note] + pub have_orig_crate_name: Option<()>, + pub crate_name: Symbol, + pub name: Symbol, +} + +#[derive(Diagnostic)] +#[diag(passes_abi)] +pub struct Abi { + #[primary_span] + pub span: Span, + pub abi: String, +} + +#[derive(Diagnostic)] +#[diag(passes_align)] +pub struct Align { + #[primary_span] + pub span: Span, + pub align: String, +} + +#[derive(Diagnostic)] +#[diag(passes_size)] +pub struct Size { + #[primary_span] + pub span: Span, + pub size: String, +} + +#[derive(Diagnostic)] +#[diag(passes_homogeneous_aggregate)] +pub struct HomogeneousAggregate { + #[primary_span] + pub span: Span, + pub homogeneous_aggregate: String, +} + +#[derive(Diagnostic)] +#[diag(passes_layout_of)] +pub struct LayoutOf { + #[primary_span] + pub span: Span, + pub normalized_ty: String, + pub ty_layout: String, +} + +#[derive(Diagnostic)] +#[diag(passes_unrecognized_field)] +pub struct UnrecognizedField { + #[primary_span] + pub span: Span, + pub name: Symbol, +} + +#[derive(Diagnostic)] +#[diag(passes_feature_stable_twice, code = "E0711")] +pub struct FeatureStableTwice { + #[primary_span] + pub span: Span, + pub feature: Symbol, + pub since: Symbol, + pub prev_since: Symbol, +} + +#[derive(Diagnostic)] +#[diag(passes_feature_previously_declared, code = "E0711")] +pub struct FeaturePreviouslyDeclared<'a, 'b> { + #[primary_span] + pub span: Span, + pub feature: Symbol, + pub declared: &'a str, + pub prev_declared: &'b str, +} + +#[derive(Diagnostic)] +#[diag(passes_expr_not_allowed_in_context, code = "E0744")] +pub struct ExprNotAllowedInContext<'a> { + #[primary_span] + pub span: Span, + pub expr: String, + pub context: &'a str, +} + +pub struct BreakNonLoop<'a> { + pub span: Span, + pub head: Option, + pub kind: &'a str, + pub suggestion: String, + pub loop_label: Option