rust-lang / rust-lang/rust-clippy

Make `manual_let_else` to lint `if let`s at the end of a function or loop

Open
#16,649 1 comment 0 reactions 1 assignee View on GitHub

@profetia is already working on this.

Since Feb 27, 2026.

C-enhancement
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Description

Make manual_let_else to lint if lets at the end of a function or loop. For example:

fn reproducer(mut c: Vec<Option<i32>>) {
    let w = Some(0);
    if let Some(v) = w {
        c.push(Some(v));
        for mut i in c {
            i = i.filter(|x| *x > 0);
            if let Some(v) = i {
                let _ = v;
                println!("{v}");
            }
        }
    }
}

Changing the two if lets into let elses would result in more compact code and less nesting:

fn reproducer(mut c: Vec<Option<i32>>) {
    let w = Some(0);
    let Some(v) = w else {
        return;
    };
    c.push(Some(v));
    for mut i in c {
        i = i.filter(|x| *x > 0);
        let Some(v) = i else {
            continue;
        };
        let _ = v;
        println!("{v}");
    }
}
Version
rustc 1.95.0-nightly (c04308580 2026-02-18)
binary: rustc
commit-hash: c043085801b7a884054add21a94882216df5971c
commit-date: 2026-02-18
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 22.1.0
Additional Labels

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.