Skip to content

Commit

Permalink
Fix unsoundness issues tokio-rs#106 and tokio-rs#107
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Jun 26, 2024
1 parent e8abfaa commit da7886f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
27 changes: 20 additions & 7 deletions async-stream-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,19 @@ impl VisitMut for Scrub<'_> {

// let ident = &self.yielder;

*i = if self.is_try {
syn::parse_quote! { __yield_tx.send(::core::result::Result::Ok(#value_expr)).await }
let yield_expr = if self.is_try {
quote! { __yield_tx.send(::core::result::Result::Ok(#value_expr)).await }
} else {
syn::parse_quote! { __yield_tx.send(#value_expr).await }
quote! { __yield_tx.send(#value_expr).await }
};
*i = syn::parse_quote! {
{
#[allow(unreachable_code)]
if false {
break 'check_stream_scope (loop {});
}
#yield_expr
}
};
}
syn::Expr::Try(try_expr) => {
Expand Down Expand Up @@ -225,8 +234,10 @@ pub fn stream_inner(input: TokenStream) -> TokenStream {
quote!({
let (mut __yield_tx, __yield_rx) = unsafe { #crate_path::__private::yielder::pair() };
#crate_path::__private::AsyncStream::new(__yield_rx, async move {
#dummy_yield
#(#stmts)*
'check_stream_scope: {
#dummy_yield
#(#stmts)*
}
})
})
.into()
Expand Down Expand Up @@ -259,8 +270,10 @@ pub fn try_stream_inner(input: TokenStream) -> TokenStream {
quote!({
let (mut __yield_tx, __yield_rx) = unsafe { #crate_path::__private::yielder::pair() };
#crate_path::__private::AsyncStream::new(__yield_rx, async move {
#dummy_yield
#(#stmts)*
'check_stream_scope: {
#dummy_yield
#(#stmts)*
}
})
})
.into()
Expand Down
2 changes: 1 addition & 1 deletion async-stream/src/yielder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::task::{Context, Poll};

#[derive(Debug)]
pub struct Sender<T> {
_p: PhantomData<T>,
_p: PhantomData<fn(T) -> T>,
}

#[derive(Debug)]
Expand Down

0 comments on commit da7886f

Please sign in to comment.