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

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

Closed
PoignardAzur opened this issue Aug 15, 2022 · 5 comments
Labels
a-macros bug Panic, non-idempotency, invalid code, etc.

Comments

@PoignardAzur
Copy link

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!();
                };
    };
}
@ytmimi ytmimi added bug Panic, non-idempotency, invalid code, etc. a-macros labels Aug 15, 2022
@ytmimi
Copy link
Contributor

ytmimi commented Aug 15, 2022

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
Copy link
Member

est31 commented Sep 23, 2022

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

@est31
Copy link
Member

est31 commented Sep 23, 2022

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
Copy link
Author

PoignardAzur commented Sep 23, 2022

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

@ytmimi
Copy link
Contributor

ytmimi commented Sep 26, 2022

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
Labels
a-macros bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

No branches or pull requests

3 participants