-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsC-bugCategory: This is a bug.Category: This is a bug.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.
Description
The following code:
fn tuple_closures_test(n: u32) {
let (print_it, is_zero) = match 0 {
0 => (|| println!("zero"), true),
_ => (|| println!("other"), false),
};
print_it();
}
Produces this error:
error[[E0308]](https://doc.rust-lang.org/stable/error-index.html#E0308): `match` arms have incompatible types
--> src/lib.rs:13:14
|
11 | let (print_it, is_zero) = match 0 {
| _______________________________-
12 | | 0 => (|| println!("zero"), true),
| | ---------------------------
| | ||
| | |the expected closure
| | this is found to be of type `([closure@src/lib.rs:12:15: 12:34], bool)`
13 | | _ => (|| println!("other"), false),
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected closure, found a different closure
14 | | };
| |_____- `match` arms have incompatible types
|
= note: expected tuple `([closure@src/lib.rs:12:15: 12:34], _)`
found tuple `([closure@src/lib.rs:13:15: 13:35], _)`
= note: no two closures, even if identical, have the same type
= help: consider boxing your closure and/or using it as a trait object
But I think it should compile by coercing the closures to fn
types. The following compiles:
fn test(n: u32) {
let print_it = match n {
0 => || println!("zero"),
_ => || println!("other"),
};
print_it();
}
Metadata
Metadata
Assignees
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsC-bugCategory: This is a bug.Category: This is a bug.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.