-
Notifications
You must be signed in to change notification settings - Fork 888
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
outer macro skip attribute on out-of-line module ignored; can't use inner attribute #5324
Comments
Thanks for reaching out. You've ventured into a lot of topics, most of which are not particularly actionable (for us anyway), but I've tried to respond to them all anyway.
Have you considered simply using brace delimiters? by design, rustfmt is nearly entirely hands-off by default on calls that use those, and it seems like the path of least resistance for you (e.g.
I would be fine with augmenting that text to highlight the fact that they're unstable, but I'm adamantly opposed to removing the text altogether just because it can't be used on stable (especially since it was a relatively recent change upstream that caused the tool attributes to no longer work on stable). We've myriad existing features/documentation/etc. that's a nightly/unstable context only, and this is no different.
This is the only item I may want to circle back to on our end. Even for out-of-line mods the outer attributes are available for rustfmt in the context of formatting the associated file. It could be intentional behavior, however, as outer attributes on imports can drive inconsistent behavior, such as formatting the file directly (e.g. editor format on save), or if the module is imported from multiple places with divergent sets of outer attributes. Additionally/alternatively, there have been discussions elsewhere about alternative mechanisms, such as a new config option that allows users to enumerate maccalls to be skipped globally, which I'm certainly still open to as well. |
#[rustfmt::skip::macros(items)]
as an outer attribute not respected; can't use inner attribute#[rustfmt::skip::macros(items)]
on module item ignored; can't use inner attribute
Thanks for the response and thanks for parsing my confusing story! Using braces works for me. I've changed the title to hopefully make it more searchable and more focused on the actionable part of the issue. |
#[rustfmt::skip::macros(items)]
on module item ignored; can't use inner attribute
Thanks, glad the brace delims are working for you! I made a minor adjustment to the title as well to add more clarity. @tommilligan - noticed you've sent a few PRs of late, and while I'm not sure if you have the bandwidth or interest in working on anything else, was curious if this is something you'd be willing to try to tackle? 👇
|
I'd be open to writing up an initial implementation of something, it might take a little while though. To clarify the requirements:
This seems like the most reasonable first pass? |
Hey @tommilligan, I think your outline of the requirements for a new configuration option are spot on. I also agree that we probably shouldn't need to worry about macro's that have been aliased. At the very least not for a first pass at this. Here is some of what I've found and thoughts for an implementation to hopefully help you out. When calling Lines 151 to 163 in 5ff7b63
(SkipContext API linked for reference) Lines 6 to 33 in a37d3ab
The main API for adding new items to the skip context is
You'll likely need to add a new method to update the skip context from the config. I think we could update Lines 181 to 195 in a37d3ab
|
Fantastic and certainly no rush. Agreed that the outline looks good, and @ytmimi has also provided some good code hints. |
Opened an initial implementation of |
@calebcartwright, I'm wondering if we should close this now that #5347 has been merged or if we should try to come up with a solution that can be used on stable? |
The new option ( Agreed that we can close this though, folks can subscribe #5346 to track stabilization progress |
I have a macro the invocation of which I want rustfmt to skip. Since the macro expands to top level items, I tried to use
#![rustfmt::skip::macros(items)]
at the module level to do this. That unfortunately breaks compilation because custom inner attributes are unstable. The next thing I tried is to put the attribute on top of themod my_mod;
item, that doesn't work either, maybe because the macro is private to the module. Putting a plain#[rustfmt::skip]
on top of the module item does work, but it skips the entire file when I only want to skip a specific invocation.To illustrate, here is a patch against an empty Git repo you could apply with
git am
.cargo fmt
does not skip the invocation:Maybe the example in the tips section of the README should be updated to stop suggesting to use custom inner attributes, but I don't know what would be a better alternative.
I tried on
rustfmt 1.4.38-stable (7737e0b5 2022-04-04)
andrustfmt 1.4.38-nightly (18f314e7 2022-04-24)
.The text was updated successfully, but these errors were encountered: