diff options
| author | sinkuu <sinkuu@sinkuu.xyz> | 2017-10-13 09:56:50 +0900 |
|---|---|---|
| committer | sinkuu <sinkuu@sinkuu.xyz> | 2017-10-13 09:56:50 +0900 |
| commit | f577847aa22cda4935562fe8e7c9420bcc58f148 (patch) | |
| tree | 8a9cce6c5dbe13469a5189c4ca3b855aec18321a | |
| parent | fa14f797f32acbea481989371f6c32739975f160 (diff) | |
| download | rust-f577847aa22cda4935562fe8e7c9420bcc58f148.tar.gz rust-f577847aa22cda4935562fe8e7c9420bcc58f148.zip | |
Reword
| -rw-r--r-- | src/librustc/traits/error_reporting.rs | 51 | ||||
| -rw-r--r-- | src/test/ui/mismatched_types/closure-arg-count.stderr | 12 |
2 files changed, 36 insertions, 27 deletions
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index a192dc6d6ea..030b7e4f646 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -852,40 +852,45 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { if n == 1 { "" } else { "s" }, ); + let expected_str = if let Some(n) = expected_tuple { + assert!(expected == 1); + if closure_args.as_ref().map(|&(ref pats, _)| pats.len()) == Some(n) { + Cow::from("a single tuple as argument") + } else { + // be verbose when numbers differ + Cow::from(format!("a single {}-tuple as argument", n)) + } + } else { + Cow::from(args_str(expected, false)) + }; + + let found_str = if expected_tuple.is_some() { + args_str(found, true) + } else { + args_str(found, false) + }; + + let mut err = struct_span_err!(self.tcx.sess, span, E0593, "{} is expected to take {}, but it takes {}", kind, - if expected_tuple.is_some() { - Cow::from("a single tuple as argument") - } else { - Cow::from(args_str(expected, false)) - }, - if expected_tuple.is_some() { - args_str(found, true) - } else { - args_str(found, false) - }, + expected_str, + found_str, ); err.span_label( span, format!( - "expected {} that takes {}{}", + "expected {} that takes {}", kind, - args_str(expected, false), - if let Some(n) = expected_tuple { - assert!(expected == 1); - Cow::from(format!(", a {}-tuple", n)) - } else { - Cow::from("") - } + expected_str, ) ); 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, true))); + err.span_label(span, format!("takes {}", found_str)); } else { let sugg = format!( "|({}){}|", @@ -906,10 +911,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { }, ); - err.span_suggestion(span, "consider changing to", sugg); + err.span_suggestion( + span, + "consider changing the closure to accept a tuple", + sugg + ); } } else { - err.span_label(span, format!("takes {}", args_str(found, false))); + err.span_label(span, format!("takes {}", found_str)); } } diff --git a/src/test/ui/mismatched_types/closure-arg-count.stderr b/src/test/ui/mismatched_types/closure-arg-count.stderr index 8f508ade68c..9d4ac630546 100644 --- a/src/test/ui/mismatched_types/closure-arg-count.stderr +++ b/src/test/ui/mismatched_types/closure-arg-count.stderr @@ -45,25 +45,25 @@ error[E0593]: closure is expected to take a single tuple as argument, but it tak --> $DIR/closure-arg-count.rs:20:53 | 20 | let _it = vec![1, 2, 3].into_iter().enumerate().map(|i, x| i); - | ^^^ ------ help: consider changing to: `|(i, x)|` + | ^^^ ------ help: consider changing the closure to accept a tuple: `|(i, x)|` | | - | expected closure that takes 1 argument, a 2-tuple + | expected closure that takes a single tuple as argument 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); - | ^^^ ------------- help: consider changing to: `|(i, x): (usize, _)|` + | ^^^ ------------- help: consider changing the closure to accept a tuple: `|(i, x): (usize, _)|` | | - | expected closure that takes 1 argument, a 2-tuple + | expected closure that takes a single tuple as argument -error[E0593]: closure is expected to take a single tuple as argument, but it takes 3 distinct arguments +error[E0593]: closure is expected to take a single 2-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 distinct arguments | | - | expected closure that takes 1 argument, a 2-tuple + | expected closure that takes a single 2-tuple as argument error: aborting due to 8 previous errors |
