rust-lang / rust-lang/rustfmt

rustfmt removes empty newlines between blocks of module-level attributes

Open
#4,082 8 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-attributes A-whitespace C-discussion E-needs-investigation I-poor-formatting
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

In a situation like

#![feature(core_intrinsics)]
#![feature(lang_items)]
#![feature(libc)]
#![feature(nll)]
#![feature(panic_unwind)]
#![feature(staged_api)]
#![feature(std_internals)]
#![feature(unwind_attributes)]
#![feature(abi_thiscall)]
#![feature(rustc_attrs)]
#![feature(raw)]
#![panic_runtime]
#![feature(panic_runtime)]

// `real_imp` is unused with Miri, so silence warnings.
#![cfg_attr(miri, allow(dead_code))]

rustfmt removes that empty line. That's not great, as grouping these attributes by "paragraphs" conveys semantic meaning.

rustfmt preserves empty lines between statements, so it seems like the semantic value of that information is acknowledged, but it is not done consistently.

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 reproducing the issue with the module-level attribute example in the report, then compare it with rustfmt's existing handling of empty lines between statements. Trace the formatting path for module-level attributes and locate the related formatter tests. Done means the blank line between attribute groups is preserved without changing the existing statement behavior.

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
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.