about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2019-05-27 14:28:20 +0100
committervarkor <github@varkor.com>2019-05-28 21:35:20 +0100
commit56181cf8abf8ad7f7d36e92ef4d7bf294df23c4c (patch)
treea77cb0373cc98c1279b413be29ba01122a5df641
parent854995313a029df89381449bb168bf61c88c546c (diff)
downloadrust-56181cf8abf8ad7f7d36e92ef4d7bf294df23c4c.tar.gz
rust-56181cf8abf8ad7f7d36e92ef4d7bf294df23c4c.zip
Correct pluralisation of tuple/array/associated type binding mismatch errors
-rw-r--r--src/librustc/ty/error.rs25
-rw-r--r--src/test/ui/consts/const-array-oob-arith.stderr4
-rw-r--r--src/test/ui/tuple/tuple-arity-mismatch.rs2
-rw-r--r--src/test/ui/tuple/tuple-arity-mismatch.stderr2
4 files changed, 22 insertions, 11 deletions
diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs
index 3d9e9cd6902..09426fe19e1 100644
--- a/src/librustc/ty/error.rs
+++ b/src/librustc/ty/error.rs
@@ -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) => {
diff --git a/src/test/ui/consts/const-array-oob-arith.stderr b/src/test/ui/consts/const-array-oob-arith.stderr
index 00286b0b0e0..77414fc7c92 100644
--- a/src/test/ui/consts/const-array-oob-arith.stderr
+++ b/src/test/ui/consts/const-array-oob-arith.stderr
@@ -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]`
diff --git a/src/test/ui/tuple/tuple-arity-mismatch.rs b/src/test/ui/tuple/tuple-arity-mismatch.rs
index 1c8b881d246..4f505c05a6a 100644
--- a/src/test/ui/tuple/tuple-arity-mismatch.rs
+++ b/src/test/ui/tuple/tuple-arity-mismatch.rs
@@ -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
 }
diff --git a/src/test/ui/tuple/tuple-arity-mismatch.stderr b/src/test/ui/tuple/tuple-arity-mismatch.stderr
index 650f4c58c77..6946a60c59a 100644
--- a/src/test/ui/tuple/tuple-arity-mismatch.stderr
+++ b/src/test/ui/tuple/tuple-arity-mismatch.stderr
@@ -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,)`