Skip to content

Commit 45d6ca9

Browse files
authored
Merge pull request #55 from sunfishcode/sunfishcode/unsafe
Reinstate `#![forbid(unsafe_code)]`.
2 parents e152197 + 0b0dec7 commit 45d6ca9

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ $ cargo add wstd
8181
```
8282

8383
## Safety
84-
This crate uses ``#![deny(unsafe_code)]`` to ensure everything is implemented in
84+
This crate uses ``#![forbid(unsafe_code)]`` to ensure everything is implemented in
8585
100% Safe Rust.
8686

8787
## Contributing

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(async_fn_in_trait)]
22
#![warn(future_incompatible, unreachable_pub)]
3+
#![forbid(unsafe_code)]
34
//#![deny(missing_debug_implementations)]
45
//#![warn(missing_docs)]
56
//#![forbid(rustdoc::missing_doc_code_examples)]

src/runtime/block_on.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use super::{Reactor, REACTOR};
22

33
use core::future::Future;
44
use core::pin::pin;
5-
use core::ptr;
65
use core::task::Waker;
7-
use core::task::{Context, Poll, RawWaker, RawWakerVTable};
6+
use core::task::{Context, Poll};
7+
use std::sync::Arc;
8+
use std::task::Wake;
89

910
/// Start the event loop
1011
pub fn block_on<Fut>(fut: Fut) -> Fut::Output
@@ -42,18 +43,11 @@ where
4243
/// Construct a new no-op waker
4344
// NOTE: we can remove this once <https://github.com/rust-lang/rust/issues/98286> lands
4445
fn noop_waker() -> Waker {
45-
const VTABLE: RawWakerVTable = RawWakerVTable::new(
46-
// Cloning just returns a new no-op raw waker
47-
|_| RAW,
48-
// `wake` does nothing
49-
|_| {},
50-
// `wake_by_ref` does nothing
51-
|_| {},
52-
// Dropping does nothing as we don't allocate anything
53-
|_| {},
54-
);
55-
const RAW: RawWaker = RawWaker::new(ptr::null(), &VTABLE);
56-
57-
// SAFETY: all fields are no-ops, so this is safe
58-
unsafe { Waker::from_raw(RAW) }
46+
struct NoopWaker;
47+
48+
impl Wake for NoopWaker {
49+
fn wake(self: Arc<Self>) {}
50+
}
51+
52+
Waker::from(Arc::new(NoopWaker))
5953
}

0 commit comments

Comments
 (0)