-
Notifications
You must be signed in to change notification settings - Fork 902
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
cargo fmt
breaks Sequoia-PGP by introducing syntax errors
#4996
Comments
From Sequoia IRC: apparently rustfmt has trouble with the macros in Sequoia. |
Thanks for reaching out with the report. However, there's a lot of extra noise in the description that makes it hard to zoom in on the formatting issue. Would you please extract a minimal reproduction example and update the issue description? I'd suggest starting with |
Hey there! I've investigated the problem here. In short: there are two things that cause breakage: 1. rustfmt removes angle brackets from a macrocreate_conversions!(Key<>); becomes create_conversions!(Key); macro definition: macro_rules! create_conversions {
( $Key:ident<$( $l:lifetime ),*> ) => {
...
}
} See here for the full macro 2. rustfmt gets confused about feature flags and code blocksimpl Default for CompressionAlgorithm {
fn default() -> Self {
use self::CompressionAlgorithm::*;
#[cfg(feature = "compression-deflate")]
{ Zip }
#[cfg(all(feature = "compression-bzip2",
not(feature = "compression-deflate")))]
{ BZip2 }
#[cfg(all(not(feature = "compression-bzip2"),
not(feature = "compression-deflate")))]
{ Uncompressed }
}
} becomes
See full file here. |
Thanks again @larswirzenius for the report, and very much appreciated @Erik1000 for the succinct summary! Your first section ultimately ties back to general macro handling limitations (e.g. #8). To be fully transparent, this is unlikely to change any time soon, so the recommended workarounds for now are:
Your second item looks like an old bug, and not one I can reproduce with rustfmt on nightly, stable, nor from source. Are you sure you're not actually using an older version of rustfmt, and if so, could you share your configuration file? |
I actually can confirm that the second item is fixed on current stable. Sequoia is locked at 1.48.0 and the bug is present there. |
Thanks for confirming. I'm going to go ahead and close this then given the only unresolved issue stems from the standard minimal macro support. |
When I try to use
cargo fmt
on the Sequoia-PGP source tree, so thatcargo check
fails.The source code: https://gitlab.com/sequoia-pgp/sequoia
Commit: 22071cfb1324ef87e2ad2ee8c38c3b5e1a1375d4
Sequoia normally builds with 1.48.0, and
cargo check -q
reports nothinig. If I use the current version of the toolchain there is a warning due to the code base not being entirely clean, butcargo check -q
works otherwise. Aftercargo fmt
however there are syntax errors.Version of rustfmt that breaks the code:
rustfmt 1.4.37-stable (c8dfcfe 2021-09-06)
Commands and output
Commands:(maintainer note: output moved to a collapsible section for better issue readability)
The text was updated successfully, but these errors were encountered: