Skip to content

nightly throws needless_return warning on anyhow::bail! #16725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kaffarell opened this issue Mar 1, 2024 · 0 comments · Fixed by #16757
Closed

nightly throws needless_return warning on anyhow::bail! #16725

kaffarell opened this issue Mar 1, 2024 · 0 comments · Fixed by #16757
Labels
A-diagnostics diagnostics / error reporting A-macro macro expansion C-bug Category: bug

Comments

@kaffarell
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting A-macro macro expansion C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants