rust-lang / rustc_codegen_gcc

libgccjit AOT codegen for rustc
Apache License 2.0
913 stars 60 forks source link

Enable Rustfmt & Clippy for cg_gcc #457

Closed tempdragon closed 6 months ago

tempdragon commented 7 months ago

It takes a long time to manually adjust the code format and style, so I advice to enable the Rustfmt for this project to avoid potential bad styling. As for clippy, it may be a good idea to reduce the poorly behaved code in Rust to improve code quality.

### Tasks
- [x] Modify the `.rustfmt.toml` and Update the Format with it
- [x] Clean Up the Errors as Is Warned by Clippy
antoyo commented 7 months ago

Yes, good idea, I'll accept a PR doing that. Ideally, we should use the same rustfmt config used by the rust project, if any.

tempdragon commented 7 months ago

What about using your rustfmt?(Since you contribute the most code). It seems that you can simply add your rustfmt.toml there? Or maybe I can upload my but it will just be a mare copy of the default one.

antoyo commented 7 months ago

I tried once to get the formatting I wanted with rustfmt, but I was unable to because some settings were missing. Using a different config than rustc will still cause issues to some people because VS Code sometimes ignore the config, so it seems best to use the same config as the Rust project. It seems we'd only need to add a few lines to .rustfmt.toml to use the same config as the Rust project: https://github.com/rust-lang/rust/blob/master/rustfmt.toml#L2-L4

tempdragon commented 7 months ago

I once noticed that in some cases, Rustfmt may behave differently on different machines. A friend of mine used VSCode and our rustfmt seemed to behaved differently, causing our code to be reformatted over and over again. Still not sure about why and how.

antoyo commented 7 months ago

Apparently, one cause is because formatting a selection of code only sends the code to be formatted to rustfmt, not the filename, so it cannot find the config.

tempdragon commented 7 months ago

By the way, have you switched back to vim? Is VSCode rustfmt-related behavior still a problem for you?

antoyo commented 7 months ago

Oh, I never used VS Code. It's some people contributing to cg_gcc via the Rust repo that have this issue.

I've been using neovim (and vim before) for many years.

antoyo commented 7 months ago

I formatted the code in #458.

tempdragon commented 7 months ago

By the way, is adding a full rustfmt specification useful? Customized Conf

tgross35 commented 7 months ago

You probably want to use the same file as upstream https://github.com/rust-lang/rust/blob/6f435eb0eb2926cdb6640b3382b9e3e21ef05f07/rustfmt.toml, the ignore section isn't needed.

Fyi, if these wind up being large changes it's often a good idea to crosscheck. Two people run the same rustfmt commands then git ls-files -s . | git hash-object --stdin to make sure their hashes line up.

Adding the hash of the formatting commit to .git-blame-ignore-revs gets the noise out of blame views (automatic on GH, need to pass --ignore-revs-file via CLI)

antoyo commented 6 months ago

Completed by #469.