Rollup merge of #64342 - glorv:master, r=varkor

factor out pluralisation remains after #64280

there are two case that doesn't not match the original macro pattern at [here](https://github.com/rust-lang/rust/blob/master/src/librustc_lint/unused.rs#L146) and [here](https://github.com/rust-lang/rust/blob/master/src/libsyntax/parse/diagnostics.rs#L539) as the provided param is already a bool or the check condition is not `x != 1`, so I change the macro accept a boolean expr instead of number to fit all the cases.

@Centril  please review

Fixes #64238.
This commit is contained in:
Mazdak Farrokhzad 2019-09-21 16:01:26 +02:00 committed by GitHub
commit d021dba048
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 56 additions and 45 deletions

View file

@ -7,7 +7,7 @@
use crate::lint::{LintPass, LateLintPass, LintArray};
use crate::middle::stability;
use crate::session::Session;
use errors::{Applicability, DiagnosticBuilder};
use errors::{Applicability, DiagnosticBuilder, pluralise};
use syntax::ast;
use syntax::source_map::Span;
use syntax::symbol::Symbol;
@ -524,7 +524,7 @@ pub(crate) fn add_elided_lifetime_in_path_suggestion(
};
db.span_suggestion(
replace_span,
&format!("indicate the anonymous lifetime{}", if n >= 2 { "s" } else { "" }),
&format!("indicate the anonymous lifetime{}", pluralise!(n)),
suggestion,
Applicability::MachineApplicable
);

View file

@ -17,7 +17,7 @@ use crate::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt};
use crate::rustc::lint;
use crate::session::Session;
use crate::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, HirIdSet};
use errors::{Applicability, DiagnosticBuilder};
use errors::{Applicability, DiagnosticBuilder, pluralise};
use rustc_macros::HashStable;
use std::borrow::Cow;
use std::cell::Cell;
@ -3047,7 +3047,7 @@ pub fn report_missing_lifetime_specifiers(
span,
E0106,
"missing lifetime specifier{}",
if count > 1 { "s" } else { "" }
pluralise!(count)
)
}

View file

@ -33,7 +33,7 @@ use crate::ty::subst::Subst;
use crate::ty::SubtypePredicate;
use crate::util::nodemap::{FxHashMap, FxHashSet};
use errors::{Applicability, DiagnosticBuilder};
use errors::{Applicability, DiagnosticBuilder, pluralise};
use std::fmt;
use syntax::ast;
use syntax::symbol::{sym, kw};
@ -1214,7 +1214,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
_ => format!("{} {}argument{}",
arg_length,
if distinct && arg_length > 1 { "distinct " } else { "" },
if arg_length == 1 { "" } else { "s" }),
pluralise!(arg_length))
}
};

View file

@ -196,7 +196,7 @@ impl<'tcx> ty::TyS<'tcx> {
let n = tcx.lift_to_global(&n).unwrap();
match n.try_eval_usize(tcx, ty::ParamEnv::empty()) {
Some(n) => {
format!("array of {} element{}", n, if n != 1 { "s" } else { "" }).into()
format!("array of {} element{}", n, pluralise!(n)).into()
}
None => "array".into(),
}