mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Add moved-out-of-ref
diagnostic
This commit is contained in:
parent
09d1265e1e
commit
b55fbd3ad7
11 changed files with 352 additions and 10 deletions
|
@ -934,7 +934,18 @@ impl<'a> InferenceContext<'a> {
|
|||
match fn_x {
|
||||
FnTrait::FnOnce => (),
|
||||
FnTrait::FnMut => {
|
||||
if !matches!(derefed_callee.kind(Interner), TyKind::Ref(Mutability::Mut, _, _)) {
|
||||
if let TyKind::Ref(Mutability::Mut, _, inner) = derefed_callee.kind(Interner) {
|
||||
if adjustments
|
||||
.last()
|
||||
.map(|x| matches!(x.kind, Adjust::Borrow(_)))
|
||||
.unwrap_or(true)
|
||||
{
|
||||
// prefer reborrow to move
|
||||
adjustments
|
||||
.push(Adjustment { kind: Adjust::Deref(None), target: inner.clone() });
|
||||
adjustments.push(Adjustment::borrow(Mutability::Mut, inner.clone()))
|
||||
}
|
||||
} else {
|
||||
adjustments.push(Adjustment::borrow(Mutability::Mut, derefed_callee.clone()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue