rust-lang / rust-lang/rustfmt

`control_brace_style` and `match_arm_blocks` incompatability

Open
#4,844 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-matches I-trailing-whitespace only-with-option P-low
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Coming from #3373.

There seems to be an issue which sometimes occurs whenever these two options are present at the same time in a rustfmt configuration:

control_brace_style = 'AlwaysNextLine'
match_arm_blocks = false

For example, take the following snippet from a cargo new main.rs file:

fn main() {
	let fooooooo = "100000000000000000000000";
	let _bar = match fooooooo {
		"100000000000000000000000" => fooooooo.len() == 1 && fooooooo.contains("222222222222222222"),
		_ => unreachable!("Should not happen"),
	};
}

Running cargo fmt on this code results in the following error:

error[internal]: left behind trailing whitespace
 --> /home/iron-e/Programming/ACTIVE/rustfmt-error-example/src/main.rs:6:6:1
  |
6 |
  | ^^^^^^^^
  |

warning: rustfmt has failed to format. See previous 1 errors.

It seems that line 4 of the snippet being >=95 characters long has something to do with it. The rest of the code is just filler to get it to compile.

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

Reproduce the issue using the provided main.rs snippet and the rustfmt configuration with control_brace_style = 'AlwaysNextLine' and match_arm_blocks = false; start by running cargo fmt. Compare behavior with shorter match-arm lines and identify the interaction that leaves trailing whitespace. Done means cargo fmt formats the example without the internal trailing-whitespace error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.