Skip to content

Commit 3fa692c

Browse files
committed
for now, do not do fake reads on non-Unpin mutable references
1 parent 3b4cbe9 commit 3fa692c

File tree

3 files changed

+14
-54
lines changed

3 files changed

+14
-54
lines changed

src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ pub struct Stacks {
4545
/// new pointer.
4646
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
4747
enum RefKind {
48-
/// `&mut` and `Box`.
48+
/// `Box`.
49+
Box,
50+
/// `&mut`.
4951
Unique { two_phase: bool },
5052
/// `&` with or without interior mutability.
5153
Shared,
@@ -56,6 +58,7 @@ enum RefKind {
5658
impl fmt::Display for RefKind {
5759
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5860
match self {
61+
RefKind::Box => write!(f, "Box"),
5962
RefKind::Unique { two_phase: false } => write!(f, "unique reference"),
6063
RefKind::Unique { two_phase: true } => write!(f, "unique reference (two-phase)"),
6164
RefKind::Shared => write!(f, "shared reference"),
@@ -654,15 +657,17 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
654657
let (perm, access) = match kind {
655658
RefKind::Unique { two_phase } => {
656659
// Permission is Unique only if the type is `Unpin` and this is not twophase
657-
let perm = if !two_phase && place.layout.ty.is_unpin(*this.tcx, this.param_env()) {
658-
Permission::Unique
660+
if !two_phase && place.layout.ty.is_unpin(*this.tcx, this.param_env()) {
661+
(Permission::Unique, Some(AccessKind::Write))
659662
} else {
660-
Permission::SharedReadWrite
661-
};
662-
// We do an access for all full borrows, even if `!Unpin`.
663-
let access = if !two_phase { Some(AccessKind::Write) } else { None };
664-
(perm, access)
663+
// FIXME: We emit `dereferenceable` for `!Unpin` mutable references, so we
664+
// should do fake accesses here. But then we run into
665+
// <https://github.com/rust-lang/unsafe-code-guidelines/issues/381>, so for now
666+
// we don't do that.
667+
(Permission::SharedReadWrite, None)
668+
}
665669
}
670+
RefKind::Box => (Permission::Unique, Some(AccessKind::Write)),
666671
RefKind::Raw { mutable: true } => {
667672
// Creating a raw ptr does not count as an access
668673
(Permission::SharedReadWrite, None)
@@ -853,7 +858,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
853858
// Boxes get a weak protectors, since they may be deallocated.
854859
self.retag_place(
855860
place,
856-
RefKind::Unique { two_phase: false },
861+
RefKind::Box,
857862
self.retag_cause,
858863
/*protector*/
859864
(self.kind == RetagKind::FnEntry).then_some(ProtectorKind::WeakProtector),

src/tools/miri/tests/fail/stacked_borrows/notunpin_dereferenceable_fakeread.rs

-17
This file was deleted.

src/tools/miri/tests/fail/stacked_borrows/notunpin_dereferenceable_fakeread.stderr

-28
This file was deleted.

0 commit comments

Comments
 (0)