Skip to content

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

Closed
@kaffarell

Description

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsdiagnostics / error reportingA-macromacro expansionC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions