rustfmt can't handle non-UTF-8 input paths
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
Research direction
The report points to src/bin/main.rs around line 235. Start by tracing how rustfmt reads input paths there and compare that with the reproduction script using a non-UTF-8 filename. Done means rustfmt handles this input without panicking; use the supplied Python script to reproduce the failure and check the result.
Written by the indexing model from the issue text.
Description
Summary
The rustfmt command panics when it encounters an input path which is not valid UTF-8. See https://github.com/rust-lang/rust/issues/164585 for the same issue in rustc.
To reproduce the issue, I ran the following python script, which runs rustfmt with a non-UTF-8 input file name:
import shutil
import subprocess
p = subprocess.run([shutil.which("rustfmt"), bytes([255])], check=False)
print(p)
The output I got was:
thread 'main' (204054) panicked at /rustc/58cf8f9c35b355199727627d07ae34a4e2846d67/library/std/src/env.rs:878:51:
called `Result::unwrap()` on an `Err` value: "\xFF"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
CompletedProcess(args=['/opt/homebrew/opt/rustup/bin/rustfmt', b'\xff'], returncode=101)
Probably relevant code: https://github.com/rust-lang/rustfmt/blob/97738dfd687ab9d35338fbceb5def4506c7c4d3b/src/bin/main.rs#L235
Meta
rustfmt --version:
rustfmt 1.10.0-stable (58cf8f9c35 2026-10-13)
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 27
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-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
-
`cfg_select!` formatting can eat commentsPossibly taken @jieyouxu claimed this 1 day ago. OpenA-cfg_select A-comments C-bug I-prioritize regression-from-nightly-to-nightly X-impacts-nightly-gated
rust-lang/rustfmt#7209 · 8 comments · 1 reaction · 1 assignee ·
Maintainers usually reply within 1 day
All issues in rust-lang/rustfmt
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
ilya-zlobintsev/LACT#1235 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
FalkorDB/FalkorDB#3482 · 1 comment ·
Maintainers usually reply within 8 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
checkpoint/verify/rebuild_indexes on a thread holding a WriteTransaction deadlock instead of INT-001Openbug known-issue
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
project-minigraf/minigraf#734 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100