Skip to content

Commit 530fc82

Browse files
committed
Make yielder::pair unsafe
1 parent b874e32 commit 530fc82

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

async-stream-impl/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub fn stream_inner(input: TokenStream) -> TokenStream {
227227
};
228228

229229
quote!({
230-
let (mut __yield_tx, __yield_rx) = #crate_path::__private::yielder::pair();
230+
let (mut __yield_tx, __yield_rx) = unsafe { #crate_path::__private::yielder::pair() };
231231
#crate_path::__private::AsyncStream::new(__yield_rx, async move {
232232
#dummy_yield
233233
#(#stmts)*
@@ -261,7 +261,7 @@ pub fn try_stream_inner(input: TokenStream) -> TokenStream {
261261
};
262262

263263
quote!({
264-
let (mut __yield_tx, __yield_rx) = #crate_path::__private::yielder::pair();
264+
let (mut __yield_tx, __yield_rx) = unsafe { #crate_path::__private::yielder::pair() };
265265
#crate_path::__private::AsyncStream::new(__yield_rx, async move {
266266
#dummy_yield
267267
#(#stmts)*

async-stream/src/yielder.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ pub(crate) struct Enter<'a, T> {
2020
prev: *mut (),
2121
}
2222

23+
// Note: It is considered unsound for anyone other than our macros to call
24+
// this function. This is a private API intended only for calls from our
25+
// macros, and users should never call it, but some people tend to
26+
// misinterpret it as fine to call unless it is marked unsafe.
2327
#[doc(hidden)]
24-
pub fn pair<T>() -> (Sender<T>, Receiver<T>) {
28+
pub unsafe fn pair<T>() -> (Sender<T>, Receiver<T>) {
2529
let tx = Sender { _p: PhantomData };
2630
let rx = Receiver { _p: PhantomData };
2731
(tx, rx)

0 commit comments

Comments
 (0)