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

Force rustfmt to use 2018 Rust edition in pre-commit hook #218

Conversation

dominic-mulligan-arm
Copy link
Member

@dominic-mulligan-arm dominic-mulligan-arm commented Sep 16, 2021

There is a bug in rustfmt currently that ignores the edition set in Cargo.toml files and defaults to 2015 edition. This means it errors on any staged file containing the async keyword, and any other change introduced in rust 2018.
The solution is to force the Rust edition to use when calling rustfmt.

@dominic-mulligan-arm dominic-mulligan-arm added bug Something isn't working repository Something related to management of the repository build-process Something related to the Veracruz build process labels Sep 16, 2021
@egrimley-arm
Copy link
Contributor

Could you add a comment (in githooks/pre-commit) with a link to the upstream bug?

I tried looking for it myself, but all I could find was rust-lang/rustfmt#4645, which was closed with someone saying the reporter was using the wrong version of rustfmt.

Could you also point to a file in the repo (I mean in the discussion here rather than in the code) that needs the --edition=2018 so I can check whether my rustfmt is affected by the bug?

@egrimley-arm
Copy link
Contributor

To answer my own question, an example of something that needs --edition=2018 is: async fn foo() {}

It seems that rustfmt is supposed to ignore the Cargo.toml, while cargo fmt is incapable of looking at a single source file, so invoking rustfmt with --edition=2018 seems to be the right thing to do in our case.

ShaleXIONG
ShaleXIONG previously approved these changes Sep 21, 2021
gbryant-arm
gbryant-arm previously approved these changes Sep 22, 2021
@dominic-mulligan-arm
Copy link
Member Author

+1+1=+1 reached, merging.

@dominic-mulligan-arm
Copy link
Member Author

Oops, seems there was some issue with the signing of commits. I've resigned and pushed again. @ShaleXIONG, @gbryant-arm can you take another look and approve, ready for merging?

@gbryant-arm gbryant-arm self-requested a review September 27, 2021 11:34
@dominic-mulligan-arm
Copy link
Member Author

+1 reached, merging.

@dominic-mulligan-arm dominic-mulligan-arm merged commit 59ddcdc into veracruz-project:main Sep 27, 2021
@dominic-mulligan-arm dominic-mulligan-arm deleted the fix-rustfmt-githook branch September 27, 2021 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working build-process Something related to the Veracruz build process repository Something related to management of the repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants