Skip to content

Commit

Permalink
Correct pluralisation of various diagnostic messages
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Sep 6, 2019
1 parent 4894123 commit f6481ed
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/librustc/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ impl<'tcx> ty::TyS<'tcx> {
ty::Array(_, n) => {
let n = tcx.lift_to_global(&n).unwrap();
match n.try_eval_usize(tcx, ty::ParamEnv::empty()) {
Some(n) => format!("array of {} elements", n).into(),
Some(n) => {
format!("array of {} element{}", n, if n != 1 { "s" } else { "" }).into()
}
None => "array".into(),
}
}
Expand Down
33 changes: 23 additions & 10 deletions src/librustc_typeck/check/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,22 +1098,35 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

fn error_scrutinee_inconsistent_length(&self, span: Span, min_len: u64, size: u64) {
struct_span_err!(
self.tcx.sess, span, E0527,
"pattern requires {} elements but array has {}",
min_len, size
self.tcx.sess,
span,
E0527,
"pattern requires {} element{} but array has {}",
min_len,
if min_len != 1 { "s" } else { "" },
size,
)
.span_label(span, format!("expected {} elements", size))
.span_label(span, format!("expected {} element{}", size, if size != 1 { "s" } else { "" }))
.emit();
}

fn error_scrutinee_with_rest_inconsistent_length(&self, span: Span, min_len: u64, size: u64) {
struct_span_err!(
self.tcx.sess, span, E0528,
"pattern requires at least {} elements but array has {}",
min_len, size
)
.span_label(span, format!("pattern cannot match array of {} elements", size))
.emit();
self.tcx.sess,
span,
E0528,
"pattern requires at least {} element{} but array has {}",
min_len,
if min_len != 1 { "s" } else { "" },
size,
).span_label(
span,
format!(
"pattern cannot match array of {} element{}",
size,
if size != 1 { "s" } else { "" },
),
).emit();
}

fn error_scrutinee_unfixed_length(&self, span: Span) {
Expand Down
9 changes: 7 additions & 2 deletions src/libsyntax/ext/tt/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,13 @@ impl LockstepIterSize {
LockstepIterSize::Constraint(r_len, _) if l_len == r_len => self,
LockstepIterSize::Constraint(r_len, r_id) => {
let msg = format!(
"meta-variable `{}` repeats {} times, but `{}` repeats {} times",
l_id, l_len, r_id, r_len
"meta-variable `{}` repeats {} time{}, but `{}` repeats {} time{}",
l_id,
l_len,
if l_len != 1 { "s" } else { "" },
r_id,
r_len,
if r_len != 1 { "s" } else { "" },
);
LockstepIterSize::Contradiction(msg)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl<'a, 'b> Context<'a, 'b> {
&format!(
"{} positional argument{} in format string, but {}",
count,
if count > 1 { "s" } else { "" },
if count != 1 { "s" } else { "" },
self.describe_num_args(),
),
);
Expand Down

0 comments on commit f6481ed

Please sign in to comment.