Skip to content

Commit ddd326f

Browse files
committed
use pluralize!
1 parent 3ae03e0 commit ddd326f

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
634634
&format!(
635635
"expected a closure taking {} argument{}, but one taking {} argument{} was given",
636636
given.len(),
637-
if given.len() == 1 { "" } else { "s" },
637+
pluralize!(given.len()),
638638
expected.len(),
639-
if expected.len() == 1 { "" } else { "s" },
639+
pluralize!(expected.len()),
640640
)
641641
);
642642
} else if !self.same_type_modulo_infer(given_ty, expected_ty) {

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::check::{
1515
use crate::structured_errors::StructuredDiagnostic;
1616

1717
use rustc_ast as ast;
18-
use rustc_errors::{Applicability, Diagnostic, DiagnosticId, MultiSpan};
18+
use rustc_errors::{pluralize, Applicability, Diagnostic, DiagnosticId, MultiSpan};
1919
use rustc_hir as hir;
2020
use rustc_hir::def::{CtorOf, DefKind, Res};
2121
use rustc_hir::def_id::DefId;
@@ -645,7 +645,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
645645
"argument"
646646
),
647647
potentially_plural_count(provided_args.len(), "argument"),
648-
if provided_args.len() == 1 { "was" } else { "were" }
648+
pluralize!("was", provided_args.len())
649649
),
650650
DiagnosticId::Error(err_code.to_owned()),
651651
);
@@ -770,7 +770,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
770770
if c_variadic { "at least " } else { "" },
771771
potentially_plural_count(formal_and_expected_inputs.len(), "argument"),
772772
potentially_plural_count(provided_args.len(), "argument"),
773-
if provided_args.len() == 1 { "was" } else { "were" }
773+
pluralize!("was", provided_args.len())
774774
),
775775
DiagnosticId::Error(err_code.to_owned()),
776776
)

compiler/rustc_typeck/src/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11231123
add a `use` for {one_of_them}:",
11241124
an = if candidates.len() == 1 { "an" } else { "" },
11251125
s = pluralize!(candidates.len()),
1126-
were = if candidates.len() == 1 { "was" } else { "were" },
1126+
were = pluralize!("was", candidates.len()),
11271127
one_of_them = if candidates.len() == 1 { "it" } else { "one_of_them" },
11281128
);
11291129
self.suggest_use_candidates(&mut err, help, candidates);

compiler/rustc_typeck/src/check/wfcheck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::check::regionck::OutlivesEnvironmentExt;
22
use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter};
33
use rustc_ast as ast;
44
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5-
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed};
5+
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed};
66
use rustc_hir as hir;
77
use rustc_hir::def_id::{DefId, LocalDefId};
88
use rustc_hir::lang_items::LangItem;
@@ -474,7 +474,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
474474
unsatisfied_bounds.sort();
475475

476476
if !unsatisfied_bounds.is_empty() {
477-
let plural = if unsatisfied_bounds.len() > 1 { "s" } else { "" };
477+
let plural = pluralize!(unsatisfied_bounds.len());
478478
let mut err = tcx.sess.struct_span_err(
479479
gat_item_hir.span,
480480
&format!("missing required bound{} on `{}`", plural, gat_item_hir.ident),

compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -420,20 +420,18 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
420420
let provided_lt_args = self.num_provided_lifetime_args();
421421
let provided_type_or_const_args = self.num_provided_type_or_const_args();
422422

423-
let get_verb = |num_args| if num_args == 1 { "was" } else { "were" };
424-
425423
let (provided_args_str, verb) = match self.gen_args_info {
426424
MissingLifetimes { .. } | ExcessLifetimes { .. } => (
427425
format!("{} lifetime argument{}", provided_lt_args, pluralize!(provided_lt_args)),
428-
get_verb(provided_lt_args),
426+
pluralize!("was", provided_lt_args),
429427
),
430428
MissingTypesOrConsts { .. } | ExcessTypesOrConsts { .. } => (
431429
format!(
432430
"{} generic argument{}",
433431
provided_type_or_const_args,
434432
pluralize!(provided_type_or_const_args)
435433
),
436-
get_verb(provided_type_or_const_args),
434+
pluralize!("was", provided_type_or_const_args),
437435
),
438436
};
439437

0 commit comments

Comments
 (0)