Skip to content

expending lint [blocks_in_if_conditions] to check not only if's conditions, but also match's as welllΒ #11814

@J-ZhengLi

Description

@J-ZhengLi

What it does

Currently only the blocks in if conditions are warned, however, if readability was a concern then those blocks after match keyword should be treated the same right?

playground example

Advantage

  • Readability
  • Consistancy with [blocks_in_if_conditions]

Drawbacks

Could breaks auto-fix capability.

Check the second example, which a block was used in a while condition, however, if we move the block up and bind it as suggested, the code will not work, as x does not changes anymore causing an infinite loop.

But maybe we can skip such senario.

Example

fn match_block() {
    let _x: i32 = match {
        let opt: Option<u8> = Some(1);
        opt
    } {
        Some(num) => num.into(),
        None => -1
    };
}

Could be written as:

fn match_block() {
    let opt: Option<u8> = Some(1);
    let _x: i32 = match opt {
        Some(num) => num.into(),
        None => -1
    };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions