rust-lang / rust-lang/rust-clippy

`question_mark` suggestion has redundant block scope

Open
#16,892 3 comments 0 reactions 1 assignee View on GitHub

@profetia is already working on this.

Since Apr 28, 2026.

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

Description

Summary

The current suggestion introduces an unnecessary block scope { ... } when converting the if let ... else return None pattern into the ? operator form.

Context: https://github.com/fish-shell/fish-shell/commit/f385266719297d11bd7f941f7a66221e7c715dfc
Reproducer: https://rust.godbolt.org/z/hrszPr5xc

cc: @profetia

Reproducer

Code:

if let Some(x) = Some(1) {
    black_box(x);
} else {
    return None;
}
Some(())

Current output:

{
    let x = Some(1)?;
    black_box(x);
}
Some(())

Desired output:

let x = Some(1)?;
black_box(x);
Some(())
Version
clippy 0.1.97 (0febdbab27 2026-04-18)

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.