1
Fork 0

Shrink suggestion span of argument mismatch error

This commit is contained in:
Michael Goulet 2022-09-02 02:17:44 +00:00
parent 0209485578
commit b0f3a551f2
38 changed files with 125 additions and 114 deletions

View file

@ -1056,11 +1056,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};
if let Some(suggestion_text) = suggestion_text {
let source_map = self.sess().source_map();
let mut suggestion = format!(
"{}(",
source_map.span_to_snippet(full_call_span).unwrap_or_else(|_| fn_def_id
.map_or("".to_string(), |fn_def_id| tcx.item_name(fn_def_id).to_string()))
);
let (mut suggestion, suggestion_span) =
if let Some(call_span) = full_call_span.find_ancestor_inside(error_span) {
("(".to_string(), call_span.shrink_to_hi().to(error_span.shrink_to_hi()))
} else {
(
format!(
"{}(",
source_map.span_to_snippet(full_call_span).unwrap_or_else(|_| {
fn_def_id.map_or("".to_string(), |fn_def_id| {
tcx.item_name(fn_def_id).to_string()
})
})
),
error_span,
)
};
let mut needs_comma = false;
for (expected_idx, provided_idx) in matched_inputs.iter_enumerated() {
if needs_comma {
@ -1088,7 +1099,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
suggestion += ")";
err.span_suggestion_verbose(
error_span,
suggestion_span,
&suggestion_text,
suggestion,
Applicability::HasPlaceholders,