Closed
Description
Hi!
Here is a minimal example to highlight the issue:
pub fn get_result() -> Result<Vec<i32>, String> {
Ok(vec![0, 2, 4])
}
pub fn weird() {
// This line triggers clippy::redundant_closure:
// warning: redundant closure
// --> src/lib.rs:6:42
// |
// | let _x = get_result().unwrap_or_else(|_| vec![]);
// | ^^^^^^^^^^ help: replace the closure with `Vec::new`: `std::vec::Vec::new`
// |
// = 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
let _x = get_result().unwrap_or_else(|_| vec![]);
// This line doesn't trigger any warning
let _y = get_result().unwrap_or_else(|_| Vec::new());
let _z = get_result().unwrap_or_else(|_| vec![0]);
}
clippy
suggests to update the code with something invalid as Vec::new
is not equivalent to |_| vec![]
which takes a parameter.
I think this may be related to #3071 but still seems to be a different issue since the vec![]
macro call appears to be what causes it (there is no problem using Vec::new()
).
Meta
cargo clippy -V
: clippy 0.1.53 (53cb7b0 2021-06-17)rustc -Vv
:rustc 1.53.0 (53cb7b09b 2021-06-17) binary: rustc commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b commit-date: 2021-06-17 host: x86_64-unknown-linux-gnu release: 1.53.0 LLVM version: 12.0.1