Skip to content

Rustfmt adds new indentation every time it formats let else in macro declaration #5503

Not planned
@PoignardAzur

Description

@PoignardAzur

Example code:

// The indentation stays the same, as expected
fn foobar() {
    let x = y else {
        panic!();
    };
}

// The indentation is increased every time you run `cargo fmt`
macro_rules! foobar {
    () => {
        let pat = expr else {
                    panic!();
                };
    };
}

Activity

added
bugPanic, non-idempotency, invalid code, etc.
on Aug 15, 2022
ytmimi

ytmimi commented on Aug 15, 2022

@ytmimi
Contributor

Thanks for reaching out. I think the underlying issue is that rustfmt doesn't currently format let else expressions because the rules for formatting them have not yet been finalized via an RFC in fmt-rfcs repo.

Related issues are #5489, #5044, and #4609 which also deal with cases where extra indentation is added in macro definitions when rustfmt fails to format the macro body.

est31

est31 commented on Sep 23, 2022

@est31
Member

This is a precise dupe of #5213 , which got closed as dupe of the issues linked above.

est31

est31 commented on Sep 23, 2022

@est31
Member

It's quite interesting that this is the second time that this specific let else case was hit. Maybe many people wrote macros in that fashion and now want to replace them with let else?

PoignardAzur

PoignardAzur commented on Sep 23, 2022

@PoignardAzur
Author

I don't know about the other bug, but I was writing assert_let.

ytmimi

ytmimi commented on Sep 26, 2022

@ytmimi
Contributor

Going to close this as a duplicate of #5213

As mentioned above, the underlying issue here is that rustfmt doesn't currently format let else. Rules need to be added to the Rust Style Guide before an implementation can be added to rustfmt. If you want to stay informed about the style discussion you can subscribe to rust-lang/style-team#165, and to keep up with implementation progress you can subscribe to #4914.

If the macro indentation behavior continues after let else formatting is implemented, then we can reopen this issue and investigate further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-macrosbugPanic, non-idempotency, invalid code, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @PoignardAzur@est31@ytmimi

        Issue actions

          Rustfmt adds new indentation every time it formats `let else` in macro declaration · Issue #5503 · rust-lang/rustfmt