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-formattable syntax? #35

Open
coolreader18 opened this issue Jul 9, 2020 · 2 comments
Open

rustfmt-formattable syntax? #35

coolreader18 opened this issue Jul 9, 2020 · 2 comments

Comments

@coolreader18
Copy link

I'm aware how minimal and stable this crate is and has been for a long time, but something that's always put me off from using it (usually in favor of manual #[cfg] attributes) is how its syntax is completely unfamiliar to rustfmt, and therefore any expressions or items inside of a cfg_if! block can't get the advantages that rustfmt brings.

// stays as is when `cargo fmt` is run
cfg_if! {
    if #[cfg(foobar)] {
        fn baz() { qux();   flop()
        }
    }
    else {
        fn bar() {
        }
    }
}

Was there a reason that you didn't choose a more traditional/valid rust syntax for the macro? e.g.

cfg_if!(if cfg!(foobar) {
    fn baz() {
        qux();
        flop()
    }
} else {
    fn bar() {}
});

I'm aware that rustfmt wasn't as popular/well-integrated in 2017, but I feel like a syntax like this would greatly improve the ergonomics of this crate.

(feel free to ignore, I was just surprised that there wasn't an issue about this already)

@alexcrichton
Copy link
Member

I chose to use #[cfg] instead of cfg! because cfg! already exists but behaves differently than this crate. It's true that when this was created rustfmt didn't exist, but I would indeed be interested if there's a way to get rustfmt to look at code inside the macro and format it. I don't know what heuristics rustfmt has, however.

@calebcartwright
Copy link
Member

We don't really have the ability to format anything that's contained with any macro call using brace delimiters, so a change to cfg! isn't going to do anything for rustfmt.

cfg_if is actually already one of the special case scenarios where we do peek inside to look for any out-of-line mods that are imported and we do format the associated files for those mods, but don't touch the inline args to the mac call.

Our ability to format the out-of-line mods is heavily predicated on the current syntax, so the only immediate impact of from #[cfg] to cfg! would actually be to break the current ability to format those mods.

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

3 participants