rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
6.05k stars 888 forks source link

rustfmt 1.8.0-nightly (6c6d210089 2024-09-22) change many codes #6346

Closed Sherlock-Holo closed 2 months ago

Sherlock-Holo commented 2 months ago

with previous version, for example:

cargo +nightly-2024-09-15 fmt

it only changes one file

--- a/core/src/cli/linux/mod.rs
+++ b/core/src/cli/linux/mod.rs
@@ -6,16 +6,16 @@ use std::future::ready;
 use std::io;
 use std::path::PathBuf;
 use std::str::FromStr;
-use std::sync::Arc;
 use std::sync::atomic::AtomicUsize;
+use std::sync::Arc;
 use std::time::Duration;

 use boringtun::x25519::{PublicKey, StaticSecret};
 use cidr::{IpCidr, Ipv4Cidr, Ipv6Cidr};
 use clap::Parser;
 use flume::Receiver;
-use futures_util::{TryStreamExt, stream};
-use rand::{Rng, thread_rng};
+use futures_util::{stream, TryStreamExt};
+use rand::{thread_rng, Rng};
 use tokio::fs::File;
 use tokio::io::{AsyncBufReadExt, BufReader};
 use tokio::signal::unix;
@@ -27,7 +27,7 @@ use tracing::level_filters::LevelFilter;
 use tracing::{debug, info, subscriber, warn};
 use tracing_subscriber::filter::Targets;
 use tracing_subscriber::layer::SubscriberExt;
-use tracing_subscriber::{Registry, fmt};
+use tracing_subscriber::{fmt, Registry};

 use super::Result;
 use crate::cli::arg::{Args, Command};

however, with 1.8.0-nightly (6c6d210089 2024-09-22) this version, it changes a lot of files:

Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) modified: core/src/cli/bootstrap.rs modified: core/src/cli/linux/reload.rs modified: core/src/cli/mod.rs modified: core/src/config/mod.rs modified: core/src/control/linux.rs modified: core/src/node/mod.rs modified: core/src/resolve/mod.rs modified: core/src/tun/linux/ebpf.rs modified: core/src/tun/linux/mod.rs modified: core/src/utils.rs modified: core/src/wireguard/mod.rs modified: core/src/wireguard/parse.rs

all of these diff like:

-use base64::prelude::BASE64_STANDARD;
 use base64::Engine;
+use base64::prelude::BASE64_STANDARD;
 use std::io;
 use std::io::ErrorKind;
 use std::path::{Path, PathBuf};
-use std::sync::atomic::{AtomicUsize, Ordering};
 use std::sync::Arc;
+use std::sync::atomic::{AtomicUsize, Ordering};

also there are other kind change, like

-                        Ok((
-                            peer_info.public_key,
-                            StructuredPeer {
-                                endpoint: peer_info.endpoint.clone(),
-                                allowed_ips: peer.allowed_ips.clone(),
-                            },
-                        ))
+                        Ok((peer_info.public_key, StructuredPeer {
+                            endpoint: peer_info.endpoint.clone(),
+                            allowed_ips: peer.allowed_ips.clone(),
+                        }))

Is this an expected behavioral change?

kodieg commented 2 months ago

I observed the same issue. The second kind of change you can revert using:

overflow_delimited_expr=false 

I couldn't find a way to fix import change. I think this is connected with introducing option style_edition="2024" which introduced new sorting algorithm. Unfortunately changing style_editon to <= 2021 does not fix the issue (I think it behaves like version="one" then and changes a.0.0 to a.0 .0 )

ytmimi commented 2 months ago

These changes are expected when using version=Two or style_edition=2024. You can take a look at the release notes for information on what changed.

kodieg commented 2 months ago

So basically there is no way to keep previous settings and we need to reformat whole code base when upgrading rust toolchain. Using style_edition=2021 or 2015 reformats other stuff (tuple nested accessors).

This is far from ideal.

pon., 23 wrz 2024, 15:26 użytkownik Yacin Tmimi @.***> napisał:

These changes are expected when using version=Two or style_edition=2024. You can take a look at the release notes for information on what changed https://github.com/rust-lang/rustfmt/blob/master/CHANGELOG.md#changed.

— Reply to this email directly, view it on GitHub https://github.com/rust-lang/rustfmt/issues/6346#issuecomment-2368242976, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJXNOECPVXDWSLKHTYTE3DZYAJHTAVCNFSM6AAAAABOV3G2YOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNRYGI2DEOJXGY . You are receiving this because you commented.Message ID: @.***>

calebcartwright commented 2 months ago

Anyone that was using the unstable version option with the Two value was explicitly opting in to unstable formatting that could potentially be changed with every single nightly release.

That's the choice that you'd voluntarily made before, and that dynamic, unstable formatting has changed. rustfmt has a stability guarantee that ensures stable, default formatting doesn't change, but that's not applicable here.

If you feel strongly enough about the old sorting algorithm and would like to have the option to utilize it over the new algorithm that the Style Guide now prescribes then I'd encourage you to open a feature request, and consider opening a PR.

Tangentially, I will also refer back to a note mentioned in the Style Guide evolution RFC that suggested the usage of git's blame.ignoreRevsFile as a method of helping to hiding these changes in tooling