ExprUseVisitor: treat ByValue use of Copy types as ImmBorrow

This commit is contained in:
Aman Arora 2021-07-11 16:26:29 -04:00
parent e9a387d6cf
commit 10b536fc71
2 changed files with 21 additions and 8 deletions

View File

@ -1535,10 +1535,9 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> {
place_with_id, diag_expr_id, mode
);
// Copy type being used as ByValue are equivalent to ImmBorrow and don't require any
// escalation.
// Copy types in ByValue scenarios need should be treated as ImmBorrows
match mode {
euv::ConsumeMode::Copy => return,
euv::ConsumeMode::Copy => unreachable!(),
euv::ConsumeMode::Move => {}
};

View File

@ -144,7 +144,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
debug!("delegate_consume(place_with_id={:?})", place_with_id);
let mode = copy_or_move(&self.mc, place_with_id);
self.delegate.consume(place_with_id, diag_expr_id, mode);
match mode {
ConsumeMode::Move => self.delegate.consume(place_with_id, diag_expr_id, mode),
ConsumeMode::Copy => {
self.delegate.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow)
}
}
}
fn consume_exprs(&mut self, exprs: &[hir::Expr<'_>]) {
@ -653,9 +659,18 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
delegate.borrow(place, discr_place.hir_id, bk);
}
ty::BindByValue(..) => {
let mode = copy_or_move(mc, &place);
debug!("walk_pat binding consuming pat");
delegate.consume(place, discr_place.hir_id, mode);
let mode = copy_or_move(mc, &place);
match mode {
ConsumeMode::Move => {
delegate.consume(place, discr_place.hir_id, mode)
}
ConsumeMode::Copy => delegate.borrow(
place,
discr_place.hir_id,
ty::BorrowKind::ImmBorrow,
),
}
}
}
}
@ -773,8 +788,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
match capture_info.capture_kind {
ty::UpvarCapture::ByValue(_) => {
let mode = copy_or_move(&self.mc, &place_with_id);
self.delegate.consume(&place_with_id, place_with_id.hir_id, mode);
self.delegate_consume(&place_with_id, place_with_id.hir_id);
}
ty::UpvarCapture::ByRef(upvar_borrow) => {
self.delegate.borrow(