rust-lang / rust-lang/rustfmt

Newline style changes to Unix-style when file is modified

Open
#4,097 10 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

1x-backport:pending
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

On Windows, using the default newline style (either without rustfmt.toml or by explicitly setting newline_style="Auto":

  • leaves the newlines intact if the file does not have any formatting issues (ok, expected)
  • saves modified files with Unix-style endings, even when all line-breaks in the input file are CRLF.

I would expect that in such cases the "Auto" value would use the line-break style inferred from examining the file.

Version used: rustfmt 1.4.11-stable (9eb4b564 2020-01-29)
as invoked via the cargo fmt command, version cargo 1.42.0 (86334295e 2020-01-31)

It's possible to work around this by forcing "Native" style in the rustfmt.toml but the default behaviour results in a mixture of line-ending styles throughout the project and triggers git line-ending conversion warnings.

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 on Windows through the mentioned cargo fmt entry point, using a CRLF file with a formatting change and the default Auto setting. Trace how Auto chooses newline style and add coverage for preserving the input style; done means modified CRLF files remain CRLF without requiring Native, with the relevant tests passing.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.