git-cliff icon indicating copy to clipboard operation
git-cliff copied to clipboard

Use stable rust for cargo-fmt

Open marcoieni opened this issue 1 year ago • 1 comments

Is there an existing issue or pull request for this?

  • [X] I have searched the existing issues and pull requests

Feature description

Not really a feature. working with cargo nightly for cargo fmt is painful :( Please, consider switching to stable to make the experience of contributors a bit better.

Desired solution

  • Remove rust-toolchain.toml file
  • Run cargo fmt

Downside: all opened PRs will have merge conflicts probably because stable uses spaces instead of tabs. So it's better to do this when there aren't big PRs opened.

Alternatives considered

The alternative is keeping the current configuration I guess.

Additional context

feedback coming from https://github.com/orhun/git-cliff/pull/613#issuecomment-2059908791

marcoieni avatar Apr 21 '24 13:04 marcoieni

Downside: all opened PRs will have merge conflicts probably because stable uses spaces instead of tabs.

Merge conflicts for this (and other similar cases where deterministic tooling is used to restyle code) by applying the new formatting rules at the end of the PR/branch before attempting to merge. Optionally this can be later squashed in with the merge commit itself so that the merge diff only shows what the PR brought to the table after all the formatting matched on both sides. If a rebase is preferred this can be done by applying formatting on each commit in the branch in reverse order (branch HEAD first, then working backwards).

alerque avatar Oct 02 '24 19:10 alerque

I'm rather partial to many unstable formatting options, particularly comment width related ones and import ordering / grouping, and would suggest keeping the nightly formatting around.

The unstable options in use in this repo are:

binop_separator = "Back" # https://github.com/rust-lang/rustfmt/issues/3368
format_code_in_doc_comments = true # https://github.com/rust-lang/rustfmt/issues/3348
format_strings = true # https://github.com/rust-lang/rustfmt/issues/3353
imports_layout = "Vertical" # https://github.com/rust-lang/rustfmt/issues/3361
normalize_doc_attributes = true # https://github.com/rust-lang/rustfmt/issues/3351
overflow_delimited_expr = true # https://github.com/rust-lang/rustfmt/issues/4991
struct_field_align_threshold = 20 # https://github.com/rust-lang/rustfmt/issues/3371
wrap_comments = true # https://github.com/rust-lang/rustfmt/issues/3347

I agree that nightly should not be in the toolchain config however.

An alternative to using nightly to format is to pass the unstable options directly to rustfmt. E.g. this would look like:

cargo fmt -- --config unstable_features=true --config binop_separator=Back --config format_code_in_doc_comments=true --config format_strings=true --config imports_layout=Vertical --config normalize_doc_attributes=true --config overflow_delimited_expr=true --config struct_field_align_threshold=20 --config wrap_comments=true

The downside is that this is a small annoyance to maintain

joshka avatar Jun 20 '25 23:06 joshka