Skip to content

match_bool: --fix drops the parentheses around (match b { .. }) | 4 #17998

Open

Description

@alpaylan

Summary

The match_bool suggestion drops the parentheses around (match b { .. }) | 4, so the resulting if parses as a statement and the fixed code does not compile.

Reproducer

fn f(b: bool) -> i32 {
    (match b { true => 1, false => 2 }) | 4
}

fn main() {
    println!("{}", f(true));
}

cargo clippy --fix -- -W clippy::match_bool

Expected:

fn f(b: bool) -> i32 {
    (if b { 1 } else { 2 }) | 4
}

fn main() {
    println!("{}", f(true));
}

Prints 5.

Actual:

fn f(b: bool) -> i32 {
    if b { 1 } else { 2 } | 4
}

error[E0308]: mismatched types

Version

rustc 1.101.0-nightly (249c1e4e3 2026-11-05)
binary: rustc
commit-hash: 249c1e4e31111b54ad2483cfd4cea06c7020c653
commit-date: 2026-11-05
host: x86_64-unknown-linux-gnu
release: 1.101.0-nightly
LLVM version: 23.1.5

Also reproduces on clippy master 321d566 (2026-11-06).

Additional Labels

I-suggestion-causes-error

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions