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
|
@ -477,7 +477,12 @@ impl SubdiagnosticKind {
|
|||
pub(super) fn from_attr(
|
||||
attr: &Attribute,
|
||||
fields: &impl HasFieldMap,
|
||||
) -> Result<(SubdiagnosticKind, Option<Path>), DiagnosticDeriveError> {
|
||||
) -> Result<Option<(SubdiagnosticKind, Option<Path>)>, DiagnosticDeriveError> {
|
||||
// Always allow documentation comments.
|
||||
if is_doc_comment(attr) {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let span = attr.span().unwrap();
|
||||
|
||||
let name = attr.path.segments.last().unwrap().ident.to_string();
|
||||
|
@ -526,7 +531,9 @@ impl SubdiagnosticKind {
|
|||
| SubdiagnosticKind::Note
|
||||
| SubdiagnosticKind::Help
|
||||
| SubdiagnosticKind::Warn
|
||||
| SubdiagnosticKind::MultipartSuggestion { .. } => return Ok((kind, None)),
|
||||
| SubdiagnosticKind::MultipartSuggestion { .. } => {
|
||||
return Ok(Some((kind, None)));
|
||||
}
|
||||
SubdiagnosticKind::Suggestion { .. } => {
|
||||
throw_span_err!(span, "suggestion without `code = \"...\"`")
|
||||
}
|
||||
|
@ -626,7 +633,7 @@ impl SubdiagnosticKind {
|
|||
| SubdiagnosticKind::MultipartSuggestion { .. } => {}
|
||||
}
|
||||
|
||||
Ok((kind, slug))
|
||||
Ok(Some((kind, slug)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -654,3 +661,7 @@ impl quote::IdentFragment for SubdiagnosticKind {
|
|||
pub(super) fn should_generate_set_arg(field: &Field) -> bool {
|
||||
field.attrs.is_empty()
|
||||
}
|
||||
|
||||
pub(super) fn is_doc_comment(attr: &Attribute) -> bool {
|
||||
attr.path.segments.last().unwrap().ident.to_string() == "doc"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue