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

Body of macro gets re-indented every time rustfmt is run #2754

Closed
sgrif opened this issue May 30, 2018 · 1 comment
Closed

Body of macro gets re-indented every time rustfmt is run #2754

sgrif opened this issue May 30, 2018 · 1 comment
Labels
a-macros bug Panic, non-idempotency, invalid code, etc. poor-formatting

Comments

@sgrif
Copy link

sgrif commented May 30, 2018

Body of file:

// Vendored from the static-cond crate as macro re-exports are not available in stable Rust.
// https://github.com/durka/static-cond/blob/36aa2dd/src/lib.rs
//
// Code is dual licensed under MIT/Apache-2.0
// Copyright (c) 2016 Alex Burka
#[macro_export]
#[doc(hidden)]
macro_rules! static_cond {
    // private rule to define and call the local macro
    (@go $lhs:tt $rhs:tt $arm1:tt $arm2:tt) => {        // note that the inner macro has no captures (it can't, because there's no way to escape `$`)
        macro_rules! __static_cond {
            ($lhs $lhs) => $arm1;
            ($lhs $rhs) => $arm2
        }

        __static_cond!($lhs $rhs);
    };

    // no else condition provided: fall through with empty else
    (if $lhs:tt == $rhs:tt $then:tt) => {
        static_cond!(if $lhs == $rhs $then else { });
    };
    (if $lhs:tt != $rhs:tt $then:tt) => {
        static_cond!(if $lhs != $rhs $then else { });
    };

    // we evaluate a conditional by generating a new macro (in an inner scope, so name shadowing is
    // not a big concern) and calling it
    (if $lhs:tt == $rhs:tt $then:tt else $els:tt) => {
        static_cond!(@go $lhs $rhs $then $els);
    };
    (if $lhs:tt != $rhs:tt $then:tt else $els:tt) => {
        static_cond!(@go $lhs $rhs $els $then);
    };
}
@topecongiro topecongiro added bug Panic, non-idempotency, invalid code, etc. poor-formatting a-macros labels May 31, 2018
@topecongiro
Copy link
Contributor

Closed via #2775.

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. poor-formatting
Projects
None yet
Development

No branches or pull requests

2 participants