address most easy comments

This commit is contained in:
Ziru Niu 2023-05-31 19:13:13 +08:00
parent 8fb4c41f35
commit a52cc0a8c9
8 changed files with 33 additions and 42 deletions

View file

@ -456,7 +456,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
}
}
Rvalue::Ref(_, kind @ BorrowKind::Mut { .. }, place) => {
Rvalue::Ref(_, BorrowKind::Mut { .. }, place) => {
let ty = place.ty(self.body, self.tcx).ty;
let is_allowed = match ty.kind() {
// Inside a `static mut`, `&mut [...]` is allowed.
@ -477,11 +477,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
};
if !is_allowed {
if let BorrowKind::Mut { .. } = kind {
self.check_mut_borrow(place.local, hir::BorrowKind::Ref)
} else {
self.check_op(ops::CellBorrow);
}
self.check_mut_borrow(place.local, hir::BorrowKind::Ref)
}
}

View file

@ -465,7 +465,9 @@ impl<'tcx> Validator<'_, 'tcx> {
}
}
BorrowKind::Mut { .. } => {
// FIXME: consider changing this to only promote &mut [] for default borrows,
// also forbidding two phase borrows
BorrowKind::Mut { kind: MutBorrowKind::Default | MutBorrowKind::TwoPhaseBorrow } => {
let ty = place.ty(self.body, self.tcx).ty;
// In theory, any zero-sized value could be borrowed