Skip to content

Commit b4b9b1d

Browse files
committed
Rename DiagnosticDeriveError as DiagDeriveError.
1 parent 96657dd commit b4b9b1d

File tree

5 files changed

+34
-43
lines changed

5 files changed

+34
-43
lines changed

compiler/rustc_macros/src/diagnostics/diagnostic.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::cell::RefCell;
44

55
use crate::diagnostics::diagnostic_builder::DiagDeriveKind;
6-
use crate::diagnostics::error::{span_err, DiagnosticDeriveError};
6+
use crate::diagnostics::error::{span_err, DiagDeriveError};
77
use crate::diagnostics::utils::SetOnce;
88
use proc_macro2::TokenStream;
99
use quote::quote;
@@ -36,7 +36,7 @@ impl<'a> DiagnosticDerive<'a> {
3636
attribute, such as `#[diag(hir_analysis_example_error)]`",
3737
)
3838
.emit();
39-
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
39+
return DiagDeriveError::ErrorHandled.to_compile_error();
4040
}
4141
Some(slug)
4242
if let Some(Mismatch { slug_name, crate_name, slug_prefix }) =
@@ -46,7 +46,7 @@ impl<'a> DiagnosticDerive<'a> {
4646
.note(format!("slug is `{slug_name}` but the crate name is `{crate_name}`"))
4747
.help(format!("expected a slug starting with `{slug_prefix}_...`"))
4848
.emit();
49-
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
49+
return DiagDeriveError::ErrorHandled.to_compile_error();
5050
}
5151
Some(slug) => {
5252
slugs.borrow_mut().push(slug.clone());
@@ -131,7 +131,7 @@ impl<'a> LintDiagnosticDerive<'a> {
131131
`#[diag(compiletest_example)]`",
132132
)
133133
.emit();
134-
DiagnosticDeriveError::ErrorHandled.to_compile_error()
134+
DiagDeriveError::ErrorHandled.to_compile_error()
135135
}
136136
Some(slug)
137137
if let Some(Mismatch { slug_name, crate_name, slug_prefix }) =
@@ -141,7 +141,7 @@ impl<'a> LintDiagnosticDerive<'a> {
141141
.note(format!("slug is `{slug_name}` but the crate name is `{crate_name}`"))
142142
.help(format!("expected a slug starting with `{slug_prefix}_...`"))
143143
.emit();
144-
DiagnosticDeriveError::ErrorHandled.to_compile_error()
144+
DiagDeriveError::ErrorHandled.to_compile_error()
145145
}
146146
Some(slug) => {
147147
slugs.borrow_mut().push(slug.clone());

compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#![deny(unused_must_use)]
22

3-
use crate::diagnostics::error::{
4-
span_err, throw_invalid_attr, throw_span_err, DiagnosticDeriveError,
5-
};
3+
use crate::diagnostics::error::{span_err, throw_invalid_attr, throw_span_err, DiagDeriveError};
64
use crate::diagnostics::utils::{
75
build_field_mapping, is_doc_comment, report_error_if_not_applied_to_span, report_type_error,
86
should_generate_arg, type_is_bool, type_is_unit, type_matches_path, FieldInfo, FieldInnerTy,
@@ -143,7 +141,7 @@ impl DiagnosticDeriveVariantBuilder {
143141
fn parse_subdiag_attribute(
144142
&self,
145143
attr: &Attribute,
146-
) -> Result<Option<(SubdiagnosticKind, Path, bool)>, DiagnosticDeriveError> {
144+
) -> Result<Option<(SubdiagnosticKind, Path, bool)>, DiagDeriveError> {
147145
let Some(subdiag) = SubdiagnosticVariant::from_attr(attr, self)? else {
148146
// Some attributes aren't errors - like documentation comments - but also aren't
149147
// subdiagnostics.
@@ -173,7 +171,7 @@ impl DiagnosticDeriveVariantBuilder {
173171
fn generate_structure_code_for_attr(
174172
&mut self,
175173
attr: &Attribute,
176-
) -> Result<TokenStream, DiagnosticDeriveError> {
174+
) -> Result<TokenStream, DiagDeriveError> {
177175
// Always allow documentation comments.
178176
if is_doc_comment(attr) {
179177
return Ok(quote! {});
@@ -307,7 +305,7 @@ impl DiagnosticDeriveVariantBuilder {
307305
attr: &Attribute,
308306
info: FieldInfo<'_>,
309307
binding: TokenStream,
310-
) -> Result<TokenStream, DiagnosticDeriveError> {
308+
) -> Result<TokenStream, DiagDeriveError> {
311309
let ident = &attr.path().segments.last().unwrap().ident;
312310
let name = ident.to_string();
313311
match (&attr.meta, name.as_str()) {
@@ -430,7 +428,7 @@ impl DiagnosticDeriveVariantBuilder {
430428
fn span_and_applicability_of_ty(
431429
&self,
432430
info: FieldInfo<'_>,
433-
) -> Result<(TokenStream, SpannedOption<TokenStream>), DiagnosticDeriveError> {
431+
) -> Result<(TokenStream, SpannedOption<TokenStream>), DiagDeriveError> {
434432
match &info.ty.inner_type() {
435433
// If `ty` is `Span` w/out applicability, then use `Applicability::Unspecified`.
436434
ty @ Type::Path(..) if type_matches_path(ty, &["rustc_span", "Span"]) => {
@@ -442,14 +440,14 @@ impl DiagnosticDeriveVariantBuilder {
442440
let mut span_idx = None;
443441
let mut applicability_idx = None;
444442

445-
fn type_err(span: &Span) -> Result<!, DiagnosticDeriveError> {
443+
fn type_err(span: &Span) -> Result<!, DiagDeriveError> {
446444
span_err(span.unwrap(), "wrong types for suggestion")
447445
.help(
448446
"`#[suggestion(...)]` on a tuple field must be applied to fields \
449447
of type `(Span, Applicability)`",
450448
)
451449
.emit();
452-
Err(DiagnosticDeriveError::ErrorHandled)
450+
Err(DiagDeriveError::ErrorHandled)
453451
}
454452

455453
for (idx, elem) in tup.elems.iter().enumerate() {

compiler/rustc_macros/src/diagnostics/error.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ use quote::quote;
44
use syn::{spanned::Spanned, Attribute, Error as SynError, Meta};
55

66
#[derive(Debug)]
7-
pub(crate) enum DiagnosticDeriveError {
7+
pub(crate) enum DiagDeriveError {
88
SynError(SynError),
99
ErrorHandled,
1010
}
1111

12-
impl DiagnosticDeriveError {
12+
impl DiagDeriveError {
1313
pub(crate) fn to_compile_error(self) -> TokenStream {
1414
match self {
15-
DiagnosticDeriveError::SynError(e) => e.to_compile_error(),
16-
DiagnosticDeriveError::ErrorHandled => {
15+
DiagDeriveError::SynError(e) => e.to_compile_error(),
16+
DiagDeriveError::ErrorHandled => {
1717
// Return ! to avoid having to create a blank Diag to return when an
1818
// error has already been emitted to the compiler.
1919
quote! {
@@ -24,19 +24,19 @@ impl DiagnosticDeriveError {
2424
}
2525
}
2626

27-
impl From<SynError> for DiagnosticDeriveError {
27+
impl From<SynError> for DiagDeriveError {
2828
fn from(e: SynError) -> Self {
29-
DiagnosticDeriveError::SynError(e)
29+
DiagDeriveError::SynError(e)
3030
}
3131
}
3232

3333
/// Helper function for use with `throw_*` macros - constraints `$f` to an `impl FnOnce`.
3434
pub(crate) fn _throw_err(
3535
diag: Diagnostic,
3636
f: impl FnOnce(Diagnostic) -> Diagnostic,
37-
) -> DiagnosticDeriveError {
37+
) -> DiagDeriveError {
3838
f(diag).emit();
39-
DiagnosticDeriveError::ErrorHandled
39+
DiagDeriveError::ErrorHandled
4040
}
4141

4242
/// Helper function for printing `syn::Path` - doesn't handle arguments in paths and these are
@@ -61,7 +61,7 @@ pub(crate) fn span_err<T: Into<String>>(span: impl MultiSpan, msg: T) -> Diagnos
6161
/// Emit a diagnostic on span `$span` with msg `$msg` (optionally performing additional decoration
6262
/// using the `FnOnce` passed in `diag`) and return `Err(ErrorHandled)`.
6363
///
64-
/// For methods that return a `Result<_, DiagnosticDeriveError>`:
64+
/// For methods that return a `Result<_, DiagDeriveError>`:
6565
macro_rules! throw_span_err {
6666
($span:expr, $msg:expr) => {{ throw_span_err!($span, $msg, |diag| diag) }};
6767
($span:expr, $msg:expr, $f:expr) => {{
@@ -86,7 +86,7 @@ pub(crate) fn invalid_attr(attr: &Attribute) -> Diagnostic {
8686
/// Emit an error diagnostic for an invalid attribute (optionally performing additional decoration
8787
/// using the `FnOnce` passed in `diag`) and return `Err(ErrorHandled)`.
8888
///
89-
/// For methods that return a `Result<_, DiagnosticDeriveError>`:
89+
/// For methods that return a `Result<_, DiagDeriveError>`:
9090
macro_rules! throw_invalid_attr {
9191
($attr:expr) => {{ throw_invalid_attr!($attr, |diag| diag) }};
9292
($attr:expr, $f:expr) => {{

compiler/rustc_macros/src/diagnostics/subdiagnostic.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![deny(unused_must_use)]
22

33
use crate::diagnostics::error::{
4-
invalid_attr, span_err, throw_invalid_attr, throw_span_err, DiagnosticDeriveError,
4+
invalid_attr, span_err, throw_invalid_attr, throw_span_err, DiagDeriveError,
55
};
66
use crate::diagnostics::utils::{
77
build_field_mapping, build_suggestion_code, is_doc_comment, new_code_ident,
@@ -182,9 +182,7 @@ impl<'a> FromIterator<&'a SubdiagnosticKind> for KindsStatistics {
182182
}
183183

184184
impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
185-
fn identify_kind(
186-
&mut self,
187-
) -> Result<Vec<(SubdiagnosticKind, Path, bool)>, DiagnosticDeriveError> {
185+
fn identify_kind(&mut self) -> Result<Vec<(SubdiagnosticKind, Path, bool)>, DiagDeriveError> {
188186
let mut kind_slugs = vec![];
189187

190188
for attr in self.variant.ast().attrs {
@@ -270,7 +268,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
270268
attr: &Attribute,
271269
info: FieldInfo<'_>,
272270
clone_suggestion_code: bool,
273-
) -> Result<TokenStream, DiagnosticDeriveError> {
271+
) -> Result<TokenStream, DiagDeriveError> {
274272
match &attr.meta {
275273
Meta::Path(path) => {
276274
self.generate_field_code_inner_path(kind_stats, attr, info, path.clone())
@@ -293,7 +291,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
293291
attr: &Attribute,
294292
info: FieldInfo<'_>,
295293
path: Path,
296-
) -> Result<TokenStream, DiagnosticDeriveError> {
294+
) -> Result<TokenStream, DiagDeriveError> {
297295
let span = attr.span().unwrap();
298296
let ident = &path.segments.last().unwrap().ident;
299297
let name = ident.to_string();
@@ -403,7 +401,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
403401
info: FieldInfo<'_>,
404402
list: &MetaList,
405403
clone_suggestion_code: bool,
406-
) -> Result<TokenStream, DiagnosticDeriveError> {
404+
) -> Result<TokenStream, DiagDeriveError> {
407405
let span = attr.span().unwrap();
408406
let mut ident = list.path.segments.last().unwrap().ident.clone();
409407
ident.set_span(info.ty.span());
@@ -478,7 +476,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
478476
}
479477
}
480478

481-
pub(crate) fn into_tokens(&mut self) -> Result<TokenStream, DiagnosticDeriveError> {
479+
pub(crate) fn into_tokens(&mut self) -> Result<TokenStream, DiagDeriveError> {
482480
let kind_slugs = self.identify_kind()?;
483481
if kind_slugs.is_empty() {
484482
if self.is_enum {

compiler/rustc_macros/src/diagnostics/utils.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::diagnostics::error::{
2-
span_err, throw_invalid_attr, throw_span_err, DiagnosticDeriveError,
3-
};
1+
use crate::diagnostics::error::{span_err, throw_invalid_attr, throw_span_err, DiagDeriveError};
42
use proc_macro::Span;
53
use proc_macro2::{Ident, TokenStream};
64
use quote::{format_ident, quote, ToTokens};
@@ -58,10 +56,7 @@ pub(crate) fn type_is_bool(ty: &Type) -> bool {
5856
}
5957

6058
/// Reports a type error for field with `attr`.
61-
pub(crate) fn report_type_error(
62-
attr: &Attribute,
63-
ty_name: &str,
64-
) -> Result<!, DiagnosticDeriveError> {
59+
pub(crate) fn report_type_error(attr: &Attribute, ty_name: &str) -> Result<!, DiagDeriveError> {
6560
let name = attr.path().segments.last().unwrap().ident.to_string();
6661
let meta = &attr.meta;
6762

@@ -86,7 +81,7 @@ fn report_error_if_not_applied_to_ty(
8681
info: &FieldInfo<'_>,
8782
path: &[&str],
8883
ty_name: &str,
89-
) -> Result<(), DiagnosticDeriveError> {
84+
) -> Result<(), DiagDeriveError> {
9085
if !type_matches_path(info.ty.inner_type(), path) {
9186
report_type_error(attr, ty_name)?;
9287
}
@@ -98,7 +93,7 @@ fn report_error_if_not_applied_to_ty(
9893
pub(crate) fn report_error_if_not_applied_to_applicability(
9994
attr: &Attribute,
10095
info: &FieldInfo<'_>,
101-
) -> Result<(), DiagnosticDeriveError> {
96+
) -> Result<(), DiagDeriveError> {
10297
report_error_if_not_applied_to_ty(
10398
attr,
10499
info,
@@ -111,7 +106,7 @@ pub(crate) fn report_error_if_not_applied_to_applicability(
111106
pub(crate) fn report_error_if_not_applied_to_span(
112107
attr: &Attribute,
113108
info: &FieldInfo<'_>,
114-
) -> Result<(), DiagnosticDeriveError> {
109+
) -> Result<(), DiagDeriveError> {
115110
if !type_matches_path(info.ty.inner_type(), &["rustc_span", "Span"])
116111
&& !type_matches_path(info.ty.inner_type(), &["rustc_errors", "MultiSpan"])
117112
{
@@ -610,7 +605,7 @@ impl SubdiagnosticVariant {
610605
pub(super) fn from_attr(
611606
attr: &Attribute,
612607
fields: &impl HasFieldMap,
613-
) -> Result<Option<SubdiagnosticVariant>, DiagnosticDeriveError> {
608+
) -> Result<Option<SubdiagnosticVariant>, DiagDeriveError> {
614609
// Always allow documentation comments.
615610
if is_doc_comment(attr) {
616611
return Ok(None);

0 commit comments

Comments
 (0)