Skip to content

Commit d5caeac

Browse files
authored
Rollup merge of rust-lang#64233 - varkor:correct-pluralisation, r=estebank
Correct pluralisation of various diagnostic messages
2 parents 84cb352 + 0b97726 commit d5caeac

File tree

9 files changed

+42
-22
lines changed

9 files changed

+42
-22
lines changed

src/librustc/ty/error.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ impl<'tcx> ty::TyS<'tcx> {
200200
ty::Array(_, n) => {
201201
let n = tcx.lift_to_global(&n).unwrap();
202202
match n.try_eval_usize(tcx, ty::ParamEnv::empty()) {
203-
Some(n) => format!("array of {} elements", n).into(),
203+
Some(n) => {
204+
format!("array of {} element{}", n, if n != 1 { "s" } else { "" }).into()
205+
}
204206
None => "array".into(),
205207
}
206208
}

src/librustc_typeck/check/pat.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -1098,22 +1098,35 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10981098

10991099
fn error_scrutinee_inconsistent_length(&self, span: Span, min_len: u64, size: u64) {
11001100
struct_span_err!(
1101-
self.tcx.sess, span, E0527,
1102-
"pattern requires {} elements but array has {}",
1103-
min_len, size
1101+
self.tcx.sess,
1102+
span,
1103+
E0527,
1104+
"pattern requires {} element{} but array has {}",
1105+
min_len,
1106+
if min_len != 1 { "s" } else { "" },
1107+
size,
11041108
)
1105-
.span_label(span, format!("expected {} elements", size))
1109+
.span_label(span, format!("expected {} element{}", size, if size != 1 { "s" } else { "" }))
11061110
.emit();
11071111
}
11081112

11091113
fn error_scrutinee_with_rest_inconsistent_length(&self, span: Span, min_len: u64, size: u64) {
11101114
struct_span_err!(
1111-
self.tcx.sess, span, E0528,
1112-
"pattern requires at least {} elements but array has {}",
1113-
min_len, size
1114-
)
1115-
.span_label(span, format!("pattern cannot match array of {} elements", size))
1116-
.emit();
1115+
self.tcx.sess,
1116+
span,
1117+
E0528,
1118+
"pattern requires at least {} element{} but array has {}",
1119+
min_len,
1120+
if min_len != 1 { "s" } else { "" },
1121+
size,
1122+
).span_label(
1123+
span,
1124+
format!(
1125+
"pattern cannot match array of {} element{}",
1126+
size,
1127+
if size != 1 { "s" } else { "" },
1128+
),
1129+
).emit();
11171130
}
11181131

11191132
fn error_scrutinee_unfixed_length(&self, span: Span) {

src/libsyntax/ext/tt/transcribe.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,13 @@ impl LockstepIterSize {
345345
LockstepIterSize::Constraint(r_len, _) if l_len == r_len => self,
346346
LockstepIterSize::Constraint(r_len, r_id) => {
347347
let msg = format!(
348-
"meta-variable `{}` repeats {} times, but `{}` repeats {} times",
349-
l_id, l_len, r_id, r_len
348+
"meta-variable `{}` repeats {} time{}, but `{}` repeats {} time{}",
349+
l_id,
350+
l_len,
351+
if l_len != 1 { "s" } else { "" },
352+
r_id,
353+
r_len,
354+
if r_len != 1 { "s" } else { "" },
350355
);
351356
LockstepIterSize::Contradiction(msg)
352357
}

src/libsyntax_ext/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl<'a, 'b> Context<'a, 'b> {
291291
&format!(
292292
"{} positional argument{} in format string, but {}",
293293
count,
294-
if count > 1 { "s" } else { "" },
294+
if count != 1 { "s" } else { "" },
295295
self.describe_num_args(),
296296
),
297297
);

src/test/ui/coercion/coercion-slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ fn main() {
44
let _: &[i32] = [0];
55
//~^ ERROR mismatched types
66
//~| expected type `&[i32]`
7-
//~| expected &[i32], found array of 1 elements
7+
//~| expected &[i32], found array of 1 element
88
}

src/test/ui/coercion/coercion-slice.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0308]: mismatched types
44
LL | let _: &[i32] = [0];
55
| ^^^
66
| |
7-
| expected &[i32], found array of 1 elements
7+
| expected &[i32], found array of 1 element
88
| help: consider borrowing here: `&[0]`
99
|
1010
= note: expected type `&[i32]`

src/test/ui/issues/issue-15783.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ fn main() {
66
let name = "Foo";
77
let x = Some(&[name]);
88
let msg = foo(x);
9-
//~^ ERROR mismatched types
10-
//~| expected type `std::option::Option<&[&str]>`
11-
//~| found type `std::option::Option<&[&str; 1]>`
12-
//~| expected slice, found array of 1 elements
9+
//~^ ERROR mismatched types
10+
//~| expected type `std::option::Option<&[&str]>`
11+
//~| found type `std::option::Option<&[&str; 1]>`
12+
//~| expected slice, found array of 1 element
1313
assert_eq!(msg, 3);
1414
}

src/test/ui/issues/issue-15783.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-15783.rs:8:19
33
|
44
LL | let msg = foo(x);
5-
| ^ expected slice, found array of 1 elements
5+
| ^ expected slice, found array of 1 element
66
|
77
= note: expected type `std::option::Option<&[&str]>`
88
found type `std::option::Option<&[&str; 1]>`

src/test/ui/match/match-vec-mismatch.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0529]: expected an array or slice, found `std::string::String`
1010
LL | ['f', 'o', ..] => {}
1111
| ^^^^^^^^^^^^^^ pattern cannot match with input type `std::string::String`
1212

13-
error[E0527]: pattern requires 1 elements but array has 3
13+
error[E0527]: pattern requires 1 element but array has 3
1414
--> $DIR/match-vec-mismatch.rs:20:9
1515
|
1616
LL | [0] => {},

0 commit comments

Comments
 (0)