Skip to content

Commit

Permalink
Use derive(Subdiagnostic) for ChangeFieldsToBeOfUnitType.
Browse files Browse the repository at this point in the history
  • Loading branch information
crlf0710 committed Nov 3, 2022
1 parent 113e8df commit a777c46
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
3 changes: 1 addition & 2 deletions compiler/rustc_error_messages/locales/en-US/passes.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
26 changes: 3 additions & 23 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
);
}
}

0 comments on commit a777c46

Please sign in to comment.