Skip to content

rust-analyzer nightly throws needless_return warning on bail! #351

@kaffarell

Description

@kaffarell

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions