Skip to content

Missing trailing expression in block with let else yields incorrectly spanned error message #94176

@JakobDegen

Description

@JakobDegen

I tried this code:

#![feature(let_else)] pub fn test(a: Option<u32>) -> Option<u32> { let Some(_) = a else { return None; }; println!("Foo"); } fn main() {}

I expected to see this happen: A helpful error message pointing to the end of the block.

Instead, this happened: An error message with a wrong span:

error[E0308]: mismatched types --> test.rs:4:5 | 4 | let Some(_) = a else { return None; }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `Option`, found `()` | = note: expected enum `Option<u32>` found unit type `()` error: aborting due to previous error For more information about this error, try `rustc --explain E0308`.

Meta

rustc --version --verbose:

rustc 1.60.0-nightly (b17226fcc 2022-02-18) binary: rustc commit-hash: b17226fcc11587fed612631be372a5b4cb89988a commit-date: 2022-02-18 host: x86_64-unknown-linux-gnu release: 1.60.0-nightly LLVM version: 14.0.0 

cc #87335

@rustbot labels: +T-compiler +F-let-else +requires-nightly +A-diagnostics

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.F-let_elseIssues related to let-else statements (RFC 3137)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions