Add note_once/help_once to diagnostic derives
This commit is contained in:
parent
56bca95875
commit
eee14e9adf
3 changed files with 30 additions and 4 deletions
|
@ -158,7 +158,9 @@ impl DiagnosticDeriveVariantBuilder {
|
||||||
let slug = subdiag.slug.unwrap_or_else(|| match subdiag.kind {
|
let slug = subdiag.slug.unwrap_or_else(|| match subdiag.kind {
|
||||||
SubdiagnosticKind::Label => parse_quote! { _subdiag::label },
|
SubdiagnosticKind::Label => parse_quote! { _subdiag::label },
|
||||||
SubdiagnosticKind::Note => parse_quote! { _subdiag::note },
|
SubdiagnosticKind::Note => parse_quote! { _subdiag::note },
|
||||||
|
SubdiagnosticKind::NoteOnce => parse_quote! { _subdiag::note_once },
|
||||||
SubdiagnosticKind::Help => parse_quote! { _subdiag::help },
|
SubdiagnosticKind::Help => parse_quote! { _subdiag::help },
|
||||||
|
SubdiagnosticKind::HelpOnce => parse_quote! { _subdiag::help_once },
|
||||||
SubdiagnosticKind::Warn => parse_quote! { _subdiag::warn },
|
SubdiagnosticKind::Warn => parse_quote! { _subdiag::warn },
|
||||||
SubdiagnosticKind::Suggestion { .. } => parse_quote! { _subdiag::suggestion },
|
SubdiagnosticKind::Suggestion { .. } => parse_quote! { _subdiag::suggestion },
|
||||||
SubdiagnosticKind::MultipartSuggestion { .. } => unreachable!(),
|
SubdiagnosticKind::MultipartSuggestion { .. } => unreachable!(),
|
||||||
|
@ -233,9 +235,11 @@ impl DiagnosticDeriveVariantBuilder {
|
||||||
};
|
};
|
||||||
let fn_ident = format_ident!("{}", subdiag);
|
let fn_ident = format_ident!("{}", subdiag);
|
||||||
match subdiag {
|
match subdiag {
|
||||||
SubdiagnosticKind::Note | SubdiagnosticKind::Help | SubdiagnosticKind::Warn => {
|
SubdiagnosticKind::Note
|
||||||
Ok(self.add_subdiagnostic(&fn_ident, slug))
|
| SubdiagnosticKind::NoteOnce
|
||||||
}
|
| SubdiagnosticKind::Help
|
||||||
|
| SubdiagnosticKind::HelpOnce
|
||||||
|
| SubdiagnosticKind::Warn => Ok(self.add_subdiagnostic(&fn_ident, slug)),
|
||||||
SubdiagnosticKind::Label | SubdiagnosticKind::Suggestion { .. } => {
|
SubdiagnosticKind::Label | SubdiagnosticKind::Suggestion { .. } => {
|
||||||
throw_invalid_attr!(attr, |diag| diag
|
throw_invalid_attr!(attr, |diag| diag
|
||||||
.help("`#[label]` and `#[suggestion]` can only be applied to fields"));
|
.help("`#[label]` and `#[suggestion]` can only be applied to fields"));
|
||||||
|
@ -347,7 +351,11 @@ impl DiagnosticDeriveVariantBuilder {
|
||||||
report_error_if_not_applied_to_span(attr, &info)?;
|
report_error_if_not_applied_to_span(attr, &info)?;
|
||||||
Ok(self.add_spanned_subdiagnostic(binding, &fn_ident, slug))
|
Ok(self.add_spanned_subdiagnostic(binding, &fn_ident, slug))
|
||||||
}
|
}
|
||||||
SubdiagnosticKind::Note | SubdiagnosticKind::Help | SubdiagnosticKind::Warn => {
|
SubdiagnosticKind::Note
|
||||||
|
| SubdiagnosticKind::NoteOnce
|
||||||
|
| SubdiagnosticKind::Help
|
||||||
|
| SubdiagnosticKind::HelpOnce
|
||||||
|
| SubdiagnosticKind::Warn => {
|
||||||
let inner = info.ty.inner_type();
|
let inner = info.ty.inner_type();
|
||||||
if type_matches_path(inner, &["rustc_span", "Span"])
|
if type_matches_path(inner, &["rustc_span", "Span"])
|
||||||
|| type_matches_path(inner, &["rustc_span", "MultiSpan"])
|
|| type_matches_path(inner, &["rustc_span", "MultiSpan"])
|
||||||
|
|
|
@ -575,8 +575,12 @@ pub(super) enum SubdiagnosticKind {
|
||||||
Label,
|
Label,
|
||||||
/// `#[note(...)]`
|
/// `#[note(...)]`
|
||||||
Note,
|
Note,
|
||||||
|
/// `#[note_once(...)]`
|
||||||
|
NoteOnce,
|
||||||
/// `#[help(...)]`
|
/// `#[help(...)]`
|
||||||
Help,
|
Help,
|
||||||
|
/// `#[help_once(...)]`
|
||||||
|
HelpOnce,
|
||||||
/// `#[warning(...)]`
|
/// `#[warning(...)]`
|
||||||
Warn,
|
Warn,
|
||||||
/// `#[suggestion{,_short,_hidden,_verbose}]`
|
/// `#[suggestion{,_short,_hidden,_verbose}]`
|
||||||
|
@ -624,7 +628,9 @@ impl SubdiagnosticVariant {
|
||||||
let mut kind = match name {
|
let mut kind = match name {
|
||||||
"label" => SubdiagnosticKind::Label,
|
"label" => SubdiagnosticKind::Label,
|
||||||
"note" => SubdiagnosticKind::Note,
|
"note" => SubdiagnosticKind::Note,
|
||||||
|
"note_once" => SubdiagnosticKind::NoteOnce,
|
||||||
"help" => SubdiagnosticKind::Help,
|
"help" => SubdiagnosticKind::Help,
|
||||||
|
"help_once" => SubdiagnosticKind::HelpOnce,
|
||||||
"warning" => SubdiagnosticKind::Warn,
|
"warning" => SubdiagnosticKind::Warn,
|
||||||
_ => {
|
_ => {
|
||||||
// Recover old `#[(multipart_)suggestion_*]` syntaxes
|
// Recover old `#[(multipart_)suggestion_*]` syntaxes
|
||||||
|
@ -682,7 +688,9 @@ impl SubdiagnosticVariant {
|
||||||
match kind {
|
match kind {
|
||||||
SubdiagnosticKind::Label
|
SubdiagnosticKind::Label
|
||||||
| SubdiagnosticKind::Note
|
| SubdiagnosticKind::Note
|
||||||
|
| SubdiagnosticKind::NoteOnce
|
||||||
| SubdiagnosticKind::Help
|
| SubdiagnosticKind::Help
|
||||||
|
| SubdiagnosticKind::HelpOnce
|
||||||
| SubdiagnosticKind::Warn
|
| SubdiagnosticKind::Warn
|
||||||
| SubdiagnosticKind::MultipartSuggestion { .. } => {
|
| SubdiagnosticKind::MultipartSuggestion { .. } => {
|
||||||
return Ok(Some(SubdiagnosticVariant { kind, slug: None, no_span: false }));
|
return Ok(Some(SubdiagnosticVariant { kind, slug: None, no_span: false }));
|
||||||
|
@ -836,7 +844,9 @@ impl SubdiagnosticVariant {
|
||||||
}
|
}
|
||||||
SubdiagnosticKind::Label
|
SubdiagnosticKind::Label
|
||||||
| SubdiagnosticKind::Note
|
| SubdiagnosticKind::Note
|
||||||
|
| SubdiagnosticKind::NoteOnce
|
||||||
| SubdiagnosticKind::Help
|
| SubdiagnosticKind::Help
|
||||||
|
| SubdiagnosticKind::HelpOnce
|
||||||
| SubdiagnosticKind::Warn => {}
|
| SubdiagnosticKind::Warn => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -849,7 +859,9 @@ impl quote::IdentFragment for SubdiagnosticKind {
|
||||||
match self {
|
match self {
|
||||||
SubdiagnosticKind::Label => write!(f, "label"),
|
SubdiagnosticKind::Label => write!(f, "label"),
|
||||||
SubdiagnosticKind::Note => write!(f, "note"),
|
SubdiagnosticKind::Note => write!(f, "note"),
|
||||||
|
SubdiagnosticKind::NoteOnce => write!(f, "note_once"),
|
||||||
SubdiagnosticKind::Help => write!(f, "help"),
|
SubdiagnosticKind::Help => write!(f, "help"),
|
||||||
|
SubdiagnosticKind::HelpOnce => write!(f, "help_once"),
|
||||||
SubdiagnosticKind::Warn => write!(f, "warn"),
|
SubdiagnosticKind::Warn => write!(f, "warn"),
|
||||||
SubdiagnosticKind::Suggestion { .. } => write!(f, "suggestions_with_style"),
|
SubdiagnosticKind::Suggestion { .. } => write!(f, "suggestions_with_style"),
|
||||||
SubdiagnosticKind::MultipartSuggestion { .. } => {
|
SubdiagnosticKind::MultipartSuggestion { .. } => {
|
||||||
|
|
|
@ -108,7 +108,9 @@ decl_derive!(
|
||||||
// struct attributes
|
// struct attributes
|
||||||
diag,
|
diag,
|
||||||
help,
|
help,
|
||||||
|
help_once,
|
||||||
note,
|
note,
|
||||||
|
note_once,
|
||||||
warning,
|
warning,
|
||||||
// field attributes
|
// field attributes
|
||||||
skip_arg,
|
skip_arg,
|
||||||
|
@ -125,7 +127,9 @@ decl_derive!(
|
||||||
// struct attributes
|
// struct attributes
|
||||||
diag,
|
diag,
|
||||||
help,
|
help,
|
||||||
|
help_once,
|
||||||
note,
|
note,
|
||||||
|
note_once,
|
||||||
warning,
|
warning,
|
||||||
// field attributes
|
// field attributes
|
||||||
skip_arg,
|
skip_arg,
|
||||||
|
@ -142,7 +146,9 @@ decl_derive!(
|
||||||
// struct/variant attributes
|
// struct/variant attributes
|
||||||
label,
|
label,
|
||||||
help,
|
help,
|
||||||
|
help_once,
|
||||||
note,
|
note,
|
||||||
|
note_once,
|
||||||
warning,
|
warning,
|
||||||
subdiagnostic,
|
subdiagnostic,
|
||||||
suggestion,
|
suggestion,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue