Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let ... = ... else {} badly and infinitely indented with repeated formatting #5866

Closed
madonuko opened this issue Jul 29, 2023 · 1 comment
Closed

Comments

@madonuko
Copy link

madonuko commented Jul 29, 2023

This issue is similar to #4609.

To reproduce:

macro_rules! a {
    () => {
        let x = y else {
            any
        };
    };
}

fn b() {
    let Some(x) = Some("hai") else {panic!("oops");};
}

d!(
    macro x() {
        let x = y else {
            any
        };
    }
);

Run $ rustfmt test.rs

And now you get this:

macro_rules! a {
    () => {
        let x = y else {
                    any
                };
    };
}

fn b() {
    let Some(x) = Some("hai") else {panic!("oops");};
}

d!(
    macro x() {
        let x = y else {
                    any
                };
    }
);

Notice the bad indentation in macro_rules! a and d!(...) and the unchanged bad indentation in b().

for d!(), this only happens with:

  • macro invocation with !()
  • the macro keyword (weird!)
  • and it should look like a function except you replace fn with macro
  • and of course the let ... = ... else {}; statement; yes you need ;

And for the case in b() it just happens anywhere; seems like there is no support for formatting let ... = ... else {}; statements in rustfmt?

Some of the affected versions

  • rustfmt 1.5.1-stable (d5a82bb 2023-02-07)
  • rustfmt 1.5.2-stable (8ede3aa 2023-07-12)
@calebcartwright
Copy link
Member

Thanks but I'm going to close because this is a duplicate of #5503 and you need to have rustfmt v1.6.0 or higher to have a version that has formatting support for let-else statements. That version of rustfmt should be on stable in Rust 1.72, and has been out on the nightly toolchains for a while.

Some docs/links below for reference:
https://github.com/rust-lang/rustfmt/blob/master/CHANGELOG.md#160-2023-07-02
#4914
https://blog.rust-lang.org/2023/07/01/rustfmt-supports-let-else-statements.html

@calebcartwright calebcartwright closed this as not planned Won't fix, can't repro, duplicate, stale Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants