Closed
Description
What it does
Warns on a |x| x
pattern, which looks like a closure.
Lint Name
pattern_leading_pipe
Category
suspicious
Advantage
- Avoids confusion of "or" pattern having a leading pipe (which is discarded), with a closure, enclosing arguments in pipes.
Drawbacks
None
Example
let (|x| x) = match x(..) {
|_| Some(2) => |_| Some(3),
|_| _ => unreachable!(),
};
assert!(matches!(x(..), |_| Some(4)));
(borrowed from weird-exprs.rs)
Could be written as:
let (x | x) = match x(..) {
_ | Some(2) => |_| Some(3),
_ | _ => unreachable!(),
};
assert!(matches!(x(..), _ | Some(4)));