Skip to content

file-lines modifies unselected fn signature lines #6864

@randomPoison

Description

@randomPoison

If the opening brace of a function is on a separate line, then when partially formatting the body of the function with --file-lines the opening brace can be moved to the previous line, even if neither of those lines were selected.

Summary

Consider the following file test.rs which defines a function where the opening brace of the function is on its own line:

fn main()
{
println!("weeeeee");
println!("weeeeee");
println!("weeeeee");
}

I would like to use --file-lines '[{"file":"test.rs","range":[5,5]}]' to format just the last line of the function.

Expected Behavior

Only the selected line is formatted:

fn main()
{
println!("weeeeee");
println!("weeeeee");
    println!("weeeeee");
}

Actual Behavior

The selected line, the preceding line, and the first two lines of the function are modified:

fn main() {
println!("weeeeee");
    println!("weeeeee");
    println!("weeeeee");
}

I have a separate issue up for the fact that line 4 is also modified (#6863), this issue is meant to focus on the fact that lines 1-2 are modified even though they are outside the selected range.

Configuration

rustfmt cli options used:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICES-has-mcveStatus: a Minimal Complete and Verifiable Example has been found for this issueUO-file_linesUnstable option: file_lines

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions