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