rust-lang / rust-lang/rustfmt

`reorder_imports=false` conflicts with `imports_indent="Visual"`

Open
#4,794 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

I-poor-formatting only-with-option
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

When using both imports_indent="Visual" and reorder_imports=false the alignments of all subsequent lines within the block are off by 4 spaces.

To Reproduce
source:

// rustfmt-imports_indent: Visual
// rustfmt-reorder_imports: false

use module::{
  submodule_A::{Type_A1, Type_A2},
  submodule_B::{Type_B1, Type_B2},
};

target:

// rustfmt-imports_indent: Visual
// rustfmt-reorder_imports: false

use module::{submodule_A::{Type_A1, Type_A2},
         submodule_B::{Type_B1, Type_B2}};

Expected behavior

// rustfmt-imports_indent: Visual
// rustfmt-reorder_imports: false

use module::{submodule_A::{Type_A1, Type_A2},
             submodule_B::{Type_B1, Type_B2}};

Note that:

  1. The correct thing happens when either imports_indent="Visual" or reorder_imports=false is set, but not when they are both set simultaneously.
  2. No reordering of modules needs to actually happen (or be prevented from happening) for this to occur.

Meta

  • rustfmt version: 94035f9148d31d3f714d9c649cf2de0f0edb4f46 (HEAD -> master)

refs #3360

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 running the supplied rustfmt reproduction with imports_indent="Visual" and reorder_imports=false, comparing the generated alignment with the expected output. Trace the formatting path for nested imports and verify that subsequent lines use the expected indentation when both options are enabled; done means the example formats exactly as shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.