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

Most upvoted comments

Can confirm this is resolved. I just updated with rustup to the latest nightly:

nightly-aarch64-unknown-linux-gnu updated - rustc 1.76.0-nightly (f5dc2653f 2023-11-25)

This is the rustfmt version I have now:

rustfmt 1.7.0-nightly (f5dc2653 2023-11-25)

And formatting my (correctly formatted) code from my repository no longer crates a diff.

Yea, that’s what I did. Essentially:

  1. ./x.py build rusfmt
  2. Verified it formatted incorrectly.
  3. gh pr checkout 118127
  4. ./x.py build rustfmt
  5. Verified it formatted correctly.

FWIW, 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-darwin and the issues start with the nightly-2023-11-20-aarch64-apple-darwin toolchain.

Confirmation Screenshot Screen Shot 2023-11-21 at 10 40 54 PM

@xxchan thank you for also providing some confirmation on this.

Is it possible that this is caused by sth like rustup or rust nightly release pipeline?

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.rs file (this is documentation from one of my actual crates, but you can repro with literally just this):

//! Market calendar aware utilities
//!
//! This crate primarily provides the [`MarketCalendar`] trait, which adds methods for traversing
//! trading days, determining whether the markets are open on a given date, and so on. Currently
//! the trait is only applied to [`chrono::NaiveDate`], and when brought into scope, allows you to
//! ask about the market calendar for a given date, or traverse by trading day count.
//!
//! ```
//! use chrono::NaiveDate;
//! use market_cal::MarketCalendar;
//!
//! let dt = NaiveDate::from_ymd_opt(2020, 12, 24).unwrap();
//! assert_eq!(dt.next_trading_day(), NaiveDate::from_ymd_opt(2020, 12, 28).unwrap());
//! ```

Also the following rustfmt.toml file:

format_code_in_doc_comments = true
wrap_comments = true

Expected Behavior (Linux)

On Linux, using nightly-2023-11-21 I get this diff (the diffs are expected as I use other rustfmt options, which I removed to make the repro case simple):

 //! Market calendar aware utilities
 //!
-//! This crate primarily provides the [`MarketCalendar`] trait, which adds methods for traversing
-//! trading days, determining whether the markets are open on a given date, and so on. Currently
-//! the trait is only applied to [`chrono::NaiveDate`], and when brought into scope, allows you to
-//! ask about the market calendar for a given date, or traverse by trading day count.
+//! This crate primarily provides the [`MarketCalendar`] trait, which adds
+//! methods for traversing trading days, determining whether the markets are
+//! open on a given date, and so on. Currently the trait is only applied to
+//! [`chrono::NaiveDate`], and when brought into scope, allows you to
+//! ask about the market calendar for a given date, or traverse by trading day
+//! count.
 //!
 //! ```
 //! use chrono::NaiveDate;
Diff in /home/luke/Code/testme/src/lib.rs at line 10:
 //! use market_cal::MarketCalendar;
 //!
 //! let dt = NaiveDate::from_ymd_opt(2020, 12, 24).unwrap();
-//! assert_eq!(dt.next_trading_day(), NaiveDate::from_ymd_opt(2020, 12, 28).unwrap());
+//! assert_eq!(
+//!     dt.next_trading_day(),
+//!     NaiveDate::from_ymd_opt(2020, 12, 28).unwrap()
+//! );
 //!

Unexpected Behavior (Darwin)

On Mac/Darwin only, on nightly-2023-10-21 (and this started only on nightly-2023-10-19), I get this diff:

 //! Market calendar aware utilities
-//!
-//! This crate primarily provides the [`MarketCalendar`] trait, which adds methods for traversing
-//! trading days, determining whether the markets are open on a given date, and so on. Currently
-//! the trait is only applied to [`chrono::NaiveDate`], and when brought into scope, allows you to
-//! ask about the market calendar for a given date, or traverse by trading day count.
-//!
-//! ```
-//! use chrono::NaiveDate;
-//! use market_cal::MarketCalendar;
-//!
-//! let dt = NaiveDate::from_ymd_opt(2020, 12, 24).unwrap();
-//! assert_eq!(dt.next_trading_day(), NaiveDate::from_ymd_opt(2020, 12, 28).unwrap());
-//! ```

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.

// This is a comment.
//
// This is more information.

^-- The second and third line of the above get removed.