Skip to content

rustfmt_skip should have the same effect on warnings when inside and outside a module #1399

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

Closed
8573 opened this issue Mar 22, 2017 · 5 comments

Comments

@8573
Copy link

8573 commented Mar 22, 2017

I'm using LALRPOP, which generates a Rust file from a build script,
which file I then reference with a mod <filename> item.

The generated file is large and, relative to the style used by
rustfmt, densely formatted, and has many long lines, at which rustfmt
always emits error messages about being unable to shorten them.
rustfmt does, however, manage to format much of the file — expanding
it from 3010 lines to 8265.

How, if at all, could I instruct rustfmt to ignore this file?

@nrc
Copy link
Member

nrc commented Mar 22, 2017

You can add a rustfmt_skip annotation to the mod declaration and then the file will be skipped. See the README for more info on the annotation.

@nrc nrc closed this as completed Mar 22, 2017
@8573
Copy link
Author

8573 commented Mar 22, 2017

Ah! I had put the attribute inside the file (as #![cfg_attr(rustfmt, rustfmt_skip)]), noted that this resulted in more overlong-line messages, saw that that's intentional (#1298), and didn't think that the behavior would be different were I to put the attribute on the mod item; thanks, and my apologies for not trying that earlier.

@solson
Copy link
Member

solson commented Mar 24, 2017

@nrc If #[rustfmt_skip] mod foo; works, then #![rustfmt_skip] at the top-level inside foo.rs should have the same behavior, IMO. It'd be better if a module can be self-contained in that way.

@nikomatsakis
Copy link

I agree with @solson on this point -- also, to me, it's just plain surprising for #![foo] in mod.rs and #[foo] mod to have distinct effects.

@nrc nrc reopened this May 30, 2017
@nrc nrc changed the title Can one exempt generated files from formatting? rustfmt_skip should have the same effect inside and outside a module May 30, 2017
@nrc nrc added this to the 1.0 milestone Nov 2, 2017
@nrc nrc changed the title rustfmt_skip should have the same effect inside and outside a module rustfmt_skip should have the same effect on warnings when inside and outside a module Nov 2, 2017
@topecongiro
Copy link
Contributor

Confirmed that this is supported in 0.3.1-nightly.

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

5 participants