mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Correct pluralisation of tuple/array/associated type binding mismatch errors
This commit is contained in:
parent
854995313a
commit
56181cf8ab
@ -80,6 +80,12 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
|
||||
}
|
||||
};
|
||||
|
||||
macro_rules! pluralise {
|
||||
($x:expr) => {
|
||||
if $x != 1 { "s" } else { "" }
|
||||
};
|
||||
}
|
||||
|
||||
match *self {
|
||||
CyclicTy(_) => write!(f, "cyclic type of infinite size"),
|
||||
Mismatch => write!(f, "types differ"),
|
||||
@ -95,16 +101,20 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
|
||||
}
|
||||
Mutability => write!(f, "types differ in mutability"),
|
||||
TupleSize(values) => {
|
||||
write!(f, "expected a tuple with {} elements, \
|
||||
found one with {} elements",
|
||||
write!(f, "expected a tuple with {} element{}, \
|
||||
found one with {} element{}",
|
||||
values.expected,
|
||||
values.found)
|
||||
pluralise!(values.expected),
|
||||
values.found,
|
||||
pluralise!(values.found))
|
||||
}
|
||||
FixedArraySize(values) => {
|
||||
write!(f, "expected an array with a fixed size of {} elements, \
|
||||
found one with {} elements",
|
||||
write!(f, "expected an array with a fixed size of {} element{}, \
|
||||
found one with {} element{}",
|
||||
values.expected,
|
||||
values.found)
|
||||
pluralise!(values.expected),
|
||||
values.found,
|
||||
pluralise!(values.found))
|
||||
}
|
||||
ArgCount => {
|
||||
write!(f, "incorrect number of function parameters")
|
||||
@ -157,8 +167,9 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
|
||||
tcx.def_path_str(values.found))
|
||||
}),
|
||||
ProjectionBoundsLength(ref values) => {
|
||||
write!(f, "expected {} associated type bindings, found {}",
|
||||
write!(f, "expected {} associated type binding{}, found {}",
|
||||
values.expected,
|
||||
pluralise!(values.expected),
|
||||
values.found)
|
||||
},
|
||||
ExistentialMismatch(ref values) => {
|
||||
|
@ -2,7 +2,7 @@ error[E0308]: mismatched types
|
||||
--> $DIR/const-array-oob-arith.rs:7:45
|
||||
|
|
||||
LL | const BLUB: [i32; (ARR[0] - 40) as usize] = [5];
|
||||
| ^^^ expected an array with a fixed size of 2 elements, found one with 1 elements
|
||||
| ^^^ expected an array with a fixed size of 2 elements, found one with 1 element
|
||||
|
|
||||
= note: expected type `[i32; 2]`
|
||||
found type `[i32; 1]`
|
||||
@ -11,7 +11,7 @@ error[E0308]: mismatched types
|
||||
--> $DIR/const-array-oob-arith.rs:8:44
|
||||
|
|
||||
LL | const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99];
|
||||
| ^^^^^^^ expected an array with a fixed size of 1 elements, found one with 2 elements
|
||||
| ^^^^^^^ expected an array with a fixed size of 1 element, found one with 2 elements
|
||||
|
|
||||
= note: expected type `[i32; 1]`
|
||||
found type `[i32; 2]`
|
||||
|
@ -13,5 +13,5 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
//~| expected type `(isize, f64)`
|
||||
//~| found type `(isize,)`
|
||||
//~| expected a tuple with 2 elements, found one with 1 elements
|
||||
//~| expected a tuple with 2 elements, found one with 1 element
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ error[E0308]: mismatched types
|
||||
--> $DIR/tuple-arity-mismatch.rs:12:20
|
||||
|
|
||||
LL | let y = first ((1,));
|
||||
| ^^^^ expected a tuple with 2 elements, found one with 1 elements
|
||||
| ^^^^ expected a tuple with 2 elements, found one with 1 element
|
||||
|
|
||||
= note: expected type `(isize, f64)`
|
||||
found type `(isize,)`
|
||||
|
Loading…
Reference in New Issue
Block a user