macros: support doc comments in diag derives
Documentation comments shouldn't affect the diagnostic derive in any way, but explicit support has to be added for ignoring the `doc` attribute. Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
1536ab1b38
commit
7fbaf27696
5 changed files with 90 additions and 14 deletions
|
@ -5,9 +5,9 @@ use crate::diagnostics::error::{
|
|||
DiagnosticDeriveError,
|
||||
};
|
||||
use crate::diagnostics::utils::{
|
||||
build_field_mapping, new_code_ident, report_error_if_not_applied_to_applicability,
|
||||
report_error_if_not_applied_to_span, FieldInfo, FieldInnerTy, FieldMap, HasFieldMap, SetOnce,
|
||||
SpannedOption, SubdiagnosticKind,
|
||||
build_field_mapping, is_doc_comment, new_code_ident,
|
||||
report_error_if_not_applied_to_applicability, report_error_if_not_applied_to_span, FieldInfo,
|
||||
FieldInnerTy, FieldMap, HasFieldMap, SetOnce, SpannedOption, SubdiagnosticKind,
|
||||
};
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
|
@ -43,6 +43,11 @@ impl SubdiagnosticDeriveBuilder {
|
|||
|
||||
if matches!(ast.data, syn::Data::Enum(..)) {
|
||||
for attr in &ast.attrs {
|
||||
// Always allow documentation comments.
|
||||
if is_doc_comment(attr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
span_err(
|
||||
attr.span().unwrap(),
|
||||
"unsupported type attribute for subdiagnostic enum",
|
||||
|
@ -173,7 +178,11 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
|
|||
let mut kind_slugs = vec![];
|
||||
|
||||
for attr in self.variant.ast().attrs {
|
||||
let (kind, slug) = SubdiagnosticKind::from_attr(attr, self)?;
|
||||
let Some((kind, slug)) = SubdiagnosticKind::from_attr(attr, self)? else {
|
||||
// Some attributes aren't errors - like documentation comments - but also aren't
|
||||
// subdiagnostics.
|
||||
continue;
|
||||
};
|
||||
|
||||
let Some(slug) = slug else {
|
||||
let name = attr.path.segments.last().unwrap().ident.to_string();
|
||||
|
@ -227,6 +236,11 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
|
|||
ast.attrs
|
||||
.iter()
|
||||
.map(|attr| {
|
||||
// Always allow documentation comments.
|
||||
if is_doc_comment(attr) {
|
||||
return quote! {};
|
||||
}
|
||||
|
||||
let info = FieldInfo {
|
||||
binding,
|
||||
ty: inner_ty.inner_type().unwrap_or(&ast.ty),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue