about summary refs log tree commit diff
diff options
context:
space:
mode:
authorsinkuu <sinkuu@sinkuu.xyz>2017-10-10 11:03:23 +0900
committersinkuu <sinkuu@sinkuu.xyz>2017-10-10 16:07:58 +0900
commitfa14f797f32acbea481989371f6c32739975f160 (patch)
tree4a7988a7df6cf688d9e725f4ae6e28faffb4938a
parentc74bda1075757cd00f72a918e2d7fdaf47f85c2d (diff)
downloadrust-fa14f797f32acbea481989371f6c32739975f160.tar.gz
rust-fa14f797f32acbea481989371f6c32739975f160.zip
Reword
-rw-r--r--src/librustc/traits/error_reporting.rs25
-rw-r--r--src/test/ui/mismatched_types/closure-arg-count.stderr16
2 files changed, 21 insertions, 20 deletions
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs
index 5056876f3ad..a192dc6d6ea 100644
--- a/src/librustc/traits/error_reporting.rs
+++ b/src/librustc/traits/error_reporting.rs
@@ -845,33 +845,34 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
 
         let kind = if is_closure { "closure" } else { "function" };
 
-        let args_str = |n| format!(
-                "{} argument{}",
+        let args_str = |n, distinct| format!(
+                "{} {}argument{}",
                 n,
-                if n == 1 { "" } else { "s" }
+                if distinct && n >= 2 { "distinct " } else { "" },
+                if n == 1 { "" } else { "s" },
             );
 
         let mut err = struct_span_err!(self.tcx.sess, span, E0593,
-            "{} takes {}, but {} {} required",
+            "{} is expected to take {}, but it takes {}",
             kind,
             if expected_tuple.is_some() {
-                Cow::from("multiple arguments")
+                Cow::from("a single tuple as argument")
             } else {
-                Cow::from(args_str(found))
+                Cow::from(args_str(expected, false))
             },
             if expected_tuple.is_some() {
-                Cow::from("a tuple argument")
+                args_str(found, true)
             } else {
-                Cow::from(args_str(expected))
+                args_str(found, false)
             },
-            if expected == 1 { "is" } else { "are" });
+        );
 
         err.span_label(
             span,
             format!(
                 "expected {} that takes {}{}",
                 kind,
-                args_str(expected),
+                args_str(expected, false),
                 if let Some(n) = expected_tuple {
                     assert!(expected == 1);
                     Cow::from(format!(", a {}-tuple", n))
@@ -884,7 +885,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
         if let Some(span) = found_span {
             if let (Some(expected_tuple), Some((pats, tys))) = (expected_tuple, closure_args) {
                 if expected_tuple != found || pats.len() != found {
-                    err.span_label(span, format!("takes {}", args_str(found)));
+                    err.span_label(span, format!("takes {}", args_str(found, true)));
                 } else {
                     let sugg = format!(
                         "|({}){}|",
@@ -908,7 +909,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
                     err.span_suggestion(span, "consider changing to", sugg);
                 }
             } else {
-                err.span_label(span, format!("takes {}", args_str(found)));
+                err.span_label(span, format!("takes {}", args_str(found, false)));
             }
         }
 
diff --git a/src/test/ui/mismatched_types/closure-arg-count.stderr b/src/test/ui/mismatched_types/closure-arg-count.stderr
index 24860faf2d5..8f508ade68c 100644
--- a/src/test/ui/mismatched_types/closure-arg-count.stderr
+++ b/src/test/ui/mismatched_types/closure-arg-count.stderr
@@ -1,4 +1,4 @@
-error[E0593]: closure takes 0 arguments, but 2 arguments are required
+error[E0593]: closure is expected to take 2 arguments, but it takes 0 arguments
   --> $DIR/closure-arg-count.rs:15:15
    |
 15 |     [1, 2, 3].sort_by(|| panic!());
@@ -6,7 +6,7 @@ error[E0593]: closure takes 0 arguments, but 2 arguments are required
    |               |
    |               expected closure that takes 2 arguments
 
-error[E0593]: closure takes 1 argument, but 2 arguments are required
+error[E0593]: closure is expected to take 2 arguments, but it takes 1 argument
   --> $DIR/closure-arg-count.rs:16:15
    |
 16 |     [1, 2, 3].sort_by(|tuple| panic!());
@@ -23,7 +23,7 @@ error[E0308]: mismatched types
    = note: expected type `&{integer}`
               found type `(_, _)`
 
-error[E0593]: closure takes 1 argument, but 2 arguments are required
+error[E0593]: closure is expected to take 2 arguments, but it takes 1 argument
   --> $DIR/closure-arg-count.rs:17:15
    |
 17 |     [1, 2, 3].sort_by(|(tuple, tuple2)| panic!());
@@ -31,7 +31,7 @@ error[E0593]: closure takes 1 argument, but 2 arguments are required
    |               |
    |               expected closure that takes 2 arguments
 
-error[E0593]: closure takes 0 arguments, but 1 argument is required
+error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments
   --> $DIR/closure-arg-count.rs:18:5
    |
 18 |     f(|| panic!());
@@ -41,7 +41,7 @@ error[E0593]: closure takes 0 arguments, but 1 argument is required
    |
    = note: required by `f`
 
-error[E0593]: closure takes multiple arguments, but a tuple argument is required
+error[E0593]: closure is expected to take a single tuple as argument, but it takes 2 distinct arguments
   --> $DIR/closure-arg-count.rs:20:53
    |
 20 |     let _it = vec![1, 2, 3].into_iter().enumerate().map(|i, x| i);
@@ -49,7 +49,7 @@ error[E0593]: closure takes multiple arguments, but a tuple argument is required
    |                                                     |
    |                                                     expected closure that takes 1 argument, a 2-tuple
 
-error[E0593]: closure takes multiple arguments, but a tuple argument is required
+error[E0593]: closure is expected to take a single tuple as argument, but it takes 2 distinct arguments
   --> $DIR/closure-arg-count.rs:21:53
    |
 21 |     let _it = vec![1, 2, 3].into_iter().enumerate().map(|i: usize, x| i);
@@ -57,11 +57,11 @@ error[E0593]: closure takes multiple arguments, but a tuple argument is required
    |                                                     |
    |                                                     expected closure that takes 1 argument, a 2-tuple
 
-error[E0593]: closure takes multiple arguments, but a tuple argument is required
+error[E0593]: closure is expected to take a single tuple as argument, but it takes 3 distinct arguments
   --> $DIR/closure-arg-count.rs:22:53
    |
 22 |     let _it = vec![1, 2, 3].into_iter().enumerate().map(|i, x, y| i);
-   |                                                     ^^^ --------- takes 3 arguments
+   |                                                     ^^^ --------- takes 3 distinct arguments
    |                                                     |
    |                                                     expected closure that takes 1 argument, a 2-tuple