diff options
| author | Charles Lew <crlf0710@gmail.com> | 2022-11-04 03:02:09 +0800 |
|---|---|---|
| committer | Charles Lew <crlf0710@gmail.com> | 2022-11-04 03:02:09 +0800 |
| commit | a777c46dff4fdb54e29a19e273d8677d485232e6 (patch) | |
| tree | 77f897f5a90aab53cea0fdd11fec1a9437b5e3d5 | |
| parent | 113e8dfb7293cc070214b42541781b2eeac25ae1 (diff) | |
| download | rust-a777c46dff4fdb54e29a19e273d8677d485232e6.tar.gz rust-a777c46dff4fdb54e29a19e273d8677d485232e6.zip | |
Use `derive(Subdiagnostic)` for `ChangeFieldsToBeOfUnitType`.
| -rw-r--r-- | compiler/rustc_error_messages/locales/en-US/passes.ftl | 3 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/errors.rs | 26 |
2 files changed, 4 insertions, 25 deletions
diff --git a/compiler/rustc_error_messages/locales/en-US/passes.ftl b/compiler/rustc_error_messages/locales/en-US/passes.ftl index a5b002fa357..a7cb9f14e82 100644 --- a/compiler/rustc_error_messages/locales/en-US/passes.ftl +++ b/compiler/rustc_error_messages/locales/en-US/passes.ftl @@ -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 } diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index d39d7629b28..83a51bcd097 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -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, - ); - } -} |
