diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index 052979d6d456..1ad5fa21d853 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -335,7 +335,7 @@ pub struct InclusiveRangeWithNoEnd { pub span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::trait_fn_async, code = "E0706")] #[note] #[note(ast_lowering::note2)] diff --git a/compiler/rustc_attr/src/session_diagnostics.rs b/compiler/rustc_attr/src/session_diagnostics.rs index 940a48ed915d..d3e9a16a9a80 100644 --- a/compiler/rustc_attr/src/session_diagnostics.rs +++ b/compiler/rustc_attr/src/session_diagnostics.rs @@ -2,8 +2,7 @@ use rustc_ast as ast; use rustc_errors::{ - error_code, fluent, Applicability, DiagnosticBuilder, IntoDiagnostic, ErrorGuaranteed, - Handler, + error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, }; use rustc_macros::Diagnostic; use rustc_span::{Span, Symbol}; diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index c66889189add..a52e95e92d55 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -178,7 +178,7 @@ fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { /// Trait implemented by error types. This should not be implemented manually. Instead, use /// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic]. #[cfg_attr(bootstrap, rustc_diagnostic_item = "AddSubdiagnostic")] -#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "Subdiagnostic")] +#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "AddToDiagnostic")] pub trait AddToDiagnostic { /// Add a subdiagnostic to an existing diagnostic. fn add_to_diagnostic(self, diag: &mut Diagnostic); diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index f9b46053486b..b4ba65ca96d3 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -16,7 +16,7 @@ /// Trait implemented by error types. This should not be implemented manually. Instead, use /// `#[derive(Diagnostic)]` -- see [rustc_macros::Diagnostic]. #[cfg_attr(bootstrap, rustc_diagnostic_item = "SessionDiagnostic")] -#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "Diagnostic")] +#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "IntoDiagnostic")] pub trait IntoDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> { /// Write out as a diagnostic out of `Handler`. #[must_use] diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 19cae2c90775..68971cebc352 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -437,11 +437,11 @@ struct HandlerInner { /// have been converted. check_unstable_expect_diagnostics: bool, - /// Expected [`Diagnostic`]s store a [`LintExpectationId`] as part of + /// Expected [`Diagnostic`][diagnostic::Diagnostic]s store a [`LintExpectationId`] as part of /// the lint level. [`LintExpectationId`]s created early during the compilation /// (before `HirId`s have been defined) are not stable and can therefore not be /// stored on disk. This buffer stores these diagnostics until the ID has been - /// replaced by a stable [`LintExpectationId`]. The [`Diagnostic`]s are the + /// replaced by a stable [`LintExpectationId`]. The [`Diagnostic`][diagnostic::Diagnostic]s are the /// submitted for storage and added to the list of fulfilled expectations. unstable_expect_diagnostics: Vec, @@ -647,8 +647,6 @@ pub fn emit_stashed_diagnostics(&self) -> Option { /// Construct a builder with the `msg` at the level appropriate for the specific `EmissionGuarantee`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_diagnostic( &self, msg: impl Into, @@ -662,8 +660,6 @@ pub fn struct_diagnostic( /// * `can_emit_warnings` is `true` /// * `is_force_warn` was set in `DiagnosticId::Lint` #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_warn( &self, span: impl Into, @@ -680,8 +676,6 @@ pub fn struct_span_warn( /// Attempting to `.emit()` the builder will only emit if either: /// * `can_emit_warnings` is `true` /// * `is_force_warn` was set in `DiagnosticId::Lint` - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_warn_with_expectation( &self, span: impl Into, @@ -695,8 +689,6 @@ pub fn struct_span_warn_with_expectation( /// Construct a builder at the `Allow` level at the given `span` and with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_allow( &self, span: impl Into, @@ -710,8 +702,6 @@ pub fn struct_span_allow( /// Construct a builder at the `Warning` level at the given `span` and with the `msg`. /// Also include a code. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_warn_with_code( &self, span: impl Into, @@ -729,8 +719,6 @@ pub fn struct_span_warn_with_code( /// * `can_emit_warnings` is `true` /// * `is_force_warn` was set in `DiagnosticId::Lint` #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_warn(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { DiagnosticBuilder::new(self, Level::Warning(None), msg) } @@ -741,8 +729,6 @@ pub fn struct_warn(&self, msg: impl Into) -> DiagnosticBuilde /// Attempting to `.emit()` the builder will only emit if either: /// * `can_emit_warnings` is `true` /// * `is_force_warn` was set in `DiagnosticId::Lint` - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_warn_with_expectation( &self, msg: impl Into, @@ -753,16 +739,12 @@ pub fn struct_warn_with_expectation( /// Construct a builder at the `Allow` level with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_allow(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { DiagnosticBuilder::new(self, Level::Allow, msg) } /// Construct a builder at the `Expect` level with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_expect( &self, msg: impl Into, @@ -773,8 +755,6 @@ pub fn struct_expect( /// Construct a builder at the `Error` level at the given `span` and with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_err( &self, span: impl Into, @@ -787,8 +767,6 @@ pub fn struct_span_err( /// Construct a builder at the `Error` level at the given `span`, with the `msg`, and `code`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_err_with_code( &self, span: impl Into, @@ -803,8 +781,6 @@ pub fn struct_span_err_with_code( /// Construct a builder at the `Error` level with the `msg`. // FIXME: This method should be removed (every error should have an associated error code). #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_err( &self, msg: impl Into, @@ -814,16 +790,12 @@ pub fn struct_err( /// This should only be used by `rustc_middle::lint::struct_lint_level`. Do not use it for hard errors. #[doc(hidden)] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_err_lint(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { DiagnosticBuilder::new(self, Level::Error { lint: true }, msg) } /// Construct a builder at the `Error` level with the `msg` and the `code`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_err_with_code( &self, msg: impl Into, @@ -836,8 +808,6 @@ pub fn struct_err_with_code( /// Construct a builder at the `Warn` level with the `msg` and the `code`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_warn_with_code( &self, msg: impl Into, @@ -850,8 +820,6 @@ pub fn struct_warn_with_code( /// Construct a builder at the `Fatal` level at the given `span` and with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_fatal( &self, span: impl Into, @@ -864,8 +832,6 @@ pub fn struct_span_fatal( /// Construct a builder at the `Fatal` level at the given `span`, with the `msg`, and `code`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_fatal_with_code( &self, span: impl Into, @@ -879,24 +845,18 @@ pub fn struct_span_fatal_with_code( /// Construct a builder at the `Error` level with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_fatal(&self, msg: impl Into) -> DiagnosticBuilder<'_, !> { DiagnosticBuilder::new_fatal(self, msg) } /// Construct a builder at the `Help` level with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_help(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { DiagnosticBuilder::new(self, Level::Help, msg) } /// Construct a builder at the `Note` level with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_note_without_error( &self, msg: impl Into, diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index ca429b6adc10..cd8a525e062c 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -11,7 +11,7 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::sync::{self, Lrc}; use rustc_errors::{ - Applicability, DiagnosticBuilder, IntoDiagnostic, ErrorGuaranteed, MultiSpan, PResult, + Applicability, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, MultiSpan, PResult, }; use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT; use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics}; diff --git a/compiler/rustc_infer/src/errors/mod.rs b/compiler/rustc_infer/src/errors/mod.rs index d232a1864624..85b877652c6a 100644 --- a/compiler/rustc_infer/src/errors/mod.rs +++ b/compiler/rustc_infer/src/errors/mod.rs @@ -1,10 +1,10 @@ use hir::GenericParamKind; use rustc_errors::{ - fluent, AddSubdiagnostic, Applicability, DiagnosticMessage, DiagnosticStyledString, MultiSpan, + fluent, AddToDiagnostic, Applicability, DiagnosticMessage, DiagnosticStyledString, MultiSpan, }; use rustc_hir as hir; use rustc_hir::{FnRetTy, Ty}; -use rustc_macros::SessionDiagnostic; +use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_middle::ty::{Region, TyCtxt}; use rustc_span::symbol::kw; use rustc_span::{symbol::Ident, BytePos, Span}; @@ -16,7 +16,7 @@ pub mod note_and_explain; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(infer::opaque_hidden_type)] pub struct OpaqueHiddenTypeDiag { #[primary_span] @@ -28,7 +28,7 @@ pub struct OpaqueHiddenTypeDiag { pub hidden_type: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(infer::type_annotations_needed, code = "E0282")] pub struct AnnotationRequired<'a> { #[primary_span] @@ -46,7 +46,7 @@ pub struct AnnotationRequired<'a> { } // Copy of `AnnotationRequired` for E0283 -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(infer::type_annotations_needed, code = "E0283")] pub struct AmbigousImpl<'a> { #[primary_span] @@ -64,7 +64,7 @@ pub struct AmbigousImpl<'a> { } // Copy of `AnnotationRequired` for E0284 -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(infer::type_annotations_needed, code = "E0284")] pub struct AmbigousReturn<'a> { #[primary_span] @@ -81,7 +81,7 @@ pub struct AmbigousReturn<'a> { pub multi_suggestions: Vec>, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(infer::need_type_info_in_generator, code = "E0698")] pub struct NeedTypeInfoInGenerator<'a> { #[primary_span] @@ -92,7 +92,7 @@ pub struct NeedTypeInfoInGenerator<'a> { } // Used when a better one isn't available -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(infer::label_bad)] pub struct InferenceBadError<'a> { #[primary_span] @@ -106,7 +106,7 @@ pub struct InferenceBadError<'a> { pub name: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum SourceKindSubdiag<'a> { #[suggestion_verbose( infer::source_kind_subdiag_let, @@ -147,7 +147,7 @@ pub enum SourceKindSubdiag<'a> { }, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum SourceKindMultiSuggestion<'a> { #[multipart_suggestion_verbose( infer::source_kind_fully_qualified, @@ -228,7 +228,7 @@ pub enum RegionOriginNote<'a> { }, } -impl AddSubdiagnostic for RegionOriginNote<'_> { +impl AddToDiagnostic for RegionOriginNote<'_> { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { let mut label_or_note = |span, msg: DiagnosticMessage| { let sub_count = diag.children.iter().filter(|d| d.span.is_dummy()).count(); @@ -289,7 +289,7 @@ pub enum LifetimeMismatchLabels { }, } -impl AddSubdiagnostic for LifetimeMismatchLabels { +impl AddToDiagnostic for LifetimeMismatchLabels { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { match self { LifetimeMismatchLabels::InRet { param_span, ret_span, span, label_var1 } => { @@ -339,7 +339,7 @@ pub struct AddLifetimeParamsSuggestion<'a> { pub add_note: bool, } -impl AddSubdiagnostic for AddLifetimeParamsSuggestion<'_> { +impl AddToDiagnostic for AddLifetimeParamsSuggestion<'_> { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { let mut mk_suggestion = || { let ( @@ -422,7 +422,7 @@ fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { } } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(infer::lifetime_mismatch, code = "E0623")] pub struct LifetimeMismatch<'a> { #[primary_span] @@ -438,7 +438,7 @@ pub struct IntroducesStaticBecauseUnmetLifetimeReq { pub binding_span: Span, } -impl AddSubdiagnostic for IntroducesStaticBecauseUnmetLifetimeReq { +impl AddToDiagnostic for IntroducesStaticBecauseUnmetLifetimeReq { fn add_to_diagnostic(mut self, diag: &mut rustc_errors::Diagnostic) { self.unmet_requirements .push_span_label(self.binding_span, fluent::infer::msl_introduces_static); @@ -450,7 +450,7 @@ pub struct ImplNote { pub impl_span: Option, } -impl AddSubdiagnostic for ImplNote { +impl AddToDiagnostic for ImplNote { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { match self.impl_span { Some(span) => diag.span_note(span, fluent::infer::msl_impl_note), @@ -465,7 +465,7 @@ pub enum TraitSubdiag { } // FIXME(#100717) used in `Vec` so requires eager translation/list support -impl AddSubdiagnostic for TraitSubdiag { +impl AddToDiagnostic for TraitSubdiag { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { match self { TraitSubdiag::Note { span } => { @@ -483,7 +483,7 @@ fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { } } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(infer::mismatched_static_lifetime)] pub struct MismatchedStaticLifetime<'a> { #[primary_span] diff --git a/compiler/rustc_infer/src/errors/note_and_explain.rs b/compiler/rustc_infer/src/errors/note_and_explain.rs index 7e051835b4bd..7f54918f7361 100644 --- a/compiler/rustc_infer/src/errors/note_and_explain.rs +++ b/compiler/rustc_infer/src/errors/note_and_explain.rs @@ -1,5 +1,5 @@ use crate::infer::error_reporting::nice_region_error::find_anon_type; -use rustc_errors::{self, fluent, AddSubdiagnostic, IntoDiagnosticArg}; +use rustc_errors::{self, fluent, AddToDiagnostic, IntoDiagnosticArg}; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::{symbol::kw, Span}; @@ -158,7 +158,7 @@ pub fn new<'tcx>( } } -impl AddSubdiagnostic for RegionExplanation<'_> { +impl AddToDiagnostic for RegionExplanation<'_> { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { if let Some(span) = self.desc.span { diag.span_note(span, fluent::infer::region_explanation); diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs index 3a4320a9a8f1..da0271a345e4 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs @@ -11,7 +11,7 @@ use crate::infer::SubregionOrigin; use crate::infer::TyCtxt; -use rustc_errors::AddSubdiagnostic; +use rustc_errors::AddToDiagnostic; use rustc_errors::{Diagnostic, ErrorGuaranteed}; use rustc_hir::Ty; use rustc_middle::ty::Region; diff --git a/compiler/rustc_lint/src/errors.rs b/compiler/rustc_lint/src/errors.rs index 3a89d90c88a6..880f3fbd00e6 100644 --- a/compiler/rustc_lint/src/errors.rs +++ b/compiler/rustc_lint/src/errors.rs @@ -1,4 +1,4 @@ -use rustc_errors::{fluent, AddToDiagnostic, IntoDiagnostic, ErrorGuaranteed, Handler}; +use rustc_errors::{fluent, AddToDiagnostic, ErrorGuaranteed, Handler, IntoDiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_session::lint::Level; use rustc_span::{Span, Symbol}; diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 942475d31fe3..d8a03024d132 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -404,7 +404,7 @@ fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { let Impl { of_trait: Some(of_trait), .. } = impl_ && let Some(def_id) = of_trait.trait_def_id() && let Some(name) = cx.tcx.get_diagnostic_name(def_id) && - matches!(name, sym::Diagnostic | sym::Subdiagnostic | sym::DecorateLint) + matches!(name, sym::IntoDiagnostic | sym::AddToDiagnostic | sym::DecorateLint) { found_impl = true; break; diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic.rs b/compiler/rustc_macros/src/diagnostics/diagnostic.rs index c1aae04fceeb..3b8d9594eb91 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic.rs @@ -9,13 +9,13 @@ use synstructure::Structure; /// The central struct for constructing the `into_diagnostic` method from an annotated struct. -pub(crate) struct SessionDiagnosticDerive<'a> { +pub(crate) struct DiagnosticDerive<'a> { structure: Structure<'a>, handler: syn::Ident, builder: DiagnosticDeriveBuilder, } -impl<'a> SessionDiagnosticDerive<'a> { +impl<'a> DiagnosticDerive<'a> { pub(crate) fn new(diag: syn::Ident, handler: syn::Ident, structure: Structure<'a>) -> Self { Self { builder: DiagnosticDeriveBuilder { @@ -31,7 +31,7 @@ pub(crate) fn new(diag: syn::Ident, handler: syn::Ident, structure: Structure<'a } pub(crate) fn into_tokens(self) -> TokenStream { - let SessionDiagnosticDerive { mut structure, handler, mut builder } = self; + let DiagnosticDerive { mut structure, handler, mut builder } = self; let ast = structure.ast(); let implementation = { diff --git a/compiler/rustc_macros/src/diagnostics/mod.rs b/compiler/rustc_macros/src/diagnostics/mod.rs index 8eaa8b87c0f3..4166816b5e3c 100644 --- a/compiler/rustc_macros/src/diagnostics/mod.rs +++ b/compiler/rustc_macros/src/diagnostics/mod.rs @@ -5,7 +5,7 @@ mod subdiagnostic; mod utils; -use diagnostic::{LintDiagnosticDerive, SessionDiagnosticDerive}; +use diagnostic::{DiagnosticDerive, LintDiagnosticDerive}; pub(crate) use fluent::fluent_messages; use proc_macro2::TokenStream; use quote::format_ident; @@ -59,7 +59,7 @@ /// See rustc dev guide for more examples on using the `#[derive(Diagnostic)]`: /// pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream { - SessionDiagnosticDerive::new(format_ident!("diag"), format_ident!("handler"), s).into_tokens() + DiagnosticDerive::new(format_ident!("diag"), format_ident!("handler"), s).into_tokens() } /// Implements `#[derive(LintDiagnostic)]`, which allows for lints to be specified as a struct, @@ -103,7 +103,7 @@ pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream { /// ``` /// /// See rustc dev guide for more examples on using the `#[derive(LintDiagnostic)]`: -/// +/// pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream { LintDiagnosticDerive::new(format_ident!("diag"), s).into_tokens() } diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index 8ff4eb5fdbc6..1cd550644bf4 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -3,7 +3,7 @@ path::{Path, PathBuf}, }; -use rustc_errors::{error_code, IntoDiagnostic, ErrorGuaranteed}; +use rustc_errors::{error_code, ErrorGuaranteed, IntoDiagnostic}; use rustc_macros::Diagnostic; use rustc_session::config; use rustc_span::{sym, Span, Symbol}; diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 10c5933574ff..2b5b4017a5a1 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -53,6 +53,7 @@ use rustc_serialize::opaque::{FileEncodeResult, FileEncoder}; use rustc_session::config::{CrateType, OutputFilenames}; use rustc_session::cstore::CrateStoreDyn; +use rustc_session::errors::TargetDataLayoutErrorsWrapper; use rustc_session::lint::Lint; use rustc_session::Limit; use rustc_session::Session; @@ -1245,7 +1246,7 @@ pub fn create_global_ctxt( output_filenames: OutputFilenames, ) -> GlobalCtxt<'tcx> { let data_layout = TargetDataLayout::parse(&s.target).unwrap_or_else(|err| { - s.emit_fatal(err); + s.emit_fatal(TargetDataLayoutErrorsWrapper(err)); }); let interners = CtxtInterners::new(arena); let common_types = CommonTypes::new( diff --git a/compiler/rustc_monomorphize/src/errors.rs b/compiler/rustc_monomorphize/src/errors.rs index cdc2c74ac8ff..cf6e18c013be 100644 --- a/compiler/rustc_monomorphize/src/errors.rs +++ b/compiler/rustc_monomorphize/src/errors.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; -use rustc_errors::IntoDiagnostic; use rustc_errors::ErrorGuaranteed; +use rustc_errors::IntoDiagnostic; use rustc_macros::{Diagnostic, LintDiagnostic}; use rustc_span::Span; diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 78bc29fc3758..dcea11eadcbf 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -434,7 +434,7 @@ pub(crate) struct NotAsNegationOperator { pub sub: NotAsNegationOperatorSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum NotAsNegationOperatorSub { #[suggestion_short( parser::unexpected_token_after_not_default, @@ -737,7 +737,7 @@ pub(crate) struct RemoveLet { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::use_eq_instead)] pub(crate) struct UseEqInstead { #[primary_span] diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 52aea9bba432..be67c9e3b82d 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -650,7 +650,7 @@ pub struct RustcLintOptDenyFieldAccess { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(passes::collapse_debuginfo)] pub struct CollapseDebuginfo { #[primary_span] diff --git a/compiler/rustc_query_system/src/error.rs b/compiler/rustc_query_system/src/error.rs index ceec75fce28f..8602a4cf5aef 100644 --- a/compiler/rustc_query_system/src/error.rs +++ b/compiler/rustc_query_system/src/error.rs @@ -1,7 +1,7 @@ use rustc_errors::AddToDiagnostic; +use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_session::Limit; use rustc_span::{Span, Symbol}; -use rustc_macros::{Diagnostic, Subdiagnostic}; pub struct CycleStack { pub span: Span, diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index 6d26c8f47f3c..64aba4703ca3 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -4,7 +4,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_errors::{ - Diagnostic, DiagnosticBuilder, IntoDiagnostic, ErrorGuaranteed, Handler, Level, + Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, Level, }; use rustc_hir::def::DefKind; use rustc_session::Session; diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 8bb3878fbbb4..57c9a3f4822d 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -3,6 +3,7 @@ pub use crate::options::*; +use crate::errors::TargetDataLayoutErrorsWrapper; use crate::search_paths::SearchPath; use crate::utils::{CanonicalizedPath, NativeLib, NativeLibKind}; use crate::{early_error, early_warn, Session}; @@ -898,7 +899,7 @@ fn default_configuration(sess: &Session) -> CrateConfig { let max_atomic_width = sess.target.max_atomic_width(); let atomic_cas = sess.target.atomic_cas; let layout = TargetDataLayout::parse(&sess.target).unwrap_or_else(|err| { - sess.emit_fatal(err); + sess.emit_fatal(TargetDataLayoutErrorsWrapper(err)); }); let mut ret = CrateConfig::default(); diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index 997a45272bca..e01dafe2102b 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -1,9 +1,10 @@ use std::num::NonZeroU32; use crate::cgu_reuse_tracker::CguReuse; -use crate::{self as rustc_session, SessionDiagnostic}; -use rustc_errors::{fluent, DiagnosticBuilder, ErrorGuaranteed, Handler, MultiSpan}; -use rustc_macros::SessionDiagnostic; +use rustc_errors::{ + fluent, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, MultiSpan, +}; +use rustc_macros::Diagnostic; use rustc_span::{Span, Symbol}; use rustc_target::abi::TargetDataLayoutErrors; use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple}; @@ -46,10 +47,12 @@ pub struct FeatureDiagnosticHelp { pub feature: Symbol, } -impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> { +pub struct TargetDataLayoutErrorsWrapper<'a>(pub TargetDataLayoutErrors<'a>); + +impl IntoDiagnostic<'_, !> for TargetDataLayoutErrorsWrapper<'_> { fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> { let mut diag; - match self { + match self.0 { TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => { diag = handler.struct_fatal(fluent::session::target_invalid_address_space); diag.set_arg("addr_space", addr_space); @@ -97,87 +100,87 @@ fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> { } } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::not_circumvent_feature)] pub struct NotCircumventFeature; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::linker_plugin_lto_windows_not_supported)] pub struct LinkerPluginToWindowsNotSupported; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::profile_use_file_does_not_exist)] pub struct ProfileUseFileDoesNotExist<'a> { pub path: &'a std::path::Path, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::profile_sample_use_file_does_not_exist)] pub struct ProfileSampleUseFileDoesNotExist<'a> { pub path: &'a std::path::Path, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::target_requires_unwind_tables)] pub struct TargetRequiresUnwindTables; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::sanitizer_not_supported)] pub struct SanitizerNotSupported { pub us: String, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::sanitizers_not_supported)] pub struct SanitizersNotSupported { pub us: String, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::cannot_mix_and_match_sanitizers)] pub struct CannotMixAndMatchSanitizers { pub first: String, pub second: String, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::cannot_enable_crt_static_linux)] pub struct CannotEnableCrtStaticLinux; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::sanitizer_cfi_enabled)] pub struct SanitizerCfiEnabled; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::unstable_virtual_function_elimination)] pub struct UnstableVirtualFunctionElimination; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::unsupported_dwarf_version)] pub struct UnsupportedDwarfVersion { pub dwarf_version: u32, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::target_stack_protector_not_supported)] pub struct StackProtectorNotSupportedForTarget<'a> { pub stack_protector: StackProtector, pub target_triple: &'a TargetTriple, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::split_debuginfo_unstable_platform)] pub struct SplitDebugInfoUnstablePlatform { pub debuginfo: SplitDebuginfo, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::file_is_not_writeable)] pub struct FileIsNotWriteable<'a> { pub file: &'a std::path::Path, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::crate_name_does_not_match)] pub struct CrateNameDoesNotMatch<'a> { #[primary_span] @@ -186,13 +189,13 @@ pub struct CrateNameDoesNotMatch<'a> { pub name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::crate_name_invalid)] pub struct CrateNameInvalid<'a> { pub s: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::crate_name_empty)] pub struct CrateNameEmpty { #[primary_span] @@ -205,11 +208,8 @@ pub struct InvalidCharacterInCrateName<'a> { pub crate_name: &'a str, } -impl crate::SessionDiagnostic<'_> for InvalidCharacterInCrateName<'_> { - fn into_diagnostic( - self, - sess: &Handler, - ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { +impl IntoDiagnostic<'_> for InvalidCharacterInCrateName<'_> { + fn into_diagnostic(self, sess: &Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> { let mut diag = sess.struct_err(fluent::session::invalid_character_in_create_name); if let Some(sp) = self.span { diag.set_span(sp); diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 3189dcb08ade..b9202af2a676 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -11,8 +11,8 @@ use rustc_data_structures::sync::{Lock, Lrc}; use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler}; use rustc_errors::{ - fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, IntoDiagnostic, - DiagnosticId, DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, MultiSpan, StashKey, + fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId, + DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, IntoDiagnostic, MultiSpan, StashKey, }; use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures}; use rustc_span::edition::Edition; diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index e660b7399284..0142e9817663 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -27,8 +27,8 @@ use rustc_errors::json::JsonEmitter; use rustc_errors::registry::Registry; use rustc_errors::{ - error_code, fallback_fluent_bundle, DiagnosticBuilder, IntoDiagnostic, DiagnosticId, - DiagnosticMessage, ErrorGuaranteed, FluentBundle, LazyFallbackBundle, MultiSpan, + error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, + ErrorGuaranteed, FluentBundle, IntoDiagnostic, LazyFallbackBundle, MultiSpan, }; use rustc_macros::HashStable_Generic; pub use rustc_span::def_id::StableCrateId; diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 1baad6a9fd7a..7785d29c15f2 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -125,6 +125,7 @@ Symbols { AcqRel, Acquire, + AddToDiagnostic, Alignment, Any, Arc, @@ -176,7 +177,6 @@ DecorateLint, Default, Deref, - Diagnostic, DiagnosticMessage, DirBuilder, Display, @@ -210,6 +210,7 @@ Implied, Input, Into, + IntoDiagnostic, IntoFuture, IntoIterator, IoRead, @@ -282,7 +283,6 @@ String, StructuralEq, StructuralPartialEq, - Subdiagnostic, SubdiagnosticMessage, Sync, T, diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index b02ee593cbef..5e1b80eae393 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -1,4 +1,4 @@ -use rustc_errors::{fluent, IntoDiagnostic, ErrorGuaranteed, Handler}; +use rustc_errors::{fluent, ErrorGuaranteed, Handler, IntoDiagnostic}; use rustc_macros::Diagnostic; use rustc_middle::ty::{PolyTraitRef, Ty, Unevaluated}; use rustc_session::Limit; diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics.rs b/src/test/ui-fulldeps/internal-lints/diagnostics.rs index 4c2c28dc3368..18e39108ecab 100644 --- a/src/test/ui-fulldeps/internal-lints/diagnostics.rs +++ b/src/test/ui-fulldeps/internal-lints/diagnostics.rs @@ -20,7 +20,7 @@ #[derive(Diagnostic)] #[diag(parser::expect_path)] -struct DeriveSessionDiagnostic { +struct DeriveDiagnostic { #[primary_span] span: Span, } @@ -32,18 +32,18 @@ struct Note { span: Span, } -pub struct UntranslatableInSessionDiagnostic; +pub struct UntranslatableInIntoDiagnostic; -impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic { +impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for UntranslatableInIntoDiagnostic { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { handler.struct_err("untranslatable diagnostic") //~^ ERROR diagnostics should be created using translatable messages } } -pub struct TranslatableInSessionDiagnostic; +pub struct TranslatableInIntoDiagnostic; -impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic { +impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for TranslatableInIntoDiagnostic { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { handler.struct_err(fluent::parser::expect_path) } diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index b07b35f27235..c3972beb5128 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -449,7 +449,7 @@ error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied --> $DIR/diagnostic-derive.rs:331:10 | LL | #[derive(Diagnostic)] - | ^^^^^^^^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello` + | ^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello` | = help: normalized in stderr note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg`