Skip to content

Commit 6556bfc

Browse files
taiki-ecarllerche
authored andcommitted
Fix an issue with multiple try operators (#23)
1 parent 1af6795 commit 6556bfc

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

async-stream-impl/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl VisitMut for Scrub {
8282
};
8383
}
8484
syn::Expr::Try(try_expr) => {
85+
syn::visit_mut::visit_expr_try_mut(self, try_expr);
8586
// let ident = &self.yielder;
8687
let e = &try_expr.expr;
8788

async-stream/tests/try_stream.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,21 @@ async fn convert_err() {
6060
assert_eq!(1, values.len());
6161
assert_eq!(Err(ErrorB(1)), values[0]);
6262
}
63+
64+
#[tokio::test]
65+
async fn multi_try() {
66+
fn test() -> impl Stream<Item = Result<i32, String>> {
67+
try_stream! {
68+
let a = Ok::<_, String>(Ok::<_, String>(123))??;
69+
for _ in (1..10) {
70+
yield a;
71+
}
72+
}
73+
}
74+
let values: Vec<_> = test().collect().await;
75+
assert_eq!(9, values.len());
76+
assert_eq!(
77+
std::iter::repeat(123).take(9).map(Ok).collect::<Vec<_>>(),
78+
values
79+
);
80+
}

0 commit comments

Comments
 (0)