use more descriptive names
This commit is contained in:
parent
64b3e4af20
commit
a311b8a4c5
1 changed files with 94 additions and 92 deletions
|
@ -908,9 +908,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
let param_env = obligation.param_env;
|
let param_env = obligation.param_env;
|
||||||
|
|
||||||
// Try to apply the original trait binding obligation by borrowing.
|
// Try to apply the original trait binding obligation by borrowing.
|
||||||
let mut try_borrowing = |old_pred: ty::PolyTraitPredicate<'tcx>,
|
let mut try_borrowing =
|
||||||
blacklist: &[DefId]|
|
|old_pred: ty::PolyTraitPredicate<'tcx>, blacklist: &[DefId]| -> bool {
|
||||||
-> bool {
|
|
||||||
if blacklist.contains(&old_pred.def_id()) {
|
if blacklist.contains(&old_pred.def_id()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -933,19 +932,25 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
self.mk_trait_obligation_with_new_self_ty(param_env, trait_pred_and_new_ty);
|
self.mk_trait_obligation_with_new_self_ty(param_env, trait_pred_and_new_ty);
|
||||||
self.predicate_must_hold_modulo_regions(&obligation)
|
self.predicate_must_hold_modulo_regions(&obligation)
|
||||||
};
|
};
|
||||||
let imm_result = mk_result(trait_pred_and_imm_ref);
|
let imm_ref_self_ty_satisfies_pred = mk_result(trait_pred_and_imm_ref);
|
||||||
let mut_result = mk_result(trait_pred_and_mut_ref);
|
let mut_ref_self_ty_satisfies_pred = mk_result(trait_pred_and_mut_ref);
|
||||||
|
|
||||||
let ref_inner_ty_result =
|
let (ref_inner_ty_satisfies_pred, ref_inner_ty_mut) =
|
||||||
if let ObligationCauseCode::ItemObligation(_) = obligation.cause.code()
|
if let ObligationCauseCode::ItemObligation(_) = obligation.cause.code()
|
||||||
&& let ty::Ref(_, ty, mutability) = old_pred.self_ty().skip_binder().kind()
|
&& let ty::Ref(_, ty, mutability) = old_pred.self_ty().skip_binder().kind()
|
||||||
{
|
{
|
||||||
Some((mk_result(old_pred.map_bound(|trait_pred| (trait_pred, *ty))), mutability))
|
(
|
||||||
|
mk_result(old_pred.map_bound(|trait_pred| (trait_pred, *ty))),
|
||||||
|
matches!(mutability, hir::Mutability::Mut),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
None
|
(false, false)
|
||||||
};
|
};
|
||||||
|
|
||||||
if imm_result || mut_result || ref_inner_ty_result.map_or(false, |(result, _)| result) {
|
if imm_ref_self_ty_satisfies_pred
|
||||||
|
|| mut_ref_self_ty_satisfies_pred
|
||||||
|
|| ref_inner_ty_satisfies_pred
|
||||||
|
{
|
||||||
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
|
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
|
||||||
// We have a very specific type of error, where just borrowing this argument
|
// We have a very specific type of error, where just borrowing this argument
|
||||||
// might solve the problem. In cases like this, the important part is the
|
// might solve the problem. In cases like this, the important part is the
|
||||||
|
@ -985,7 +990,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
// }
|
// }
|
||||||
// ```
|
// ```
|
||||||
|
|
||||||
if imm_result && mut_result {
|
if imm_ref_self_ty_satisfies_pred && mut_ref_self_ty_satisfies_pred {
|
||||||
err.span_suggestions(
|
err.span_suggestions(
|
||||||
span.shrink_to_lo(),
|
span.shrink_to_lo(),
|
||||||
"consider borrowing here",
|
"consider borrowing here",
|
||||||
|
@ -993,10 +998,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let is_mut = mut_result
|
let is_mut = mut_ref_self_ty_satisfies_pred || ref_inner_ty_mut;
|
||||||
|| ref_inner_ty_result.map_or(false, |(_, mutabl)| {
|
|
||||||
matches!(mutabl, hir::Mutability::Mut)
|
|
||||||
});
|
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
span.shrink_to_lo(),
|
span.shrink_to_lo(),
|
||||||
&format!(
|
&format!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue