rust-lang / rust-lang/rustfmt

file-lines can't partially format function signatures

Open
#6,868 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug UO-file_lines
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

With the --file-lines option I'd expect to be able to partially format a function's signature, e.g. only format one argument while leaving the rest of the signature as-is. But any attempt to format the function signature formats the whole thing.

Summary

For the following code in test.rs:

fn long_fn_decl(
arg: i32,
arg2: i32,
arg3: i32,
)
    {
println!("a");
    }

I would like to use --file-lines '[{"file":"test.rs","range":[2,4]}]' to format just the arguments to the function, without modifying any other lines.

Expected behavior
fn long_fn_decl(
    arg: i32,
    arg2: i32,
    arg3: i32,
)
    {
println!("a");
    }
Actual behavior
fn long_fn_decl(arg: i32, arg2: i32, arg3: i32) {
println!("a");
    }

Configuration

rustfmt cli options used:

rustfmt --unstable-features --file-lines '[{"file":"test.rs","range":[2,4]}]' test.rs

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

Reproduce the command in the issue using the provided test.rs input and --file-lines range. Trace the rustfmt handling for partial ranges and add regression coverage for formatting only the selected function arguments; done means the expected indentation changes while the rest of the signature and body remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.