#cargo fmt differs from rustfmt

2 messages · Page 1 of 1 (latest)

dawn pebble
#

Hey, running cargo fmt creates output thats different to running rustfmt.
From my understanding, cargo fmt is just a wrapper around rustfmt?
What can i do to make them behave the same?
In this example I don't have a rustfmt.toml and the Cargo.toml has the default configuration.

cargo fmt:

mod a;

use crate::a::A;
use crate::a::b::B;

fn main() {
    std::thread::spawn(move || {
        loop {
            println!("Hello world {:?} {:?}", A {}, B {});
        }
    });
}

rustfmt src/main.rs:

mod a;

use crate::a::b::B;
use crate::a::A;

fn main() {
    std::thread::spawn(move || loop {
        println!("Hello world {:?} {:?}", A {}, B {});
    });
}

rustfmt --version: rustfmt 1.8.0-stable (4d91de4e48 2025-02-17)
cargo fmt --version: rustfmt 1.8.0-stable (4d91de4e48 2025-02-17)

dull pecan
#

cargo fmt passes the edition declared in your Cargo.toml when it calls rustfmt