Skip to content

Commit 793888f

Browse files
authored
fix: TimerFuture being Send and Sync (#470)
* fix: TimerFuture being Send and Sync * fix: ci
1 parent 878d7fa commit 793888f

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

compio-runtime/src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,27 @@ pub use runtime::{
2727
BorrowedBuffer, BufferPool, JoinHandle, Runtime, RuntimeBuilder, spawn, spawn_blocking, submit,
2828
submit_with_flags,
2929
};
30+
31+
/// Macro that asserts a type *DOES NOT* implement some trait. Shamelessly
32+
/// copied from <https://users.rust-lang.org/t/a-macro-to-assert-that-a-type-does-not-implement-trait-bounds/31179>.
33+
///
34+
/// # Example
35+
///
36+
/// ```rust,ignore
37+
/// assert_not_impl!(u8, From<u16>);
38+
/// ```
39+
macro_rules! assert_not_impl {
40+
($x:ty, $($t:path),+ $(,)*) => {
41+
const _: fn() -> () = || {
42+
struct Check<T: ?Sized>(T);
43+
trait AmbiguousIfImpl<A> { fn some_item() { } }
44+
45+
impl<T: ?Sized> AmbiguousIfImpl<()> for Check<T> { }
46+
impl<T: ?Sized $(+ $t)*> AmbiguousIfImpl<u8> for Check<T> { }
47+
48+
<Check::<$x> as AmbiguousIfImpl<_>>::some_item()
49+
};
50+
};
51+
}
52+
53+
use assert_not_impl;

compio-runtime/src/runtime/time.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{
22
cmp::Reverse,
33
collections::BinaryHeap,
44
future::Future,
5+
marker::PhantomData,
56
pin::Pin,
67
task::{Context, Poll, Waker},
78
time::{Duration, Instant},
@@ -125,11 +126,15 @@ impl TimerRuntime {
125126

126127
pub struct TimerFuture {
127128
key: usize,
129+
_local_marker: PhantomData<*const ()>,
128130
}
129131

130132
impl TimerFuture {
131133
pub fn new(key: usize) -> Self {
132-
Self { key }
134+
Self {
135+
key,
136+
_local_marker: PhantomData,
137+
}
133138
}
134139
}
135140

@@ -147,6 +152,8 @@ impl Drop for TimerFuture {
147152
}
148153
}
149154

155+
crate::assert_not_impl!(TimerFuture, Send, Sync);
156+
150157
#[test]
151158
fn timer_min_timeout() {
152159
let mut runtime = TimerRuntime::new();

0 commit comments

Comments
 (0)