Closed
Description
Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=cc081036ff00b0844aac10d9fdac636f
fn foo(_f: impl Fn()) {}
fn bar() -> i32 { 1 }
fn main() {
foo(|| bar())
}
The current output is:
error[E0308]: mismatched types
--> src/main.rs:6:12
|
5 | fn main() {
| - expected `()` because of default return type
6 | foo(|| bar())
| ^^^^^ expected `()`, found `i32`
Ideally rustc should suggest adding a semicolon (and a block):
error[E0308]: mismatched types
--> src/main.rs:6:14
|
6 | foo(|| { bar(); })
| ++ +++- help: consider using a semicolon here
| |
| expected `()`, found `i32`
It already does that if we have a block https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=433c9f8d9638e927fe4f5ba66d5551fa:
foo(|| { bar() })
error[E0308]: mismatched types
--> src/main.rs:6:14
|
6 | foo(|| { bar() })
| ^^^^^- help: consider using a semicolon here: `;`
| |
| expected `()`, found `i32`
@rustbot label +A-suggestion-diagnostics
@rustbot claim
Noticed by this StackOverflow question.