summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_macros/src/diagnostics
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_macros/src/diagnostics')
-rw-r--r--compiler/rustc_macros/src/diagnostics/diagnostic.rs27
-rw-r--r--compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs19
-rw-r--r--compiler/rustc_macros/src/diagnostics/subdiagnostic.rs2
-rw-r--r--compiler/rustc_macros/src/diagnostics/utils.rs6
4 files changed, 28 insertions, 26 deletions
diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic.rs b/compiler/rustc_macros/src/diagnostics/diagnostic.rs
index 1a8174bfd..5de0203fc 100644
--- a/compiler/rustc_macros/src/diagnostics/diagnostic.rs
+++ b/compiler/rustc_macros/src/diagnostics/diagnostic.rs
@@ -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,
}
@@ -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() {
@@ -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);
}
}
};
@@ -77,11 +77,12 @@ impl<'a> DiagnosticDerive<'a> {
}
});
- let DiagnosticDeriveKind::Diagnostic { handler } = &builder.kind else { unreachable!() };
+ let DiagnosticDeriveKind::Diagnostic { dcx } = &builder.kind else { unreachable!() };
+ // A lifetime of `'a` causes conflicts, but `_sess` is fine.
let mut imp = structure.gen_impl(quote! {
- gen impl<'__diagnostic_handler_sess, G>
- rustc_errors::IntoDiagnostic<'__diagnostic_handler_sess, G>
+ gen impl<'_sess, G>
+ rustc_errors::IntoDiagnostic<'_sess, G>
for @Self
where G: rustc_errors::EmissionGuarantee
{
@@ -89,8 +90,8 @@ impl<'a> DiagnosticDerive<'a> {
#[track_caller]
fn into_diagnostic(
self,
- #handler: &'__diagnostic_handler_sess rustc_errors::Handler
- ) -> rustc_errors::DiagnosticBuilder<'__diagnostic_handler_sess, G> {
+ #dcx: &'_sess rustc_errors::DiagCtxt
+ ) -> rustc_errors::DiagnosticBuilder<'_sess, G> {
use rustc_errors::IntoDiagnosticArg;
#implementation
}
@@ -175,9 +176,9 @@ impl<'a> LintDiagnosticDerive<'a> {
fn decorate_lint<'__b>(
self,
#diag: &'__b mut rustc_errors::DiagnosticBuilder<'__a, ()>
- ) -> &'__b mut rustc_errors::DiagnosticBuilder<'__a, ()> {
+ ) {
use rustc_errors::IntoDiagnosticArg;
- #implementation
+ #implementation;
}
fn msg(&self) -> rustc_errors::DiagnosticMessage {
@@ -229,8 +230,8 @@ fn generate_test(slug: &syn::Path, structure: &Structure<'_>) -> TokenStream {
}
}
use std::sync::atomic::{AtomicUsize, Ordering};
- // We need to make sure that the same diagnostic slug can be used multiple times without causing an
- // error, so just have a global counter here.
+ // We need to make sure that the same diagnostic slug can be used multiple times without
+ // causing an error, so just have a global counter here.
static COUNTER: AtomicUsize = AtomicUsize::new(0);
let slug = slug.get_ident().unwrap();
let ident = quote::format_ident!("verify_{slug}_{}", COUNTER.fetch_add(1, Ordering::Relaxed));
diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs
index e9a5cd9de..511654d99 100644
--- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs
+++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs
@@ -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,
}
@@ -53,6 +53,7 @@ pub(crate) struct DiagnosticDeriveVariantBuilder<'parent> {
/// Slug is a mandatory part of the struct attribute as corresponds to the Fluent message that
/// has the actual diagnostic message.
pub slug: SpannedOption<Path>,
+
/// Error codes are a optional part of the struct attribute - this is only set to detect
/// multiple specifications.
pub code: SpannedOption<()>,
@@ -68,7 +69,7 @@ impl DiagnosticDeriveBuilder {
/// Call `f` for the struct or for each variant of the enum, returning a `TokenStream` with the
/// tokens from `f` wrapped in an `match` expression. Emits errors for use of derive on unions
/// or attributes on the type itself when input is an enum.
- pub fn each_variant<'s, F>(&mut self, structure: &mut Structure<'s>, f: F) -> TokenStream
+ pub(crate) fn each_variant<'s, F>(&mut self, structure: &mut Structure<'s>, f: F) -> TokenStream
where
F: for<'a, 'v> Fn(DiagnosticDeriveVariantBuilder<'a>, &VariantInfo<'v>) -> TokenStream,
{
@@ -121,7 +122,7 @@ impl DiagnosticDeriveBuilder {
impl<'a> DiagnosticDeriveVariantBuilder<'a> {
/// Generates calls to `code` and similar functions based on the attributes on the type or
/// variant.
- pub fn preamble(&mut self, variant: &VariantInfo<'_>) -> TokenStream {
+ pub(crate) fn preamble(&mut self, variant: &VariantInfo<'_>) -> TokenStream {
let ast = variant.ast();
let attrs = &ast.attrs;
let preamble = attrs.iter().map(|attr| {
@@ -135,7 +136,7 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
/// Generates calls to `span_label` and similar functions based on the attributes on fields or
/// calls to `set_arg` when no attributes are present.
- pub fn body(&mut self, variant: &VariantInfo<'_>) -> TokenStream {
+ pub(crate) fn body(&mut self, variant: &VariantInfo<'_>) -> TokenStream {
let mut body = quote! {};
// Generate `set_arg` calls first..
for binding in variant.bindings().iter().filter(|bi| should_generate_set_arg(bi.ast())) {
@@ -347,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); });
}
@@ -375,15 +376,15 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
return Ok(quote! {});
}
- let handler = match &self.parent.kind {
- DiagnosticDeriveKind::Diagnostic { handler } => handler,
+ let dcx = match &self.parent.kind {
+ DiagnosticDeriveKind::Diagnostic { dcx } => dcx,
DiagnosticDeriveKind::LintDiagnostic => {
throw_invalid_attr!(attr, |diag| {
diag.help("eager subdiagnostics are not supported on lints")
})
}
};
- return Ok(quote! { #diag.eager_subdiagnostic(#handler, #binding); });
+ return Ok(quote! { #diag.eager_subdiagnostic(#dcx, #binding); });
}
_ => (),
}
diff --git a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs
index 877271ff0..0f9e68cdc 100644
--- a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs
+++ b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs
@@ -478,7 +478,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
}
}
- pub fn into_tokens(&mut self) -> Result<TokenStream, DiagnosticDeriveError> {
+ pub(crate) fn into_tokens(&mut self) -> Result<TokenStream, DiagnosticDeriveError> {
let kind_slugs = self.identify_kind()?;
if kind_slugs.is_empty() {
if self.is_enum {
diff --git a/compiler/rustc_macros/src/diagnostics/utils.rs b/compiler/rustc_macros/src/diagnostics/utils.rs
index 125632921..2700f02e3 100644
--- a/compiler/rustc_macros/src/diagnostics/utils.rs
+++ b/compiler/rustc_macros/src/diagnostics/utils.rs
@@ -17,7 +17,7 @@ use synstructure::{BindingInfo, VariantInfo};
use super::error::invalid_attr;
thread_local! {
- pub static CODE_IDENT_COUNT: RefCell<u32> = RefCell::new(0);
+ pub(crate) static CODE_IDENT_COUNT: RefCell<u32> = RefCell::new(0);
}
/// Returns an ident of the form `__code_N` where `N` is incremented once with every call.
@@ -208,7 +208,7 @@ impl<'ty> FieldInnerTy<'ty> {
}
}
- pub fn span(&self) -> proc_macro2::Span {
+ pub(crate) fn span(&self) -> proc_macro2::Span {
match self {
FieldInnerTy::Option(ty) | FieldInnerTy::Vec(ty) | FieldInnerTy::Plain(ty) => ty.span(),
}
@@ -537,7 +537,7 @@ impl fmt::Display for SuggestionKind {
}
impl SuggestionKind {
- pub fn to_suggestion_style(&self) -> TokenStream {
+ pub(crate) fn to_suggestion_style(&self) -> TokenStream {
match self {
SuggestionKind::Normal => {
quote! { rustc_errors::SuggestionStyle::ShowCode }