semgrep / semgrep

Lightweight static analysis for many languages. Find bug variants with patterns that look like source code.

Home Page:https://semgrep.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`match` matching ignores the branches enum variant names

Ten0 opened this issue · comments

Describe the bug
In semgrep's Rust matching, match matching ignores the branches enum variant names

To Reproduce
https://semgrep.dev/playground/s/ZqJ1W

rules:
  - id: my_pattern_id
    languages:
      - rust
    severity: ERROR
    message: Semgrep found a match
    pattern: match ... { Ok(_) => ..., Err(_) => ... }
match f() {
   Abc(_) => {}
   Def(_) => {}
}

Expected behavior
Does not match

Actual behavior
image

What is the priority of the bug to you?

  • P0: blocking your adoption of Semgrep or workflow
  • P1: important to fix or quite annoying
  • P2: regular bug that should get fixed

Use case

CI makes good practices check based on semgrep. We want to forbid underscore-matching both the Ok and Err variant of a result, but this creates a lot of false positives.