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 binding in macro-rules makes unintended indent forever #5775

Closed
e0328eric opened this issue May 29, 2023 · 1 comment
Closed

let-else binding in macro-rules makes unintended indent forever #5775

e0328eric opened this issue May 29, 2023 · 1 comment

Comments

@e0328eric
Copy link

For example, if one runs rustfmt on the following rust code

macro_rules! fmt_wrong {
    ($foo: ident := $bar: expr) => {
        let Some($foo) = $bar else {
            return; // This
        }; // This
    };
}

fn main() {
    println!("Hello, world!");
}

is formatted by indenting This parts. Each time one runs rustfmt, This parts are indented as much as we want.

@ytmimi
Copy link
Contributor

ytmimi commented May 30, 2023

Thanks for reaching out. This is a duplicate of #5213 and other related issues. This hopefully won't be an issue for much longer, and in the meantime you can follow #4914 to be informed when let-else support is available.

To prevent this issue for now your best option is to annotate your macro with the #[rustfmt::skip] attribute.

#[rustfmt::skip]
macro_rules! fmt_wrong {
    ($foo: ident := $bar: expr) => {
        let Some($foo) = $bar else {
            return; // This
        }; // This
    };
}

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale May 30, 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