From 27c0d564efedef1bec06076c8c12108c0d6fd6ec Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Mon, 23 Jul 2018 22:45:37 +0800 Subject: [PATCH] Mark the suggestion applicable --- src/librustc/traits/error_reporting.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 1c502b66103..e0dcbf520b4 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1048,25 +1048,31 @@ 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::>() - .join(", "); - err.span_suggestion( + .split("") + .filter(|s| !s.is_empty()) + .collect::>() + .join(", "); + err.span_suggestion_with_applicability( found_span, - "consider changing this to", + &format!("change the closure to take and ignore the argument{}", + if expected_args.len() < 2 { + "" + } else { + "s" + } + ), format!("|{}|", underscores), + Applicability::MachineApplicable, ); - } else { - err.span_label(found_span, format!("takes {}", found_str)); } - if let &[ArgKind::Tuple(_, ref fields)] = &found_args[..] { if fields.len() == expected_args.len() { let sugg = fields.iter()