Skip to content

needless_return misfires in a let-else statement (RFC 3137) #7637

@yvt

Description

@yvt

Lint name: needless_return

I tried this code:

#![feature(let_else)]
pub fn hoge(x: Option<u32>) {
    let Some(x) = x else { return; };
    dbg!(x);
}

I expected to see this happen: No warnings emitted

Instead, this happened:

    Checking playground v0.0.1 (/playground)
warning: unneeded `return` statement
 --> src/lib.rs:3:28
  |
3 |     let Some(x) = x else { return; };
  |                            ^^^^^^^ help: remove `return`
  |
  = note: `#[warn(clippy::needless_return)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

Meta

Rust version (rustc -Vv):

rustc 1.56.0-nightly (50171c310 2021-09-01)
binary: rustc
commit-hash: 50171c310cd15e1b2d3723766ce64e2e4d6696fc
commit-date: 2021-09-01
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 13.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions