Skip to content

Commit f577847

Browse files
committed
Reword
1 parent fa14f79 commit f577847

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

src/librustc/traits/error_reporting.rs

+30-21
Original file line numberDiff line numberDiff line change
@@ -852,40 +852,45 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
852852
if n == 1 { "" } else { "s" },
853853
);
854854

855+
let expected_str = if let Some(n) = expected_tuple {
856+
assert!(expected == 1);
857+
if closure_args.as_ref().map(|&(ref pats, _)| pats.len()) == Some(n) {
858+
Cow::from("a single tuple as argument")
859+
} else {
860+
// be verbose when numbers differ
861+
Cow::from(format!("a single {}-tuple as argument", n))
862+
}
863+
} else {
864+
Cow::from(args_str(expected, false))
865+
};
866+
867+
let found_str = if expected_tuple.is_some() {
868+
args_str(found, true)
869+
} else {
870+
args_str(found, false)
871+
};
872+
873+
855874
let mut err = struct_span_err!(self.tcx.sess, span, E0593,
856875
"{} is expected to take {}, but it takes {}",
857876
kind,
858-
if expected_tuple.is_some() {
859-
Cow::from("a single tuple as argument")
860-
} else {
861-
Cow::from(args_str(expected, false))
862-
},
863-
if expected_tuple.is_some() {
864-
args_str(found, true)
865-
} else {
866-
args_str(found, false)
867-
},
877+
expected_str,
878+
found_str,
868879
);
869880

870881
err.span_label(
871882
span,
872883
format!(
873-
"expected {} that takes {}{}",
884+
"expected {} that takes {}",
874885
kind,
875-
args_str(expected, false),
876-
if let Some(n) = expected_tuple {
877-
assert!(expected == 1);
878-
Cow::from(format!(", a {}-tuple", n))
879-
} else {
880-
Cow::from("")
881-
}
886+
expected_str,
882887
)
883888
);
884889

885890
if let Some(span) = found_span {
886891
if let (Some(expected_tuple), Some((pats, tys))) = (expected_tuple, closure_args) {
887892
if expected_tuple != found || pats.len() != found {
888-
err.span_label(span, format!("takes {}", args_str(found, true)));
893+
err.span_label(span, format!("takes {}", found_str));
889894
} else {
890895
let sugg = format!(
891896
"|({}){}|",
@@ -906,10 +911,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
906911
},
907912
);
908913

909-
err.span_suggestion(span, "consider changing to", sugg);
914+
err.span_suggestion(
915+
span,
916+
"consider changing the closure to accept a tuple",
917+
sugg
918+
);
910919
}
911920
} else {
912-
err.span_label(span, format!("takes {}", args_str(found, false)));
921+
err.span_label(span, format!("takes {}", found_str));
913922
}
914923
}
915924

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,25 @@ error[E0593]: closure is expected to take a single tuple as argument, but it tak
4545
--> $DIR/closure-arg-count.rs:20:53
4646
|
4747
20 | let _it = vec![1, 2, 3].into_iter().enumerate().map(|i, x| i);
48-
| ^^^ ------ help: consider changing to: `|(i, x)|`
48+
| ^^^ ------ help: consider changing the closure to accept a tuple: `|(i, x)|`
4949
| |
50-
| expected closure that takes 1 argument, a 2-tuple
50+
| expected closure that takes a single tuple as argument
5151

5252
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);
56-
| ^^^ ------------- help: consider changing to: `|(i, x): (usize, _)|`
56+
| ^^^ ------------- help: consider changing the closure to accept a tuple: `|(i, x): (usize, _)|`
5757
| |
58-
| expected closure that takes 1 argument, a 2-tuple
58+
| expected closure that takes a single tuple as argument
5959

60-
error[E0593]: closure is expected to take a single tuple as argument, but it takes 3 distinct arguments
60+
error[E0593]: closure is expected to take a single 2-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);
6464
| ^^^ --------- takes 3 distinct arguments
6565
| |
66-
| expected closure that takes 1 argument, a 2-tuple
66+
| expected closure that takes a single 2-tuple as argument
6767

6868
error: aborting due to 8 previous errors
6969

0 commit comments

Comments
 (0)