Skip to content

Warn on leading pipes in patterns #10717

Closed
@LeoniePhiline

Description

@LeoniePhiline

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)));

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-restrictionLint: Belongs in the restriction lint group

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions