rustfmt: `rustfmt 1.7.0-nightly` inconsistent output across targets
Our CI started failing at the formatting check step after updating to 1.7.0-nightly (9a66e4471 2023-11-19); however, when run locally cargo +nightly fmt --check passes. I verified that they both are using the same version of rustfmt, the only differences being the platform/target.
CI: nightly-x86_64-unknown-linux-gnu installed - rustc 1.76.0-nightly (9a66e4471 2023-11-19)
Local: nightly-aarch64-apple-darwin - Up to date : 1.76.0-nightly (9a66e4471 2023-11-19)
Note that rustfmt 1.7.0-nightly (28317017 2023-11-17) produces the same output regardless of platform, so I think that the issue only exists in the most recent nightly (rustfmt 1.7.0-nightly (9a66e447 2023-11-19)) on the nightly-aarch64-apple-darwin target.
Example
CI Output (nightly-x86_64-unknown-linux-gnu)
use serde_json::json;
fn main() {
let map = json!({ "key": "value" });
let _value: String = map
.get("key")
.map(|v| v.as_str())
.flatten()
.unwrap_or_default()
.to_string();
}
Local Output (nightly-aarch64-apple-darwin)
use serde_json::json;
fn main() {
let map = json!({ "key": "value" });
let _value: String =
map.get("key")
.map(|v| v.as_str())
.flatten()
.unwrap_or_default()
.to_string();
}
Output Diff
diff --git a/src/main.rs b/src/main.rs
index 789b018..771d6ca 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,10 +3,10 @@ use serde_json::json;
fn main() {
let map = json!({ "key": "value" });
- let _value: String =
- map.get("key")
- .map(|v| v.as_str())
- .flatten()
- .unwrap_or_default()
- .to_string();
+ let _value: String = map
+ .get("key")
+ .map(|v| v.as_str())
+ .flatten()
+ .unwrap_or_default()
+ .to_string();
}
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Reactions: 12
- Comments: 26 (19 by maintainers)
Commits related to this issue
- Revert "cargo +nightly fmt" This reverts commit 4e590b2f288e8ac084fac799ad567bb33329c5c7. Reverting because of problem in rustfmt +nightly on aarch64 architectures https://github.com/rust-lang/rust... — committed to jqnatividad/qsv by jqnatividad 7 months ago
- Undo aarch64 rustfmt skips. These skips were added in #173 to work around this issue: https://github.com/rust-lang/rustfmt/issues/5964 It has been resolved; so formatting should now work on all ar... — committed to jsirois/jump by jsirois 7 months ago
- Undo aarch64 rustfmt skips. (#178) These skips were added in #173 to work around this issue: https://github.com/rust-lang/rustfmt/issues/5964 It has been resolved; so formatting should now work on... — committed to a-scie/jump by jsirois 7 months ago
- Update nightly to 2024-01-11 (arbitrarily chosen) trying to solve difference in rustfmt output between Mac Intel and Mac Silicon: https://github.com/rust-lang/rustfmt/issues/5964 — committed to Sajjon/RadixWalletKit by Sajjon 5 months ago
- Update nightly to 2024-01-11 (arbitrarily chosen) trying to solve difference in rustfmt output between Mac Intel and Mac Silicon: https://github.com/rust-lang/rustfmt/issues/5964 — committed to Vinnstah/RadixWalletKit by Sajjon 5 months ago
Can confirm this is resolved. I just updated with
rustupto the latest nightly:This is the rustfmt version I have now:
And formatting my (correctly formatted) code from my repository no longer crates a diff.
Yea, that’s what I did. Essentially:
./x.py build rusfmtgh pr checkout 118127./x.py build rustfmtFWIW, bisecting showed the change appeared with https://github.com/rust-lang/rust/pull/117500.
@lukesneeringer thanks for providing a small reproducible test case. I think a new issue would be overkill at this point. I couldn’t tell you why these issues are related, but something definitely seems off on
aarch64-apple-darwinand the issues start with thenightly-2023-11-20-aarch64-apple-darwintoolchain.Confirmation Screenshot
@xxchan thank you for also providing some confirmation on this.
At this point I’m not too sure what the underlying issue is, but I’ll be sure to report back if I figure anything out.
@ytmimi I’ve come up with a fairly simple repro case. I’m posting it here rather than making it a new ticket because I’ve proven that it only occurs on aarch64-apple-darwin (not Linux). I’m happy to open a new issue if appropriate.
Here’s my
src/lib.rsfile (this is documentation from one of my actual crates, but you can repro with literally just this):Also the following
rustfmt.tomlfile:Expected Behavior (Linux)
On Linux, using
nightly-2023-11-21I get this diff (the diffs are expected as I use other rustfmt options, which I removed to make the repro case simple):Unexpected Behavior (Darwin)
On Mac/Darwin only, on
nightly-2023-10-21(and this started only onnightly-2023-10-19), I get this diff:I’m happy to post another issue if you still believe it’s unrelated, although since it popped up at the same time and appears to be isolated to Macs, I really do think it’s a symptom of the same issue.
I can do that. Although I’m fairly certain it’s related, and this comment seems to suggest the same.
I’ll open a separate issue in a little bit when I get a moment. 😃
P. S. I didn’t know about the
+nightly-{date}syntax, thanks for the tip!As a note, the output on Darwin is alarmingly weird. The formatting differences are annoying enough, but it also eats comments after a single blank line, e.g.
^-- The second and third line of the above get removed.