Skip to content

Commit a777c46

Browse files
committed
Use derive(Subdiagnostic) for ChangeFieldsToBeOfUnitType.
1 parent 113e8df commit a777c46

File tree

2 files changed

+4
-25
lines changed

2 files changed

+4
-25
lines changed

compiler/rustc_error_messages/locales/en-US/passes.ftl

+1-2
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,7 @@ passes_change_fields_to_be_of_unit_type =
685685
consider changing the { $num ->
686686
[one] field
687687
*[other] fields
688-
} to be of unit type to suppress this warning
689-
while preserving the field numbering, or remove the { $num ->
688+
} to be of unit type to suppress this warning while preserving the field numbering, or remove the { $num ->
690689
[one] field
691690
*[other] fields
692691
}

compiler/rustc_passes/src/errors.rs

+3-23
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
1212
use rustc_middle::ty::{MainDefinition, Ty};
1313
use rustc_span::{Span, Symbol, DUMMY_SP};
1414

15-
use rustc_errors::{pluralize, AddToDiagnostic, Diagnostic, SubdiagnosticMessage};
16-
1715
use crate::lang_items::Duplicate;
1816

1917
#[derive(LintDiagnostic)]
@@ -1502,28 +1500,10 @@ pub struct IgnoredDerivedImpls {
15021500
pub trait_list_len: usize,
15031501
}
15041502

1503+
#[derive(Subdiagnostic)]
1504+
#[multipart_suggestion(passes_change_fields_to_be_of_unit_type, applicability = "has-placeholders")]
15051505
pub struct ChangeFieldsToBeOfUnitType {
15061506
pub num: usize,
1507+
#[suggestion_part(code = "()")]
15071508
pub spans: Vec<Span>,
15081509
}
1509-
1510-
// FIXME: Replace this impl with a derive.
1511-
impl AddToDiagnostic for ChangeFieldsToBeOfUnitType {
1512-
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
1513-
where
1514-
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
1515-
{
1516-
diag.multipart_suggestion(
1517-
&format!(
1518-
"consider changing the field{s} to be of unit type to \
1519-
suppress this warning while preserving the field \
1520-
numbering, or remove the field{s}",
1521-
s = pluralize!(self.num)
1522-
),
1523-
self.spans.iter().map(|sp| (*sp, "()".to_string())).collect(),
1524-
// "HasPlaceholders" because applying this fix by itself isn't
1525-
// enough: All constructor calls have to be adjusted as well
1526-
Applicability::HasPlaceholders,
1527-
);
1528-
}
1529-
}

0 commit comments

Comments
 (0)