Skip to content

Let empty files be empty files#6839

Merged
ytmimi merged 6 commits intorust-lang:mainfrom
notpeter:empty_file
Mar 27, 2026
Merged

Let empty files be empty files#6839
ytmimi merged 6 commits intorust-lang:mainfrom
notpeter:empty_file

Conversation

@notpeter
Copy link
Copy Markdown
Contributor

@notpeter notpeter commented Mar 23, 2026

No longer add a "final newline" to empty files.
Empty files shouldn't need need trailing newlines.

Since this is a breaking change, I've done my best to feature gate this behind StyleEdition::Edition2027. Please let me know if this should be handled differently.

New tests:

  • append_newline_adds_newlines_before_2027
  • append_newline_leaves_empty_files_empty_in_2027
  • newline_file (existing 2024 behavior; excess newline is preserved)
  • reorder_modules_2027 (2027 behavior test extracted from reorder_modules)

The empty file mod.rs test fixtures for the reorder_modules test were previously being re-used for multiple editions (2015, 2024, 2027), but since 2027 now requires those files be actually empty instead of \n, I moved {enabled,disabled_style_edition_2027.rs} from reorder_modules/ to a new reorder_modules_2027/ and mirrored the mod.rs test fixture structure.

The existing empty_file.rs test (empty file becomes newline) remains untouched. (config not specified; so 2015).

Update1: Fixed reorder_modules
Update2: 2027 tests pass on nightly, fail on stable. Unsure of the proper fix.
Update3: Renamed empty_file_style_edition_2024 to newline_file because it's not actually an empty file.
Update4: Implemented ytmimi's suggestion and fixed tests.

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Mar 23, 2026
Copy link
Copy Markdown
Contributor

@ytmimi ytmimi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please investigate test failures. Also see my suggestion for simplifying the conditional logic.

View changes since this review

Comment thread src/source_file.rs Outdated
@notpeter notpeter requested a review from ytmimi March 24, 2026 04:29
Comment thread tests/source/reorder_modules_2027/_abcd/mod.rs Outdated
@ytmimi ytmimi merged commit 5e73127 into rust-lang:main Mar 27, 2026
26 checks passed
@rustbot rustbot added release-notes Needs an associated changelog entry and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Mar 27, 2026
@ytmimi ytmimi added the A-2027-style-edition Area: style edition 2027 label Mar 27, 2026
@notpeter notpeter deleted the empty_file branch March 27, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-2027-style-edition Area: style edition 2027 release-notes Needs an associated changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustfmt fails on an empty file; --check's diff doesn't result in properly formatted file

3 participants