Placeholder Syntax - Revisited

The specific case of things like .map(|x| x.foo()) where that's using autoderef and can't be written as .map(T::foo) I've run into many times and been mildly annoyed by each time. I've even written .map(Deref::deref).map(T::foo) at least once to stay pointfree.

Generalized placeholder based closures are fundamentally (human) ambiguous unless the language is designed around supporting it, e.g. like Kotlin or Swift, where closures are always {}-delimited. (And even there, nesting closures with implicitly and explicitly named arguments is problematic.)

I think Rust could get away with and probably benefit from specifically allowing pointfree single-argument closures only for method calls with the argument as a receiver. Allowing _ as a single complete argument to a function call is potentially arguable (but is very context dependent imho, which makes it problematic), but anything beyond that is too far into (human) ambiguity to justify.

4 Likes