tokio-rs / async-stream

Asynchronous streams for Rust using async & await notation
Other
636 stars 33 forks source link

`let` - `else` expressions don't work with try stream #89

Closed Soremwar closed 1 year ago

Soremwar commented 1 year ago
fn stream() -> impl Stream<Item = Result<u8, ()>>{
  yield 1;

  let Ok(x) = Err("a") else {
    Err(())?;
  };
}
expected !, found ()
rust-analyzer[type-mismatch](https://rust-analyzer.github.io/manual.html#type-mismatch)
`else` clause of `let...else` does not diverge
  expected type `!`
found unit type `()`
try adding a diverging expression, such as `return` or `panic!(..)`
taiki-e commented 1 year ago

I don't know the exact situation because the example you provided contains neither the stream macro nor the try_stream macro, but it is probably because syn parses let-else as Expr::Verbatim.

In that case, it could be fixed by one of the following: adjusting our code to visit Expr::Verbatim, relanding #53 (see #56), or waiting for syn 2 including https://github.com/dtolnay/syn/pull/1231 to be released.

taiki-e commented 1 year ago

Should be fixed in 0.3.5 which updated syn to 2.