Use derive(Subdiagnostic) for ChangeFieldsToBeOfUnitType.

This commit is contained in:
Charles Lew 2022-11-04 03:02:09 +08:00
parent 113e8dfb72
commit a777c46dff
2 changed files with 4 additions and 25 deletions

View File

@ -685,8 +685,7 @@ passes_change_fields_to_be_of_unit_type =
consider changing the { $num ->
[one] field
*[other] fields
} to be of unit type to suppress this warning
while preserving the field numbering, or remove the { $num ->
} to be of unit type to suppress this warning while preserving the field numbering, or remove the { $num ->
[one] field
*[other] fields
}

View File

@ -12,8 +12,6 @@ use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::{MainDefinition, Ty};
use rustc_span::{Span, Symbol, DUMMY_SP};
use rustc_errors::{pluralize, AddToDiagnostic, Diagnostic, SubdiagnosticMessage};
use crate::lang_items::Duplicate;
#[derive(LintDiagnostic)]
@ -1502,28 +1500,10 @@ pub struct IgnoredDerivedImpls {
pub trait_list_len: usize,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(passes_change_fields_to_be_of_unit_type, applicability = "has-placeholders")]
pub struct ChangeFieldsToBeOfUnitType {
pub num: usize,
#[suggestion_part(code = "()")]
pub spans: Vec<Span>,
}
// FIXME: Replace this impl with a derive.
impl AddToDiagnostic for ChangeFieldsToBeOfUnitType {
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
diag.multipart_suggestion(
&format!(
"consider changing the field{s} to be of unit type to \
suppress this warning while preserving the field \
numbering, or remove the field{s}",
s = pluralize!(self.num)
),
self.spans.iter().map(|sp| (*sp, "()".to_string())).collect(),
// "HasPlaceholders" because applying this fix by itself isn't
// enough: All constructor calls have to be adjusted as well
Applicability::HasPlaceholders,
);
}
}