Suggest reborrowing mutable reference when move error ocurrs #74706
Labels
A-borrow-checker
Area: The borrow checker
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`.
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
The following code:
produces the following error:
When
self
is passed directly touse_val
(e.g.use_val(self
), a reborrow will automatically be inserted, allowing the code to compile. However, the fact thatuse_val
takes an&mut T
means that the compiler won't adjust the inferred type in any way (in this case,&mut Wrapper<&mut Foo>
), leading to the move error.The solution is to add an explicit reborrow (
&mut Wrapper(&mut *self)
), however, this wasn't obvious to me. It would be useful if the compiler could suggest inserting a reborrow in this situation.The text was updated successfully, but these errors were encountered: