diff options
| author | csmoe <35686186+csmoe@users.noreply.github.com> | 2018-07-23 22:16:53 +0800 |
|---|---|---|
| committer | csmoe <35686186+csmoe@users.noreply.github.com> | 2018-07-23 22:35:51 +0800 |
| commit | 87f0c1f33789df39db871857055a2d7d533da47f (patch) | |
| tree | 68faa25e6997ccd79a735b03c2e88b56a00eae4f /src | |
| parent | c7cba3d33f564be140275c4fb9e33c6dc2c97b21 (diff) | |
| download | rust-87f0c1f33789df39db871857055a2d7d533da47f.tar.gz rust-87f0c1f33789df39db871857055a2d7d533da47f.zip | |
Suggest to take and ignore args while closure args count mismatching
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/traits/error_reporting.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index df26ac67060..1c502b66103 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1048,7 +1048,24 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { err.span_label(span, format!( "expected {} that takes {}", kind, expected_str)); if let Some(found_span) = found_span { - err.span_label(found_span, format!("takes {}", found_str)); + // Suggest to take and ignore the arguments with expected_args_length `_`s if + // found arguments is empty(Suppose the user just wants to ignore args in this case). + // like `|_, _|` for closure with 2 expected args. + if found_args.is_empty() && is_closure { + let mut underscores = "_".repeat(expected_args.len()) + .split("") + .filter(|s| !s.is_empty()) + .collect::<Vec<_>>() + .join(", "); + err.span_suggestion( + found_span, + "consider changing this to", + format!("|{}|", underscores), + ); + } else { + err.span_label(found_span, format!("takes {}", found_str)); + } + if let &[ArgKind::Tuple(_, ref fields)] = &found_args[..] { if fields.len() == expected_args.len() { |
