Skip to content

Commit

Permalink
Rename DiagnosticDeriveKind::Diagnostic::handler as `DiagnosticDeri…
Browse files Browse the repository at this point in the history
…veKind::Diagnostic::dcx`.
  • Loading branch information
nnethercote committed Dec 18, 2023
1 parent f7125f1 commit 7b8644e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions compiler/rustc_macros/src/diagnostics/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ pub(crate) struct DiagnosticDerive<'a> {
}

impl<'a> DiagnosticDerive<'a> {
pub(crate) fn new(diag: syn::Ident, handler: syn::Ident, structure: Structure<'a>) -> Self {
pub(crate) fn new(diag: syn::Ident, dcx: syn::Ident, structure: Structure<'a>) -> Self {
Self {
builder: DiagnosticDeriveBuilder {
diag,
kind: DiagnosticDeriveKind::Diagnostic { handler },
kind: DiagnosticDeriveKind::Diagnostic { dcx },
},
structure,
}
Expand All @@ -36,7 +36,7 @@ impl<'a> DiagnosticDerive<'a> {
let body = builder.body(variant);

let diag = &builder.parent.diag;
let DiagnosticDeriveKind::Diagnostic { handler } = &builder.parent.kind else {
let DiagnosticDeriveKind::Diagnostic { dcx } = &builder.parent.kind else {
unreachable!()
};
let init = match builder.slug.value_ref() {
Expand All @@ -62,7 +62,7 @@ impl<'a> DiagnosticDerive<'a> {
Some(slug) => {
slugs.borrow_mut().push(slug.clone());
quote! {
let mut #diag = #handler.struct_diagnostic(crate::fluent_generated::#slug);
let mut #diag = #dcx.struct_diagnostic(crate::fluent_generated::#slug);
}
}
};
Expand All @@ -77,7 +77,7 @@ impl<'a> DiagnosticDerive<'a> {
}
});

let DiagnosticDeriveKind::Diagnostic { handler } = &builder.kind else { unreachable!() };
let DiagnosticDeriveKind::Diagnostic { dcx } = &builder.kind else { unreachable!() };

let mut imp = structure.gen_impl(quote! {
gen impl<'__diagnostic_handler_sess, G>
Expand All @@ -89,7 +89,7 @@ impl<'a> DiagnosticDerive<'a> {
#[track_caller]
fn into_diagnostic(
self,
#handler: &'__diagnostic_handler_sess rustc_errors::DiagCtxt
#dcx: &'__diagnostic_handler_sess rustc_errors::DiagCtxt
) -> rustc_errors::DiagnosticBuilder<'__diagnostic_handler_sess, G> {
use rustc_errors::IntoDiagnosticArg;
#implementation
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::utils::SubdiagnosticVariant;
/// What kind of diagnostic is being derived - a fatal/error/warning or a lint?
#[derive(Clone, PartialEq, Eq)]
pub(crate) enum DiagnosticDeriveKind {
Diagnostic { handler: syn::Ident },
Diagnostic { dcx: syn::Ident },
LintDiagnostic,
}

Expand Down Expand Up @@ -348,11 +348,11 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
}
(Meta::Path(_), "subdiagnostic") => {
if FieldInnerTy::from_type(&info.binding.ast().ty).will_iterate() {
let DiagnosticDeriveKind::Diagnostic { handler } = &self.parent.kind else {
let DiagnosticDeriveKind::Diagnostic { dcx } = &self.parent.kind else {
// No eager translation for lints.
return Ok(quote! { #diag.subdiagnostic(#binding); });
};
return Ok(quote! { #diag.eager_subdiagnostic(#handler, #binding); });
return Ok(quote! { #diag.eager_subdiagnostic(#dcx, #binding); });
} else {
return Ok(quote! { #diag.subdiagnostic(#binding); });
}
Expand All @@ -377,7 +377,7 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
}

let handler = match &self.parent.kind {
DiagnosticDeriveKind::Diagnostic { handler } => handler,
DiagnosticDeriveKind::Diagnostic { dcx } => dcx,
DiagnosticDeriveKind::LintDiagnostic => {
throw_invalid_attr!(attr, |diag| {
diag.help("eager subdiagnostics are not supported on lints")
Expand Down

0 comments on commit 7b8644e

Please sign in to comment.