mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-21 22:34:05 +00:00
Add note_once/help_once to diagnostic derives
This commit is contained in:
parent
56bca95875
commit
eee14e9adf
@ -158,7 +158,9 @@ impl DiagnosticDeriveVariantBuilder {
|
||||
let slug = subdiag.slug.unwrap_or_else(|| match subdiag.kind {
|
||||
SubdiagnosticKind::Label => parse_quote! { _subdiag::label },
|
||||
SubdiagnosticKind::Note => parse_quote! { _subdiag::note },
|
||||
SubdiagnosticKind::NoteOnce => parse_quote! { _subdiag::note_once },
|
||||
SubdiagnosticKind::Help => parse_quote! { _subdiag::help },
|
||||
SubdiagnosticKind::HelpOnce => parse_quote! { _subdiag::help_once },
|
||||
SubdiagnosticKind::Warn => parse_quote! { _subdiag::warn },
|
||||
SubdiagnosticKind::Suggestion { .. } => parse_quote! { _subdiag::suggestion },
|
||||
SubdiagnosticKind::MultipartSuggestion { .. } => unreachable!(),
|
||||
@ -233,9 +235,11 @@ impl DiagnosticDeriveVariantBuilder {
|
||||
};
|
||||
let fn_ident = format_ident!("{}", subdiag);
|
||||
match subdiag {
|
||||
SubdiagnosticKind::Note | SubdiagnosticKind::Help | SubdiagnosticKind::Warn => {
|
||||
Ok(self.add_subdiagnostic(&fn_ident, slug))
|
||||
}
|
||||
SubdiagnosticKind::Note
|
||||
| SubdiagnosticKind::NoteOnce
|
||||
| SubdiagnosticKind::Help
|
||||
| SubdiagnosticKind::HelpOnce
|
||||
| SubdiagnosticKind::Warn => Ok(self.add_subdiagnostic(&fn_ident, slug)),
|
||||
SubdiagnosticKind::Label | SubdiagnosticKind::Suggestion { .. } => {
|
||||
throw_invalid_attr!(attr, |diag| diag
|
||||
.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)?;
|
||||
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();
|
||||
if type_matches_path(inner, &["rustc_span", "Span"])
|
||||
|| type_matches_path(inner, &["rustc_span", "MultiSpan"])
|
||||
|
@ -575,8 +575,12 @@ pub(super) enum SubdiagnosticKind {
|
||||
Label,
|
||||
/// `#[note(...)]`
|
||||
Note,
|
||||
/// `#[note_once(...)]`
|
||||
NoteOnce,
|
||||
/// `#[help(...)]`
|
||||
Help,
|
||||
/// `#[help_once(...)]`
|
||||
HelpOnce,
|
||||
/// `#[warning(...)]`
|
||||
Warn,
|
||||
/// `#[suggestion{,_short,_hidden,_verbose}]`
|
||||
@ -624,7 +628,9 @@ impl SubdiagnosticVariant {
|
||||
let mut kind = match name {
|
||||
"label" => SubdiagnosticKind::Label,
|
||||
"note" => SubdiagnosticKind::Note,
|
||||
"note_once" => SubdiagnosticKind::NoteOnce,
|
||||
"help" => SubdiagnosticKind::Help,
|
||||
"help_once" => SubdiagnosticKind::HelpOnce,
|
||||
"warning" => SubdiagnosticKind::Warn,
|
||||
_ => {
|
||||
// Recover old `#[(multipart_)suggestion_*]` syntaxes
|
||||
@ -682,7 +688,9 @@ impl SubdiagnosticVariant {
|
||||
match kind {
|
||||
SubdiagnosticKind::Label
|
||||
| SubdiagnosticKind::Note
|
||||
| SubdiagnosticKind::NoteOnce
|
||||
| SubdiagnosticKind::Help
|
||||
| SubdiagnosticKind::HelpOnce
|
||||
| SubdiagnosticKind::Warn
|
||||
| SubdiagnosticKind::MultipartSuggestion { .. } => {
|
||||
return Ok(Some(SubdiagnosticVariant { kind, slug: None, no_span: false }));
|
||||
@ -836,7 +844,9 @@ impl SubdiagnosticVariant {
|
||||
}
|
||||
SubdiagnosticKind::Label
|
||||
| SubdiagnosticKind::Note
|
||||
| SubdiagnosticKind::NoteOnce
|
||||
| SubdiagnosticKind::Help
|
||||
| SubdiagnosticKind::HelpOnce
|
||||
| SubdiagnosticKind::Warn => {}
|
||||
}
|
||||
|
||||
@ -849,7 +859,9 @@ impl quote::IdentFragment for SubdiagnosticKind {
|
||||
match self {
|
||||
SubdiagnosticKind::Label => write!(f, "label"),
|
||||
SubdiagnosticKind::Note => write!(f, "note"),
|
||||
SubdiagnosticKind::NoteOnce => write!(f, "note_once"),
|
||||
SubdiagnosticKind::Help => write!(f, "help"),
|
||||
SubdiagnosticKind::HelpOnce => write!(f, "help_once"),
|
||||
SubdiagnosticKind::Warn => write!(f, "warn"),
|
||||
SubdiagnosticKind::Suggestion { .. } => write!(f, "suggestions_with_style"),
|
||||
SubdiagnosticKind::MultipartSuggestion { .. } => {
|
||||
|
@ -108,7 +108,9 @@ decl_derive!(
|
||||
// struct attributes
|
||||
diag,
|
||||
help,
|
||||
help_once,
|
||||
note,
|
||||
note_once,
|
||||
warning,
|
||||
// field attributes
|
||||
skip_arg,
|
||||
@ -125,7 +127,9 @@ decl_derive!(
|
||||
// struct attributes
|
||||
diag,
|
||||
help,
|
||||
help_once,
|
||||
note,
|
||||
note_once,
|
||||
warning,
|
||||
// field attributes
|
||||
skip_arg,
|
||||
@ -142,7 +146,9 @@ decl_derive!(
|
||||
// struct/variant attributes
|
||||
label,
|
||||
help,
|
||||
help_once,
|
||||
note,
|
||||
note_once,
|
||||
warning,
|
||||
subdiagnostic,
|
||||
suggestion,
|
||||
|
Loading…
Reference in New Issue
Block a user