rustfmt-formattable syntax? #35
Labels
No labels
bug
dependencies
duplicate
enhancement
github_actions
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-rust-lang/cfg-if#35
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 acfg_if!block can't get the advantages that rustfmt brings.Was there a reason that you didn't choose a more traditional/valid rust syntax for the macro? e.g.
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)
I chose to use
#[cfg]instead ofcfg!becausecfg!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.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_ifis 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]tocfg!would actually be to break the current ability to format those mods.I just realized that this is possible while also solving #43. I implemented the macros in the
cfg-elifcrate. For items, you always need to use parenthesis for macro calls likeitem::cfg!().Will you accept a PR for this when I make one? Or, do you think this is to hacky for a repository under
rust-lang?It's likely development efforts are going to be focused on getting
match_cfgready for stabilization, which will entirely replace the need for this crate.I didn't know that the work is going on. Thank you for the info!