Skip to content

Commit 1fa31c5

Browse files
committed
Fix stacked borrows violation with -Zmiri-tag-raw-pointers
1 parent 31708e4 commit 1fa31c5

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
run: rustup toolchain install nightly --component miri && rustup default nightly
7171
- run: cargo miri test
7272
env:
73-
MIRIFLAGS: -Zmiri-disable-isolation
73+
MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-tag-raw-pointers
7474

7575
security_audit:
7676
runs-on: ubuntu-latest

src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl Event {
175175
let inner = self.inner();
176176
let listener = EventListener {
177177
inner: unsafe { Arc::clone(&ManuallyDrop::new(Arc::from_raw(inner))) },
178-
entry: Some(inner.lock().insert(inner.cache_ptr())),
178+
entry: unsafe { Some((*inner).lock().insert((*inner).cache_ptr())) },
179179
};
180180

181181
// Make sure the listener is registered before whatever happens next.
@@ -365,8 +365,11 @@ impl Event {
365365
unsafe { inner.as_ref() }
366366
}
367367

368-
/// Returns a reference to the inner state, initializing it if necessary.
369-
fn inner(&self) -> &Inner {
368+
/// Returns a raw pointer to the inner state, initializing it if necessary.
369+
///
370+
/// This returns a raw pointer instead of reference because `from_raw`
371+
/// requires raw/mut provenance: <https://github.com/rust-lang/rust/pull/67339>
372+
fn inner(&self) -> *const Inner {
370373
let mut inner = self.inner.load(Ordering::Acquire);
371374

372375
// Initialize the state if this is its first use.
@@ -410,7 +413,7 @@ impl Event {
410413
}
411414
}
412415

413-
unsafe { &*inner }
416+
inner
414417
}
415418
}
416419

0 commit comments

Comments
 (0)