nightly throws needless_return warning on anyhow::bail! #16725
Closed
Description
opened on Mar 1, 2024
When using anyhow::bail!
like this (which is a really common use case):
fn cool_function(i: i32) -> Result<i32, anyhow::Error>{
match i {
1 => Ok(1),
2 => Ok(2),
_ => anyhow::bail!("out of range"),
}
}
the nightly rust-analyzer gives this diagnostic warning:
replace <expr>; with <expr> [needless_return]
which is expected because bail! expands roughly to return Err(...)
, which obviously triggers the above error.
This only happens with the nightly rust-analyzer (rust-analyzer 0.4.1863-standalone) and I don't get this warning with clippy.
Original issue in anyhow repo: dtolnay/anyhow#351
Activity