Skip to content

Type mismatch helper not check is closure return block #155670

@A4-Tacks

Description

@A4-Tacks

Code

struct SmolStr;
const _: fn() = || {
    match Some(()) {
        Some(()) => (),
        None => return,
    };
    let _: String = {
        SmolStr
    };
};

Current output

error[E0308]: mismatched types
 --> src/lib.rs:8:9
  |
8 |         SmolStr
  |         ^^^^^^^ expected `String`, found `SmolStr`
  |
note: return type inferred to be `String` here
 --> src/lib.rs:5:17
  |
5 |         None => return,
  |                 ^^^^^^

Desired output

error[E0308]: mismatched types
 --> src/lib.rs:8:9
  |
8 |         SmolStr
  |         ^^^^^^^ expected `String`, found `SmolStr`
  |

Rationale and extra context

No response

Other cases

struct SmolStr;
const _: fn() = || {
    match Some(()) {
        Some(()) => (),
        None => return,
    };
    let _: String = SmolStr;
};

Rust Version

rustc 1.97.0-nightly (913e4bea8 2026-04-22)
binary: rustc
commit-hash: 913e4bea83424658d76712fee9c52452a3a9ef0e
commit-date: 2026-04-22
host: aarch64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.2

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.S-has-bisectionStatus: A bisection has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions