1
Fork 0

Suggest Pin::as_mut when encountering borrow error

This commit is contained in:
Esteban Küber 2022-12-23 09:59:39 -08:00
parent 984eab57f7
commit c79db9c5e5
5 changed files with 68 additions and 0 deletions

View file

@ -1133,6 +1133,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
place_name, partially_str, loop_message
),
);
if let ty::Adt(def, ..)
= moved_place.ty(self.body, self.infcx.tcx).ty.kind()
&& Some(def.did()) == self.infcx.tcx.lang_items().pin_type()
{
err.span_suggestion_verbose(
fn_call_span.shrink_to_lo(),
"consider reborrowing the `Pin` instead of moving it",
"as_mut().".to_string(),
Applicability::MaybeIncorrect,
);
}
}
let tcx = self.infcx.tcx;
// Avoid pointing to the same function in multiple different