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 gets upset when trying to format a let-else block inside a macro. #5760

Closed
vincenzopalazzo opened this issue May 1, 2023 · 1 comment

Comments

@vincenzopalazzo
Copy link
Member

This what rustfmt produces when I run the code formatting

#[macro_export]
macro_rules! from_cstr {
    ($x:expr) => {{
        use std::ffi::CStr;
        let c_str = unsafe { CStr::from_ptr($x) };
        let Ok(c_str) = c_str.to_str() else {
                                                                                    return null!()
                                                                                };
        c_str
    }};
}
@ytmimi
Copy link
Contributor

ytmimi commented May 1, 2023

Thanks for reaching out. This is a duplicate of #5503.

The reason for the infinite indentation is that we haven't landed support for let-else in rustfmt yet. You can subscribe to #5690 for updates on when that work is done.

In the meantime you might want to use #[rustfmt::skip] to prevent rustfmt from messing with the formatting.

#[rusfmt::skip]
#[macro_export]
macro_rules! from_cstr {
    ($x:expr) => {{
        use std::ffi::CStr;
        let c_str = unsafe { CStr::from_ptr($x) };
        let Ok(c_str) = c_str.to_str() else {
            return null!();
        };
        c_str
    }};
}

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

No branches or pull requests

2 participants