rust-lang / rust-lang/rustfmt

A brace style that puts { on a new line if the function or if condition is multiline

Open
#4,825 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request P-low
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

In terms of the placement of the {, the following style is one I prefer to use. Examples by showing expected style below.

Expected (same line { when function signature is short - this is similar to existing SameLineWhere):

fn lorem(ipsum: usize) -> usize {
    ipsum
}

Expected style (new line before { with multiline function signature)

fn format_with_overflow(f: &mut fmt::Formatter<'_>, length: usize, limit: usize,
                        separator: &str, ellipsis: &str,
                        fmt_elem: &mut dyn FnMut(&mut fmt::Formatter, usize) -> fmt::Result)
                        -> fmt::Result
{
    Ok(())
}

Expected style - alternate (new line before { with multiline function signature)

fn format_with_overflow(
    f: &mut fmt::Formatter<'_>, length: usize, limit: usize, separator: &str, ellipsis: &str,
    fmt_elem: &mut dyn FnMut(&mut fmt::Formatter, usize) -> fmt::Result,
) -> fmt::Result
{
    Ok(())
}

Description: Like SameLineWhere except newline before the opening brace if the function signature is multi-line.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining rustfmt's existing SameLineWhere behavior and how it detects multiline function signatures or if conditions. Compare the requested examples with current formatting, then determine the affected formatting paths and tests; done means the brace stays on the same line for short constructs and moves to a new line for multiline ones.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.