rust-lang / rust-lang/rustfmt

`reorder_impl_items` adds empty line between single-line macros

Open
#5,323 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

We have some macros that we use inside impl statements that look like this:

impl Value {
    impl_value!(as_i64, from_i64, data_i64, as_data_i64, i64, Int64);
    impl_value!(as_f32, from_f32, data_f32, as_data_f32, f32, Float32);
    impl_value!(as_vec2, from_vec2, data_vec2, as_data_vec2, [f32; 2], Vec2);
    impl_value!(as_vec3, from_vec3, data_vec3, as_data_vec3, [f32; 3], Vec3);
    impl_value!(as_vec4, from_vec4, data_vec4, as_data_vec4, [f32; 4], Vec4);
    impl_value!(as_quat, from_quat, data_quat, as_data_quat, [f32; 4], Quat);

that when formatting with reorder_impl_items=true gets rearranged to have a new empty line between them:

impl Value {
    impl_value!(as_i64, from_i64, data_i64, as_data_i64, i64, Int64);

    impl_value!(as_f32, from_f32, data_f32, as_data_f32, f32, Float32);

    impl_value!(as_vec2, from_vec2, data_vec2, as_data_vec2, [f32; 2], Vec2);

    impl_value!(as_vec3, from_vec3, data_vec3, as_data_vec3, [f32; 3], Vec3);

    impl_value!(as_vec4, from_vec4, data_vec4, as_data_vec4, [f32; 4], Vec4);

    impl_value!(as_quat, from_quat, data_quat, as_data_quat, [f32; 4], Quat);

Which is a bit more verbose. Should/could this option skip macros inside impl statements or maybe specifically skip single-line macros? That would be nice!

Not sure how how common this pattern is but we do use it for some types. We could potentially move the macro out of the impl statement, could be a bit more standard but do quite like that this location is clear that it just adds implementation.

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 reproducing the reported Rust example with reorder_impl_items=true, focusing on how single-line macros inside impl statements are reordered. The change is done when formatting no longer inserts empty lines between these macros, while the existing reordering behavior remains intact.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.