`newline_style=Auto` doesn't report any issue on mixed line endings
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start by reading the issue’s referenced newline handling in src/source_file.rs and src/formatting.rs, then trace how rustfmt --check detects newline style. Reproduce with the mixed-ending sample and compare behavior when newline_style is unset, Unix, and Windows; done means mixed endings are reported in auto mode and empty-file formatting is idempotent.
Written by the indexing model from the issue text.
Description
Summary
I don't trust GitHub to respect line-endings if I paste code, so:
$ printf 'fn main() {\r\n blah() // no CR!\n}\r\n' > file.rs
$ rustfmt --check ./files.rs
I can't imagine this is very impactful, I would expect almost all text editors to force the same line endings within a file (so someone would likely need to go out of their way to hit this)
Expected behavior
rustfmt reports the inconsistency like: Incorrect newline style in file.rs
Actual behavior
rustfmt reports nothing
Configuration
Ensure newline_style is unset or Auto
Reproduction Steps
See above. Note that with newline_style set this reports correctly:
$ rustfmt --check --config newline_style=Unix ./samples/lines.rs
Incorrect newline style in lines.rs
$ rustfmt --check --config newline_style=Windows ./samples/lines.rs
Incorrect newline style in lines.rs
Meta
$ rustfmt --version
rustfmt 1.11.0-nightly (3e92e1a2d2 2026-11-01)
Notes
I found this while working on https://github.com/rust-lang/rustfmt/pull/7233. The issue is when we don't set newline_style we get the original file content from the source map here which only contains Unix line endings (so strips the CR). When we determine the newline style to apply we check the output from the snippet provider, which I don't think will ever contain carriage returns (but I haven't dug deep enough to confirm).
This also results in non-idempotent formatting of empty files in Windows:
- Format
"":apply_newline_stylefinds no newlines, defaults toNative, so we write out\r\n - Second turn: format
\r\n: per aboveapply_newline_stylereads from snippet, which strips out\rso it only sees\nand determinesUnixline endings, so we write out\n
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 29
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rust-lang/rustfmt
-
A-Unicode C-bug P-low
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
rust-lang/rustfmt#7210 · 5 comments ·
Maintainers usually reply within 1 day
-
A-imports C-bug E-hard I-non-idempotency X-impacts-stable-default-format
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
rust-lang/rustfmt#7173 · 1 comment ·
Maintainers usually reply within 1 day
-
A-comments C-bug only-with-option UO-indent_style
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Fix `first_line_width` to be tab-awareMay be free again A pull request for this issue was closed without being merged. OpenA-tabs A-whitespace C-bug SO-hard_tabs
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
C-feature-request P-low
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
rust-lang/rustfmt#7114 · 2 reactions ·
Maintainers usually reply within 1 day
All issues in rust-lang/rustfmt
Similar issues
-
good first issue help wanted program
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
hffgzktbcc-blip/ounce-core#297 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nautechsystems/nautilus_trader#5631 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
bytecodealliance/rustix#1736 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
longbridge/gpui-kit#3871 ·
Maintainers usually reply within 1 day
-
area:models enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day