1
Fork 0

UPDATE - rename DiagnosticHandler trait to IntoDiagnostic

This commit is contained in:
Jhonny Bill Mena 2022-09-18 11:45:41 -04:00
parent 5b8152807c
commit 19b348fed4
46 changed files with 659 additions and 584 deletions

View file

@ -11,27 +11,27 @@ use synstructure::Structure;
/// The central struct for constructing the `into_diagnostic` method from an annotated struct.
pub(crate) struct SessionDiagnosticDerive<'a> {
structure: Structure<'a>,
sess: syn::Ident,
handler: syn::Ident,
builder: DiagnosticDeriveBuilder,
}
impl<'a> SessionDiagnosticDerive<'a> {
pub(crate) fn new(diag: syn::Ident, sess: syn::Ident, structure: Structure<'a>) -> Self {
pub(crate) fn new(diag: syn::Ident, handler: syn::Ident, structure: Structure<'a>) -> Self {
Self {
builder: DiagnosticDeriveBuilder {
diag,
fields: build_field_mapping(&structure),
kind: DiagnosticDeriveKind::SessionDiagnostic,
kind: DiagnosticDeriveKind::DiagnosticHandler,
code: None,
slug: None,
},
sess,
handler,
structure,
}
}
pub(crate) fn into_tokens(self) -> TokenStream {
let SessionDiagnosticDerive { mut structure, sess, mut builder } = self;
let SessionDiagnosticDerive { mut structure, handler, mut builder } = self;
let ast = structure.ast();
let implementation = {
@ -53,7 +53,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
}
Some(slug) => {
quote! {
let mut #diag = #sess.struct_diagnostic(rustc_errors::fluent::#slug);
let mut #diag = #handler.struct_diagnostic(rustc_errors::fluent::#slug);
}
}
};
@ -72,7 +72,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
} else {
span_err(
ast.span().unwrap(),
"`#[derive(SessionDiagnostic)]` can only be used on structs",
"`#[derive(DiagnosticHandler)]` can only be used on structs",
)
.emit();
@ -81,15 +81,15 @@ impl<'a> SessionDiagnosticDerive<'a> {
};
structure.gen_impl(quote! {
gen impl<'__session_diagnostic_sess, G>
rustc_errors::SessionDiagnostic<'__session_diagnostic_sess, G>
gen impl<'__diagnostic_handler_sess, G>
rustc_errors::IntoDiagnostic<'__diagnostic_handler_sess, G>
for @Self
where G: rustc_errors::EmissionGuarantee
{
fn into_diagnostic(
self,
#sess: &'__session_diagnostic_sess rustc_errors::Handler
) -> rustc_errors::DiagnosticBuilder<'__session_diagnostic_sess, G> {
#handler: &'__diagnostic_handler_sess rustc_errors::Handler
) -> rustc_errors::DiagnosticBuilder<'__diagnostic_handler_sess, G> {
use rustc_errors::IntoDiagnosticArg;
#implementation
}

View file

@ -21,12 +21,12 @@ use synstructure::{BindingInfo, Structure};
/// What kind of diagnostic is being derived - a fatal/error/warning or a lint?
#[derive(Copy, Clone, PartialEq, Eq)]
pub(crate) enum DiagnosticDeriveKind {
SessionDiagnostic,
DiagnosticHandler,
LintDiagnostic,
}
/// Tracks persistent information required for building up individual calls to diagnostic methods
/// for generated diagnostic derives - both `SessionDiagnostic` for fatal/errors/warnings and
/// for generated diagnostic derives - both `DiagnosticHandler` for fatal/errors/warnings and
/// `LintDiagnostic` for lints.
pub(crate) struct DiagnosticDeriveBuilder {
/// The identifier to use for the generated `DiagnosticBuilder` instance.
@ -333,7 +333,7 @@ impl DiagnosticDeriveBuilder {
}
"primary_span" => {
match self.kind {
DiagnosticDeriveKind::SessionDiagnostic => {
DiagnosticDeriveKind::DiagnosticHandler => {
report_error_if_not_applied_to_span(attr, &info)?;
Ok(quote! {

View file

@ -12,7 +12,7 @@ use quote::format_ident;
use subdiagnostic::SessionSubdiagnosticDerive;
use synstructure::Structure;
/// Implements `#[derive(SessionDiagnostic)]`, which allows for errors to be specified as a struct,
/// Implements `#[derive(DiagnosticHandler)]`, which allows for errors to be specified as a struct,
/// independent from the actual diagnostics emitting code.
///
/// ```ignore (rust)
@ -22,7 +22,7 @@ use synstructure::Structure;
/// # use rustc_span::{symbol::Ident, Span};
/// # extern crate rust_middle;
/// # use rustc_middle::ty::Ty;
/// #[derive(SessionDiagnostic)]
/// #[derive(DiagnosticHandler)]
/// #[diag(borrowck::move_out_of_borrow, code = "E0505")]
/// pub struct MoveOutOfBorrowError<'tcx> {
/// pub name: Ident,
@ -56,10 +56,10 @@ use synstructure::Structure;
/// });
/// ```
///
/// See rustc dev guide for more examples on using the `#[derive(SessionDiagnostic)]`:
/// See rustc dev guide for more examples on using the `#[derive(DiagnosticHandler)]`:
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html>
pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream {
SessionDiagnosticDerive::new(format_ident!("diag"), format_ident!("sess"), s).into_tokens()
SessionDiagnosticDerive::new(format_ident!("diag"), format_ident!("handler"), s).into_tokens()
}
/// Implements `#[derive(LintDiagnostic)]`, which allows for lints to be specified as a struct,

View file

@ -127,7 +127,7 @@ decl_derive!([TypeFoldable, attributes(type_foldable)] => type_foldable::type_fo
decl_derive!([TypeVisitable, attributes(type_visitable)] => type_visitable::type_visitable_derive);
decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
decl_derive!(
[SessionDiagnostic, attributes(
[DiagnosticHandler, attributes(
// struct attributes
diag,
help,