1
Fork 0

reduce to single suggestion for all arguments

This commit is contained in:
akida31 2022-11-13 22:40:54 +01:00
parent 4d87fb5d11
commit f780faa8c4
No known key found for this signature in database
GPG key ID: 02E1AF2C3D9FB7C9
5 changed files with 66 additions and 89 deletions

View file

@ -3429,26 +3429,37 @@ fn hint_missing_borrow<'tcx>(
(ty, refs)
}
let mut to_borrow = Vec::new();
let mut remove_borrow = Vec::new();
for ((found_arg, expected_arg), arg_span) in found_args.zip(expected_args).zip(arg_spans) {
let (found_ty, found_refs) = get_deref_type_and_refs(*found_arg);
let (expected_ty, expected_refs) = get_deref_type_and_refs(*expected_arg);
if found_ty == expected_ty {
let hint = if found_refs < expected_refs {
"consider borrowing the argument"
} else if found_refs == expected_refs {
continue;
} else {
"do not borrow the argument"
};
err.span_suggestion_verbose(
arg_span,
hint,
expected_arg.to_string(),
Applicability::MaybeIncorrect,
);
if found_refs < expected_refs {
to_borrow.push((arg_span, expected_arg.to_string()));
} else if found_refs > expected_refs {
remove_borrow.push((arg_span, expected_arg.to_string()));
}
}
}
if !to_borrow.is_empty() {
err.multipart_suggestion(
"consider borrowing the argument",
to_borrow,
Applicability::MaybeIncorrect,
);
}
if !remove_borrow.is_empty() {
err.multipart_suggestion(
"do not borrow the argument",
remove_borrow,
Applicability::MaybeIncorrect,
);
}
}
/// Collect all the returned expressions within the input expression.