Skip to content

Commit df9d457

Browse files
committed
give a better error for tuple structs in derive(Diagnostic)
1 parent 74583db commit df9d457

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Diff for: compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
263263
let mut field_binding = binding_info.binding.clone();
264264
field_binding.set_span(field.ty.span());
265265

266-
let ident = field.ident.as_ref().unwrap();
266+
let Some(ident) = field.ident.as_ref() else {
267+
span_err(field.span().unwrap(), "tuple structs are not supported").emit();
268+
return TokenStream::new();
269+
};
267270
let ident = format_ident!("{}", ident); // strip `r#` prefix, if present
268271

269272
quote! {

Diff for: compiler/rustc_macros/src/diagnostics/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn path_to_string(path: &syn::Path) -> String {
5555
/// Returns an error diagnostic on span `span` with msg `msg`.
5656
#[must_use]
5757
pub(crate) fn span_err<T: Into<String>>(span: impl MultiSpan, msg: T) -> Diagnostic {
58-
Diagnostic::spanned(span, Level::Error, msg)
58+
Diagnostic::spanned(span, Level::Error, format!("derive(Diagnostic): {}", msg.into()))
5959
}
6060

6161
/// Emit a diagnostic on span `$span` with msg `$msg` (optionally performing additional decoration

0 commit comments

Comments
 (0)