rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Remove extra unnecessary blocks

Open jjant opened this issue 3 years ago • 5 comments

Description

It should be safe to remove unnecessarily nested blocks when there's no statements in between: {{{ <stmts> }}} => { <stmts> }.

Example

Input:

fn f() {
    {{{{{ g() }}}}};
}

Expected output:

fn f() {
  g();
}

Actual output:

fn f() {
    {
        {
            {
                {
                    {
                        g()
                    }
                }
            }
        }
    };
}

jjant avatar Nov 28 '22 14:11 jjant

Hi, I would like to contribute to this issue, please assign me and point to where I should look for these.

0xSaksham avatar Feb 06 '23 13:02 0xSaksham

@0xSaksham Thanks for your interest in working on this. You can assign yourself by commenting @rustbot claim. I'd encourage you to read the Issue claiming section of the rustc dev guide.

I imagine this option would work just like remove_nested_parens, and you can check out how remove_nested_parens is implemented by looking at rewrite_paren.

Maybe it makes sense to implement this logic in walk_block_stmts, but to be honest I haven't looked into this so you'll need to do some investigating on your own.

ytmimi avatar Feb 07 '23 16:02 ytmimi

@rustbot claim

vatsalkeshav avatar Jan 29 '25 16:01 vatsalkeshav

@vats004 Are you working on this? If you are no longer able to work on this issue, I'll try to tackle it.

Edit: It's been a month since you've claimed this, and I implemented it myself.

karolzwolak avatar Feb 25 '25 14:02 karolzwolak

@rustbot release-assignment

vatsalkeshav avatar Jun 07 '25 11:06 vatsalkeshav