#7120·rustfmt

[Feature Request] Allow configurable number of blank lines before control structures

Author: zeon256Created Sep 14, 2026Updated Sep 14, 2026
LabelsP-lowC-feature-request

Feature Request

Allow configurable number of blank lines before control structures like the following:

  • for
  • while
  • match
  • if/else
  • loop

Take a look at these examples:

Before:

rust
fn main() {
    let data = vec![1, 2, 3];
    for d in data {
       // ....
    }
}

After:

rust
fn main() {
    let data = vec![1, 2, 3];

    for d in data {
      // notice the blank line before this for loop
    }
}

However, it should not do it for the following (in the else branch):

rust
let x = if condition {
    foo()
} else {
    bar()
};

and not for nested control structures:

rust
if a {
    if b {
        ...
    }
}

Perhaps these can come as:

blank_lines_before_control_flow_statements = 1

Summary

Allow configurable number of blank lines before control flow structures.

Motivation

In cases where the number of lines is a lot, having no blank lines before control flow structures makes it very difficult to scan implementations. While it is trivial to add a line before control structures, I would like to have something automated across the codebase and this can be useful in cases where codegen (not necessarily LLMs, more like using tools like an openapi -> rust generator) is involved

This was discussed back in 2017 in https://github.com/rust-lang/style-team/issues/57 except that my particular feature request is a much more narrow impl of it. Apologies if I missed out other discussion surrounding this

Related configuration options

AFAIK, blank_lines_lower_bound and blank_lines_upper_bound are tangibly related but kinda different.

Possibly related issues

PR

I am open to try to implement this feature if the team and wider community is in a agreement with this.

Thanks!