Closed
Description
Lint name: redundant_closure
With this code:
fn explode() -> ! {
panic!("never returns")
}
fn main() {
Some(32).unwrap_or_else(|| explode());
}
Clippy emits the following warning:
warning: redundant closure
--> src\main.rs:6:29
|
6 | Some(32).unwrap_or_else(|| explode());
| ^^^^^^^^^^^^ help: replace the closure with the function itself: `explode`
|
= note: `#[warn(clippy::redundant_closure)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
However, I cannot inline the closure and use the function pointer directly -- this code:
fn explode() -> ! {
panic!("never returns")
}
fn main() {
Some(32).unwrap_or_else(explode);
}
fails to compile with:
error[E0271]: type mismatch resolving `<fn() -> ! {explode} as std::ops::FnOnce<()>>::Output == {integer}`
--> src\main.rs:6:14
|
6 | Some(32).unwrap_or_else(explode);
| ^^^^^^^^^^^^^^ expected `!`, found integer
|
= note: expected type `!`
found type `{integer}`
For more information about this error, try `rustc --explain E0271`
Meta
Rust version (rustc -Vv
):
rustc 1.57.0-nightly (5b210643e 2021-10-11)
binary: rustc
commit-hash: 5b210643ebf2485aafdf2494de8cf41941a64e95
commit-date: 2021-10-11
host: x86_64-pc-windows-msvc
release: 1.57.0-nightly
LLVM version: 13.0.0
Related, but not identical issues ( redundant_closure
false positives):