Skip to content

Commit f14daa5

Browse files
committed
Always reborrow mutable reference receiver in methods
1 parent ea22d24 commit f14daa5

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

crates/hir-ty/src/method_resolution.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,10 @@ pub fn iterate_method_candidates_dyn(
896896
let deref_chain = autoderef_method_receiver(&mut table, ty);
897897

898898
let result = deref_chain.into_iter().try_for_each(|(receiver_ty, adj)| {
899+
if matches!(receiver_ty.value.kind(Interner), TyKind::Ref(Mutability::Mut, _, _)) {
900+
// We should prefer reborrow of mutable references instead of moving them.
901+
return ControlFlow::Continue(());
902+
}
899903
iterate_method_candidates_with_autoref(
900904
&receiver_ty,
901905
adj,

crates/ide/src/inlay_hints/adjustment.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ fn main() {
322322
//^^^^^^^^^^^&
323323
//^^^^^^^^^^^*
324324
(&mut Struct).by_ref_mut();
325+
//^^^^^^^^^^^&mut $
326+
//^^^^^^^^^^^*
325327
326328
// Check that block-like expressions don't duplicate hints
327329
let _: &mut [u32] = (&mut []);
@@ -425,6 +427,10 @@ fn main() {
425427
//^^^^^^^^^^^.*
426428
//^^^^^^^^^^^.&
427429
(&mut Struct).by_ref_mut();
430+
//^^^^^^^^^^^(
431+
//^^^^^^^^^^^)
432+
//^^^^^^^^^^^.*
433+
//^^^^^^^^^^^.&mut
428434
429435
// Check that block-like expressions don't duplicate hints
430436
let _: &mut [u32] = (&mut []);

0 commit comments

Comments
 (0)