Skip to content

Bad formatting of let-else in macro #5213

Closed as not planned
Closed as not planned
@est31

Description

@est31

The following macro makes rustfmt as of nightly do bad formatting:

macro_rules! unwrap_some {
    ($name:ident) => {
        let Some($name) = $name else {
            panic!();
        };
    };
}

If you run it once, it moves the panic and the }; one indentation level to the right:

macro_rules! unwrap_some {
    ($id:ident) => {
        let Some($id) = $id else {
                    panic!();
                };
    };
}

This process is continued, until you reach this fixpoint:

macro_rules! unwrap_some {
    ($id:ident) => {
        let Some($id) = $id else {
                                                                                    panic!();
                                                                                };
    };
}

I file this bug not because the output is bad style (it is, but that is the purpose of #4914 to figure out), but because the rustfmt output from running it once is not a fixpoint.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions