rust-lang / rust-lang/rustfmt

rustfmt's `--config-path` help text is misleading

Open
#5,206 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-config P-low
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

As of 8b0b213cddb23a9bbe421b717d1a0e5fb3982712, the help text is:

$ rustfmt -h
...
        --config-path [Path for the configuration file]
                        Recursively searches the given path for the
                        rustfmt.toml config file. If not found reverts to the
                        input file path

Some points of confusion:

  1. How can there be a recursive search if the configure is a "file": [Path for the configuration file]?
    a. It seems like this option can take a directory with rustfmt.toml OR the file itself.
  2. When passed a directory, rustfmt does not appear to search recursively for a config file through ancestors or decedent directories:
    $ mkdir -p /tmp/dir1/dir2/dir3
    $ find /tmp/dir1/
    /tmp/dir1/
    /tmp/dir1/dir2
    /tmp/dir1/dir2/dir3
    $ strace target/debug/rustfmt --config-path=/tmp/dir1/dir2/ /dev/null |& rg dir1 -C1
    execve("target/debug/rustfmt", ["target/debug/rustfmt", "--config-path=/tmp/dir1/dir2/", "/dev/null"], 0x7ffc4c2ad340 /* 61 vars */) = 0
    brk(NULL)                               = 0x5607c5058000
    --
    statx(0, NULL, AT_STATX_SYNC_AS_STAT, STATX_ALL, NULL) = -1 EFAULT (Bad address)
    statx(AT_FDCWD, "/tmp/dir1/dir2/", AT_STATX_SYNC_AS_STAT, STATX_ALL, {stx_mask=STATX_ALL|0x1000, stx_attributes=0, stx_mode=S_IFDIR|0775, stx_size=4096, ...}) = 0
    statx(AT_FDCWD, "/tmp/dir1/dir2/", AT_STATX_SYNC_AS_STAT, STATX_ALL, {stx_mask=STATX_ALL|0x1000, stx_attributes=0, stx_mode=S_IFDIR|0775, stx_size=4096, ...}) = 0
    statx(AT_FDCWD, "/tmp/dir1/dir2/.rustfmt.toml", AT_STATX_SYNC_AS_STAT, STATX_ALL, 0x7ffc9118d8b0) = -1 ENOENT (No such file or directory)
    statx(AT_FDCWD, "/tmp/dir1/dir2/rustfmt.toml", AT_STATX_SYNC_AS_STAT, STATX_ALL, 0x7ffc9118d8b0) = -1 ENOENT (No such file or directory)
    write(2, "Error: unable to find a config f"..., 73Error: unable to find a config file for the given path: `/tmp/dir1/dir2/`) = 73
    write(2, "\n", 1
    
  3. The last sentence says that if the file is not found, then "reverts to the input file path", but it seems like rustfmt will emit an error when the file does not exist
    rustfmt --config-path=/does/not/exist /dev/null
    Error: unable to find a config file for the given path: `/does/not/exist`
    

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 locating the rustfmt CLI definition and the help text for --config-path, then reproduce the documented directory, file, and nonexistent-path commands from the issue. Done means the help text accurately describes accepted paths, search behavior, and the error case, with checks covering the reported examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.