-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.F-let_elseIssues related to let-else statements (RFC 3137)Issues related to let-else statements (RFC 3137)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
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
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.F-let_elseIssues related to let-else statements (RFC 3137)Issues related to let-else statements (RFC 3137)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.