ExprUseVisitor: treat ByValue use of Copy types as ImmBorrow
This commit is contained in:
parent
e9a387d6cf
commit
10b536fc71
2 changed files with 21 additions and 8 deletions
|
@ -1535,10 +1535,9 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> {
|
||||||
place_with_id, diag_expr_id, mode
|
place_with_id, diag_expr_id, mode
|
||||||
);
|
);
|
||||||
|
|
||||||
// Copy type being used as ByValue are equivalent to ImmBorrow and don't require any
|
// Copy types in ByValue scenarios need should be treated as ImmBorrows
|
||||||
// escalation.
|
|
||||||
match mode {
|
match mode {
|
||||||
euv::ConsumeMode::Copy => return,
|
euv::ConsumeMode::Copy => unreachable!(),
|
||||||
euv::ConsumeMode::Move => {}
|
euv::ConsumeMode::Move => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
||||||
debug!("delegate_consume(place_with_id={:?})", place_with_id);
|
debug!("delegate_consume(place_with_id={:?})", place_with_id);
|
||||||
|
|
||||||
let mode = copy_or_move(&self.mc, 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<'_>]) {
|
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);
|
delegate.borrow(place, discr_place.hir_id, bk);
|
||||||
}
|
}
|
||||||
ty::BindByValue(..) => {
|
ty::BindByValue(..) => {
|
||||||
let mode = copy_or_move(mc, &place);
|
|
||||||
debug!("walk_pat binding consuming pat");
|
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 {
|
match capture_info.capture_kind {
|
||||||
ty::UpvarCapture::ByValue(_) => {
|
ty::UpvarCapture::ByValue(_) => {
|
||||||
let mode = copy_or_move(&self.mc, &place_with_id);
|
self.delegate_consume(&place_with_id, place_with_id.hir_id);
|
||||||
self.delegate.consume(&place_with_id, place_with_id.hir_id, mode);
|
|
||||||
}
|
}
|
||||||
ty::UpvarCapture::ByRef(upvar_borrow) => {
|
ty::UpvarCapture::ByRef(upvar_borrow) => {
|
||||||
self.delegate.borrow(
|
self.delegate.borrow(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue