From 4d092c32993cf61eef479b2388b633fe39d07cc0 Mon Sep 17 00:00:00 2001 From: A4-Tacks Date: Fri, 18 Sep 2026 18:47:18 +0800 Subject: [PATCH] internal: xtask reformat ignore nightly dates `nightly-2026-08-23` cannot match `rustfmt 1.10.0-nightly (c54751567b 2026-08-22)` --- xtask/src/codegen.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index 482b31e306ca..f8a7f1875539 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs @@ -132,12 +132,19 @@ fn reformat(text: String) -> String { let rustfmt_toml = project_root().join("rustfmt.toml"); let toolchain = &std::env::var("RUSTFMT_TOOLCHAIN").unwrap_or("stable".to_owned()); let version = cmd!(sh, "rustup run {toolchain} rustfmt --version").read().unwrap_or_default(); + let toolchain_matches = |version: &str| { + if version.contains(toolchain) { + return true; + } + // Nightly date cannot be accurately matched + toolchain.starts_with("nightly-") && version.contains("nightly") + }; // First try explicitly requesting the stable channel via rustup in case nightly is being used by default, // then plain rustfmt in case rustup isn't being used to manage the compiler (e.g. when using Nix). - let mut stdout = if !version.contains(toolchain) { + let mut stdout = if !toolchain_matches(&version) { let version = cmd!(sh, "rustfmt --version").read().unwrap_or_default(); - if !version.contains(toolchain) { + if !toolchain_matches(&version) { panic!( "Failed to run rustfmt from toolchain '{toolchain}'. \ Please run `rustup component add rustfmt --toolchain {toolchain}` to install it.",