diff options
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 17206b21af0..dafc424f1b4 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -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. |
