Skip to content

Commit 56181cf

Browse files
committed
Correct pluralisation of tuple/array/associated type binding mismatch errors
1 parent 8549953 commit 56181cf

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

src/librustc/ty/error.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
8080
}
8181
};
8282

83+
macro_rules! pluralise {
84+
($x:expr) => {
85+
if $x != 1 { "s" } else { "" }
86+
};
87+
}
88+
8389
match *self {
8490
CyclicTy(_) => write!(f, "cyclic type of infinite size"),
8591
Mismatch => write!(f, "types differ"),
@@ -95,16 +101,20 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
95101
}
96102
Mutability => write!(f, "types differ in mutability"),
97103
TupleSize(values) => {
98-
write!(f, "expected a tuple with {} elements, \
99-
found one with {} elements",
104+
write!(f, "expected a tuple with {} element{}, \
105+
found one with {} element{}",
100106
values.expected,
101-
values.found)
107+
pluralise!(values.expected),
108+
values.found,
109+
pluralise!(values.found))
102110
}
103111
FixedArraySize(values) => {
104-
write!(f, "expected an array with a fixed size of {} elements, \
105-
found one with {} elements",
112+
write!(f, "expected an array with a fixed size of {} element{}, \
113+
found one with {} element{}",
106114
values.expected,
107-
values.found)
115+
pluralise!(values.expected),
116+
values.found,
117+
pluralise!(values.found))
108118
}
109119
ArgCount => {
110120
write!(f, "incorrect number of function parameters")
@@ -157,8 +167,9 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
157167
tcx.def_path_str(values.found))
158168
}),
159169
ProjectionBoundsLength(ref values) => {
160-
write!(f, "expected {} associated type bindings, found {}",
170+
write!(f, "expected {} associated type binding{}, found {}",
161171
values.expected,
172+
pluralise!(values.expected),
162173
values.found)
163174
},
164175
ExistentialMismatch(ref values) => {

src/test/ui/consts/const-array-oob-arith.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/const-array-oob-arith.rs:7:45
33
|
44
LL | const BLUB: [i32; (ARR[0] - 40) as usize] = [5];
5-
| ^^^ expected an array with a fixed size of 2 elements, found one with 1 elements
5+
| ^^^ expected an array with a fixed size of 2 elements, found one with 1 element
66
|
77
= note: expected type `[i32; 2]`
88
found type `[i32; 1]`
@@ -11,7 +11,7 @@ error[E0308]: mismatched types
1111
--> $DIR/const-array-oob-arith.rs:8:44
1212
|
1313
LL | const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99];
14-
| ^^^^^^^ expected an array with a fixed size of 1 elements, found one with 2 elements
14+
| ^^^^^^^ expected an array with a fixed size of 1 element, found one with 2 elements
1515
|
1616
= note: expected type `[i32; 1]`
1717
found type `[i32; 2]`

src/test/ui/tuple/tuple-arity-mismatch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ fn main() {
1313
//~^ ERROR mismatched types
1414
//~| expected type `(isize, f64)`
1515
//~| found type `(isize,)`
16-
//~| expected a tuple with 2 elements, found one with 1 elements
16+
//~| expected a tuple with 2 elements, found one with 1 element
1717
}

src/test/ui/tuple/tuple-arity-mismatch.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ error[E0308]: mismatched types
1111
--> $DIR/tuple-arity-mismatch.rs:12:20
1212
|
1313
LL | let y = first ((1,));
14-
| ^^^^ expected a tuple with 2 elements, found one with 1 elements
14+
| ^^^^ expected a tuple with 2 elements, found one with 1 element
1515
|
1616
= note: expected type `(isize, f64)`
1717
found type `(isize,)`

0 commit comments

Comments
 (0)