Support other types of pluralization in pluralize macro
This commit is contained in:
parent
bce19cf7f1
commit
3bf9124f14
8 changed files with 26 additions and 23 deletions
|
@ -1761,7 +1761,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
sp,
|
||||
&format!(
|
||||
"include the missing field{} in the pattern{}",
|
||||
if len == 1 { "" } else { "s" },
|
||||
pluralize!(len),
|
||||
if have_inaccessible_fields { " and ignore the inaccessible fields" } else { "" }
|
||||
),
|
||||
format!(
|
||||
|
@ -1780,10 +1780,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
err.span_suggestion(
|
||||
sp,
|
||||
&format!(
|
||||
"if you don't care about {} missing field{}, you can explicitly ignore {}",
|
||||
if len == 1 { "this" } else { "these" },
|
||||
if len == 1 { "" } else { "s" },
|
||||
if len == 1 { "it" } else { "them" },
|
||||
"if you don't care about {these} missing field{s}, you can explicitly ignore {them}",
|
||||
these = pluralize!("this", len),
|
||||
s = pluralize!(len),
|
||||
them = if len == 1 { "it" } else { "them" },
|
||||
),
|
||||
format!("{}..{}", prefix, postfix),
|
||||
Applicability::MachineApplicable,
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
//! `tcx.inherent_impls(def_id)`). That value, however,
|
||||
//! is computed by selecting an idea from this table.
|
||||
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_errors::{pluralize, struct_span_err};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
|
@ -410,7 +410,6 @@ impl<'tcx> InherentCollect<'tcx> {
|
|||
let to_implement = if assoc_items.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
let plural = assoc_items.len() > 1;
|
||||
let assoc_items_kind = {
|
||||
let item_types = assoc_items.iter().map(|x| x.kind);
|
||||
if item_types.clone().all(|x| x == hir::AssocItemKind::Const) {
|
||||
|
@ -427,9 +426,9 @@ impl<'tcx> InherentCollect<'tcx> {
|
|||
|
||||
format!(
|
||||
" to implement {} {}{}",
|
||||
if plural { "these" } else { "this" },
|
||||
pluralize!("this", assoc_items.len()),
|
||||
assoc_items_kind,
|
||||
if plural { "s" } else { "" }
|
||||
pluralize!(assoc_items.len()),
|
||||
)
|
||||
};
|
||||
|
||||
|
|
|
@ -657,10 +657,9 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
|
||||
let num_redundant_lt_args = lt_arg_spans.len() - self.num_expected_lifetime_args();
|
||||
let msg_lifetimes = format!(
|
||||
"remove {} {} argument{}",
|
||||
if num_redundant_lt_args == 1 { "this" } else { "these" },
|
||||
"lifetime",
|
||||
pluralize!(num_redundant_lt_args),
|
||||
"remove {these} lifetime argument{s}",
|
||||
these = pluralize!("this", num_redundant_lt_args),
|
||||
s = pluralize!(num_redundant_lt_args),
|
||||
);
|
||||
|
||||
err.span_suggestion(
|
||||
|
@ -700,10 +699,9 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
let num_redundant_gen_args =
|
||||
gen_arg_spans.len() - self.num_expected_type_or_const_args();
|
||||
let msg_types_or_consts = format!(
|
||||
"remove {} {} argument{}",
|
||||
if num_redundant_gen_args == 1 { "this" } else { "these" },
|
||||
"generic",
|
||||
pluralize!(num_redundant_type_or_const_args),
|
||||
"remove {these} generic argument{s}",
|
||||
these = pluralize!("this", num_redundant_gen_args),
|
||||
s = pluralize!(num_redundant_gen_args),
|
||||
);
|
||||
|
||||
err.span_suggestion(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue