|_| comes up in a lot of uses of map, map_err, unwrap_or_else, and other methods that take closures. It’s annoying to type, and unsightly—to me at least!
I wanted to get people’s thoughts on allowing writing || expr in these cases when all parameters are being ignored. I think it fits in with Rust’s embracing of local inference to make things easier to type and read.
Is this something worth expanding into an RFC?
A couple examples from the Rust codebase:
// src/librustc_mir/borrow_check/nll/region_infer/values.rs:230
self.add_internal(r, i, |_| cause.clone())
// src/librustc_metadata/locator.rs:873
let buf = fs::read(filename).map_err(|_|
format!("failed to read rmeta metadata: '{}'", filename.display()))?;
// src/librustc_typeck/check/closure.rs:99
let substs = base_substs.extend_to(
self.tcx,
expr_def_id,
|_, _| span_bug!(expr.span, "closure has region param"),
|_, _| {
self.infcx
.next_ty_var(TypeVariableOrigin::ClosureSynthetic(expr.span))
},
);