Skip to content

Commit fa14f79

Browse files
committed
Reword
1 parent c74bda1 commit fa14f79

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

src/librustc/traits/error_reporting.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -845,33 +845,34 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
845845

846846
let kind = if is_closure { "closure" } else { "function" };
847847

848-
let args_str = |n| format!(
849-
"{} argument{}",
848+
let args_str = |n, distinct| format!(
849+
"{} {}argument{}",
850850
n,
851-
if n == 1 { "" } else { "s" }
851+
if distinct && n >= 2 { "distinct " } else { "" },
852+
if n == 1 { "" } else { "s" },
852853
);
853854

854855
let mut err = struct_span_err!(self.tcx.sess, span, E0593,
855-
"{} takes {}, but {} {} required",
856+
"{} is expected to take {}, but it takes {}",
856857
kind,
857858
if expected_tuple.is_some() {
858-
Cow::from("multiple arguments")
859+
Cow::from("a single tuple as argument")
859860
} else {
860-
Cow::from(args_str(found))
861+
Cow::from(args_str(expected, false))
861862
},
862863
if expected_tuple.is_some() {
863-
Cow::from("a tuple argument")
864+
args_str(found, true)
864865
} else {
865-
Cow::from(args_str(expected))
866+
args_str(found, false)
866867
},
867-
if expected == 1 { "is" } else { "are" });
868+
);
868869

869870
err.span_label(
870871
span,
871872
format!(
872873
"expected {} that takes {}{}",
873874
kind,
874-
args_str(expected),
875+
args_str(expected, false),
875876
if let Some(n) = expected_tuple {
876877
assert!(expected == 1);
877878
Cow::from(format!(", a {}-tuple", n))
@@ -884,7 +885,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
884885
if let Some(span) = found_span {
885886
if let (Some(expected_tuple), Some((pats, tys))) = (expected_tuple, closure_args) {
886887
if expected_tuple != found || pats.len() != found {
887-
err.span_label(span, format!("takes {}", args_str(found)));
888+
err.span_label(span, format!("takes {}", args_str(found, true)));
888889
} else {
889890
let sugg = format!(
890891
"|({}){}|",
@@ -908,7 +909,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
908909
err.span_suggestion(span, "consider changing to", sugg);
909910
}
910911
} else {
911-
err.span_label(span, format!("takes {}", args_str(found)));
912+
err.span_label(span, format!("takes {}", args_str(found, false)));
912913
}
913914
}
914915

src/test/ui/mismatched_types/closure-arg-count.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error[E0593]: closure takes 0 arguments, but 2 arguments are required
1+
error[E0593]: closure is expected to take 2 arguments, but it takes 0 arguments
22
--> $DIR/closure-arg-count.rs:15:15
33
|
44
15 | [1, 2, 3].sort_by(|| panic!());
55
| ^^^^^^^ -- takes 0 arguments
66
| |
77
| expected closure that takes 2 arguments
88

9-
error[E0593]: closure takes 1 argument, but 2 arguments are required
9+
error[E0593]: closure is expected to take 2 arguments, but it takes 1 argument
1010
--> $DIR/closure-arg-count.rs:16:15
1111
|
1212
16 | [1, 2, 3].sort_by(|tuple| panic!());
@@ -23,15 +23,15 @@ error[E0308]: mismatched types
2323
= note: expected type `&{integer}`
2424
found type `(_, _)`
2525

26-
error[E0593]: closure takes 1 argument, but 2 arguments are required
26+
error[E0593]: closure is expected to take 2 arguments, but it takes 1 argument
2727
--> $DIR/closure-arg-count.rs:17:15
2828
|
2929
17 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!());
3030
| ^^^^^^^ ----------------- takes 1 argument
3131
| |
3232
| expected closure that takes 2 arguments
3333

34-
error[E0593]: closure takes 0 arguments, but 1 argument is required
34+
error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments
3535
--> $DIR/closure-arg-count.rs:18:5
3636
|
3737
18 | f(|| panic!());
@@ -41,27 +41,27 @@ error[E0593]: closure takes 0 arguments, but 1 argument is required
4141
|
4242
= note: required by `f`
4343

44-
error[E0593]: closure takes multiple arguments, but a tuple argument is required
44+
error[E0593]: closure is expected to take a single tuple as argument, but it takes 2 distinct arguments
4545
--> $DIR/closure-arg-count.rs:20:53
4646
|
4747
20 | let _it = vec![1, 2, 3].into_iter().enumerate().map(|i, x| i);
4848
| ^^^ ------ help: consider changing to: `|(i, x)|`
4949
| |
5050
| expected closure that takes 1 argument, a 2-tuple
5151

52-
error[E0593]: closure takes multiple arguments, but a tuple argument is required
52+
error[E0593]: closure is expected to take a single tuple as argument, but it takes 2 distinct arguments
5353
--> $DIR/closure-arg-count.rs:21:53
5454
|
5555
21 | let _it = vec![1, 2, 3].into_iter().enumerate().map(|i: usize, x| i);
5656
| ^^^ ------------- help: consider changing to: `|(i, x): (usize, _)|`
5757
| |
5858
| expected closure that takes 1 argument, a 2-tuple
5959

60-
error[E0593]: closure takes multiple arguments, but a tuple argument is required
60+
error[E0593]: closure is expected to take a single tuple as argument, but it takes 3 distinct arguments
6161
--> $DIR/closure-arg-count.rs:22:53
6262
|
6363
22 | let _it = vec![1, 2, 3].into_iter().enumerate().map(|i, x, y| i);
64-
| ^^^ --------- takes 3 arguments
64+
| ^^^ --------- takes 3 distinct arguments
6565
| |
6666
| expected closure that takes 1 argument, a 2-tuple
6767

0 commit comments

Comments
 (0)