Rename some Diagnostic
setters.
`Diagnostic` has 40 methods that return `&mut Self` and could be considered setters. Four of them have a `set_` prefix. This doesn't seem necessary for a type that implements the builder pattern. This commit removes the `set_` prefixes on those four methods.
This commit is contained in:
parent
e51e98dde6
commit
505c1371d0
53 changed files with 274 additions and 281 deletions
|
@ -5,8 +5,8 @@ use crate::diagnostics::error::{
|
|||
};
|
||||
use crate::diagnostics::utils::{
|
||||
build_field_mapping, is_doc_comment, report_error_if_not_applied_to_span, report_type_error,
|
||||
should_generate_set_arg, type_is_bool, type_is_unit, type_matches_path, FieldInfo,
|
||||
FieldInnerTy, FieldMap, HasFieldMap, SetOnce, SpannedOption, SubdiagnosticKind,
|
||||
should_generate_arg, type_is_bool, type_is_unit, type_matches_path, FieldInfo, FieldInnerTy,
|
||||
FieldMap, HasFieldMap, SetOnce, SpannedOption, SubdiagnosticKind,
|
||||
};
|
||||
use proc_macro2::{Ident, Span, TokenStream};
|
||||
use quote::{format_ident, quote, quote_spanned};
|
||||
|
@ -125,15 +125,15 @@ impl DiagnosticDeriveVariantBuilder {
|
|||
}
|
||||
|
||||
/// Generates calls to `span_label` and similar functions based on the attributes on fields or
|
||||
/// calls to `set_arg` when no attributes are present.
|
||||
/// calls to `arg` when no attributes are present.
|
||||
pub(crate) fn body(&mut self, variant: &VariantInfo<'_>) -> TokenStream {
|
||||
let mut body = quote! {};
|
||||
// Generate `set_arg` calls first..
|
||||
for binding in variant.bindings().iter().filter(|bi| should_generate_set_arg(bi.ast())) {
|
||||
// Generate `arg` calls first..
|
||||
for binding in variant.bindings().iter().filter(|bi| should_generate_arg(bi.ast())) {
|
||||
body.extend(self.generate_field_code(binding));
|
||||
}
|
||||
// ..and then subdiagnostic additions.
|
||||
for binding in variant.bindings().iter().filter(|bi| !should_generate_set_arg(bi.ast())) {
|
||||
for binding in variant.bindings().iter().filter(|bi| !should_generate_arg(bi.ast())) {
|
||||
body.extend(self.generate_field_attrs_code(binding));
|
||||
}
|
||||
body
|
||||
|
@ -253,7 +253,7 @@ impl DiagnosticDeriveVariantBuilder {
|
|||
let ident = format_ident!("{}", ident); // strip `r#` prefix, if present
|
||||
|
||||
quote! {
|
||||
diag.set_arg(
|
||||
diag.arg(
|
||||
stringify!(#ident),
|
||||
#field_binding
|
||||
);
|
||||
|
@ -312,7 +312,7 @@ impl DiagnosticDeriveVariantBuilder {
|
|||
let name = ident.to_string();
|
||||
match (&attr.meta, name.as_str()) {
|
||||
// Don't need to do anything - by virtue of the attribute existing, the
|
||||
// `set_arg` call will not be generated.
|
||||
// `arg` call will not be generated.
|
||||
(Meta::Path(_), "skip_arg") => return Ok(quote! {}),
|
||||
(Meta::Path(_), "primary_span") => {
|
||||
match self.kind {
|
||||
|
@ -320,7 +320,7 @@ impl DiagnosticDeriveVariantBuilder {
|
|||
report_error_if_not_applied_to_span(attr, &info)?;
|
||||
|
||||
return Ok(quote! {
|
||||
diag.set_span(#binding);
|
||||
diag.span(#binding);
|
||||
});
|
||||
}
|
||||
DiagnosticDeriveKind::LintDiagnostic => {
|
||||
|
|
|
@ -6,8 +6,8 @@ use crate::diagnostics::error::{
|
|||
use crate::diagnostics::utils::{
|
||||
build_field_mapping, build_suggestion_code, is_doc_comment, new_code_ident,
|
||||
report_error_if_not_applied_to_applicability, report_error_if_not_applied_to_span,
|
||||
should_generate_set_arg, AllowMultipleAlternatives, FieldInfo, FieldInnerTy, FieldMap,
|
||||
HasFieldMap, SetOnce, SpannedOption, SubdiagnosticKind,
|
||||
should_generate_arg, AllowMultipleAlternatives, FieldInfo, FieldInnerTy, FieldMap, HasFieldMap,
|
||||
SetOnce, SpannedOption, SubdiagnosticKind,
|
||||
};
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
|
@ -214,7 +214,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
|
|||
}
|
||||
|
||||
/// Generates the code for a field with no attributes.
|
||||
fn generate_field_set_arg(&mut self, binding_info: &BindingInfo<'_>) -> TokenStream {
|
||||
fn generate_field_arg(&mut self, binding_info: &BindingInfo<'_>) -> TokenStream {
|
||||
let diag = &self.parent.diag;
|
||||
|
||||
let field = binding_info.ast();
|
||||
|
@ -225,7 +225,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
|
|||
let ident = format_ident!("{}", ident); // strip `r#` prefix, if present
|
||||
|
||||
quote! {
|
||||
#diag.set_arg(
|
||||
#diag.arg(
|
||||
stringify!(#ident),
|
||||
#field_binding
|
||||
);
|
||||
|
@ -505,7 +505,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
|
|||
.variant
|
||||
.bindings()
|
||||
.iter()
|
||||
.filter(|binding| !should_generate_set_arg(binding.ast()))
|
||||
.filter(|binding| !should_generate_arg(binding.ast()))
|
||||
.map(|binding| self.generate_field_attr_code(binding, kind_stats))
|
||||
.collect();
|
||||
|
||||
|
@ -593,8 +593,8 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
|
|||
.variant
|
||||
.bindings()
|
||||
.iter()
|
||||
.filter(|binding| should_generate_set_arg(binding.ast()))
|
||||
.map(|binding| self.generate_field_set_arg(binding))
|
||||
.filter(|binding| should_generate_arg(binding.ast()))
|
||||
.map(|binding| self.generate_field_arg(binding))
|
||||
.collect();
|
||||
|
||||
let formatting_init = &self.formatting_init;
|
||||
|
|
|
@ -584,7 +584,7 @@ pub(super) enum SubdiagnosticKind {
|
|||
suggestion_kind: SuggestionKind,
|
||||
applicability: SpannedOption<Applicability>,
|
||||
/// Identifier for variable used for formatted code, e.g. `___code_0`. Enables separation
|
||||
/// of formatting and diagnostic emission so that `set_arg` calls can happen in-between..
|
||||
/// of formatting and diagnostic emission so that `arg` calls can happen in-between..
|
||||
code_field: syn::Ident,
|
||||
/// Initialization logic for `code_field`'s variable, e.g.
|
||||
/// `let __formatted_code = /* whatever */;`
|
||||
|
@ -863,9 +863,9 @@ impl quote::IdentFragment for SubdiagnosticKind {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if `field` should generate a `set_arg` call rather than any other diagnostic
|
||||
/// Returns `true` if `field` should generate a `arg` call rather than any other diagnostic
|
||||
/// call (like `span_label`).
|
||||
pub(super) fn should_generate_set_arg(field: &Field) -> bool {
|
||||
pub(super) fn should_generate_arg(field: &Field) -> bool {
|
||||
// Perhaps this should be an exhaustive list...
|
||||
field.attrs.iter().all(|attr| is_doc_comment(attr))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue