Rustfmt behaving differently between systems

Hi! I'm trying to implement a CI pipeline for a project, and seeing different behavior in my rustfmt step than I see locally.

Here's what my GitHub Actions workflow looks like:

      - name: Install Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          profile: minimal
          override: true
          default: true
          components: rustfmt, clippy

      - name: Rust version
        run: |
          rustup --version && cargo --version && cargo fmt --version && cargo clippy --version && \
            cargo tarpaulin --version

      - name: Lint and format
        run: |
          cargo fmt --check --verbose
          cargo clippy --all-targets --all-features

And this is the result:

rustup 1.26.0 (5af9b9484 2023-04-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.70.0 (90c541806 2023-05-31)`
cargo 1.70.0 (ec8a8a0ca 2023-04-25)
rustfmt 1.5.2-stable (90c5418 2023-05-31)
clippy 0.1.70 (90c5418 2023-05-31)
cargo-tarpaulin version: 0.26.1
...
[example (2021)] "/home/runner/work/clio-auth/clio-auth/examples/auth0.rs"
[lib (2021)] "/home/runner/work/clio-auth/clio-auth/src/lib.rs"
rustfmt --edition 2021 --check /home/runner/work/clio-auth/clio-auth/examples/auth0.rs /home/runner/work/clio-auth/clio-auth/src/lib.rs
Diff in /home/runner/work/clio-auth/clio-auth/examples/auth0.rs at line 56:
                     token_result.unwrap_err()
                 );
             }
-        },
+        }
         Err(e) => warn!("👎 uh oh! {:?}", e),
     };
     info!("🏁 finished!");
Diff in /home/runner/work/clio-auth/clio-auth/src/server.rs at line 68:
                 .header("Connection", "close")
                 .body(body)
                 .unwrap()
-        },
+        }
         None => Response::builder()
             .status(400)
             .header("Connection", "close")
Error: Process completed with exit code 1.

If I run the same commands locally:

$ rustup --version && cargo --version && cargo fmt --version && cargo clippy --version && \
            cargo tarpaulin --version
rustup 1.26.0 (5af9b9484 2023-04-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.70.0 (90c541806 2023-05-31)`
cargo 1.70.0 (ec8a8a0ca 2023-04-25)
rustfmt 1.5.2-stable (90c54180 2023-05-31)
clippy 0.1.70 (90c54180 2023-05-31)
cargo-tarpaulin version: 0.26.1
...
$ cargo fmt --check --verbose
[example (2021)] "/Users/ericmcintyre/Development/src/clio-auth/examples/auth0.rs"
[lib (2021)] "/Users/ericmcintyre/Development/src/clio-auth/src/lib.rs"
rustfmt --edition 2021 --check /Users/ericmcintyre/Development/src/clio-auth/examples/auth0.rs /Users/ericmcintyre/Development/src/clio-auth/src/lib.rs

The tool versions are identical. I have no local changes in my workspace. The only difference I can see is OS (macOS locally, Ubuntu in GitHub). Can anyone help me understand why rustfmt is reporting different results?

I've noticed that GitHub Ubuntu runners have a weird setup where they have some tools already installed — on rustup update I see this warning from rustup:

warning: tool `rust-analyzer` is already installed, remove it from `/home/runner/.cargo/bin`, then run `rustup update` to have rustup manage this tool.
warning: tool `rustfmt` is already installed, remove it from `/home/runner/.cargo/bin`, then run `rustup update` to have rustup manage this tool.
warning: tool `cargo-fmt` is already installed, remove it from `/home/runner/.cargo/bin`, then run `rustup update` to have rustup manage this tool.

Possibly they are interfering somehow? The version numbers being identical suggests they shouldn't, though.

1 Like

Thanks for the lead. I'll see if I can remove/suppress the stock tooling.

I verified the path of rustup/cargo before & after I installed the latest toolchain, and confirmed that I was executing the right one. Not sure how to account for it. If I have time, I'll work up a minimal example and open a bug report.

In the meantime, I was able to get the build working by creating a .rustfmt.toml file to force the match_block_trailing_comma setting to false. This seems to be working locally and in CI.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.