Skip to content

single_line_if_else_max_width doesn't apply to if-only expressions? #1908

Closed
@Sushisource

Description

@Sushisource

If I've got a nasty blob like:

  fn neighbor_count(&self, x: usize, y: usize) -> i32 {
    let mut count = 0;
    if x >= 1 {
      if y >= 1 && self.ca_grid[x - 1][y - 1] {
        count += 1
      }
      if self.ca_grid[x - 1][y] {
        count += 1
      }
      if self.ca_grid[x - 1][y + 1] {
        count += 1
      }
    }
    if y >= 1 && self.ca_grid[x][y - 1] {
      count += 1
    }
    if self.ca_grid[x][y + 1] {
      count += 1
    }
    if y >= 1 && self.ca_grid[x + 1][y - 1] {
      count += 1
    }
    if self.ca_grid[x + 1][y] {
      count += 1
    }
    if self.ca_grid[x + 1][y + 1] {
      count += 1
    }
    count
  }

Ideally those ifs would get flattened if I they fit under single_line_if_else_max_width, but rustfmt seems intent on breaking them up. Am I missing something, or is this expected?

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