This commit is contained in:
sinkuu 2017-10-10 11:03:23 +09:00
parent c74bda1075
commit fa14f797f3
2 changed files with 21 additions and 20 deletions

View file

@ -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)));
}
}

View file

@ -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