rust-analyzer nightly throws needless_return warning on bail!
Closed this issue · 2 comments
kaffarell commented
When using 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.
Now the question is if this is better fixed in rust-analyzer (maybe introduce an exception when using macros) or in anyhow.
dtolnay commented
This is a rust-analyzer bug. cargo clippy
correctly does not report this lint.
kaffarell commented
Reported this on the rust-analyzer issue-tracker (rust-lang/rust-analyzer#16725)