From b114fb4f8b93a45fde02f405692bdc79a2ce4451 Mon Sep 17 00:00:00 2001 From: Tapan Prakash Date: Sun, 31 May 2026 12:26:41 +0530 Subject: [PATCH 1/3] Stabilize `hex_literal_case` --- Configurations.md | 2 +- src/config/mod.rs | 2 +- tests/source/hex_literal_lower.rs | 2 ++ tests/source/hex_literal_preserve.rs | 7 +++++++ tests/source/hex_literal_upper.rs | 2 ++ tests/target/hex_literal_lower.rs | 2 ++ tests/target/hex_literal_preserve.rs | 2 ++ tests/target/hex_literal_upper.rs | 2 ++ 8 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/source/hex_literal_preserve.rs diff --git a/Configurations.md b/Configurations.md index 1df79daf798..0f4320853fe 100644 --- a/Configurations.md +++ b/Configurations.md @@ -1257,7 +1257,7 @@ Control the case of the letters in hexadecimal literal values - **Default value**: `Preserve` - **Possible values**: `Preserve`, `Upper`, `Lower` -- **Stable**: No (tracking issue: [#5081](https://github.com/rust-lang/rustfmt/issues/5081)) +- **Stable**: Yes ## `float_literal_trailing_zero` diff --git a/src/config/mod.rs b/src/config/mod.rs index 8abb7439257..8c4ed07c3d7 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -78,7 +78,7 @@ create_config! { "Format the bodies of declarative macro definitions"; skip_macro_invocations: SkipMacroInvocations, false, "Skip formatting the bodies of macros invoked with the following names."; - hex_literal_case: HexLiteralCaseConfig, false, "Format hexadecimal integer literals"; + hex_literal_case: HexLiteralCaseConfig, true, "Format hexadecimal integer literals"; float_literal_trailing_zero: FloatLiteralTrailingZeroConfig, false, "Add or remove trailing zero in floating-point literals"; diff --git a/tests/source/hex_literal_lower.rs b/tests/source/hex_literal_lower.rs index ce307b3aa52..8023f0f19f7 100644 --- a/tests/source/hex_literal_lower.rs +++ b/tests/source/hex_literal_lower.rs @@ -2,4 +2,6 @@ fn main() { let h1 = 0xCAFE_5EA7; let h2 = 0xCAFE_F00Du32; + let h3 = -0xCAFE_5EA7; + let h4 = -0xCAFE_F00Di32; } diff --git a/tests/source/hex_literal_preserve.rs b/tests/source/hex_literal_preserve.rs new file mode 100644 index 00000000000..9c1937b7979 --- /dev/null +++ b/tests/source/hex_literal_preserve.rs @@ -0,0 +1,7 @@ +// rustfmt-hex_literal_case: Preserve +fn main() { + let h1 = 0xcAfE_5Ea7; + let h2 = 0xCaFe_F00du32; + let h3 = -0xcAfE_5Ea7; + let h4 = -0xCaFe_F00di32; +} diff --git a/tests/source/hex_literal_upper.rs b/tests/source/hex_literal_upper.rs index b1092ad71ba..2972e615291 100644 --- a/tests/source/hex_literal_upper.rs +++ b/tests/source/hex_literal_upper.rs @@ -2,4 +2,6 @@ fn main() { let h1 = 0xCaFE_5ea7; let h2 = 0xCAFE_F00Du32; + let h3 = -0xCaFE_5ea7; + let h4 = -0xCAFE_F00Di32; } diff --git a/tests/target/hex_literal_lower.rs b/tests/target/hex_literal_lower.rs index 5c27fded167..f6654d7e3c2 100644 --- a/tests/target/hex_literal_lower.rs +++ b/tests/target/hex_literal_lower.rs @@ -2,4 +2,6 @@ fn main() { let h1 = 0xcafe_5ea7; let h2 = 0xcafe_f00du32; + let h3 = -0xcafe_5ea7; + let h4 = -0xcafe_f00di32; } diff --git a/tests/target/hex_literal_preserve.rs b/tests/target/hex_literal_preserve.rs index e8774d0bb24..9c1937b7979 100644 --- a/tests/target/hex_literal_preserve.rs +++ b/tests/target/hex_literal_preserve.rs @@ -2,4 +2,6 @@ fn main() { let h1 = 0xcAfE_5Ea7; let h2 = 0xCaFe_F00du32; + let h3 = -0xcAfE_5Ea7; + let h4 = -0xCaFe_F00di32; } diff --git a/tests/target/hex_literal_upper.rs b/tests/target/hex_literal_upper.rs index 48bb93d2c1c..a9e03c211fe 100644 --- a/tests/target/hex_literal_upper.rs +++ b/tests/target/hex_literal_upper.rs @@ -2,4 +2,6 @@ fn main() { let h1 = 0xCAFE_5EA7; let h2 = 0xCAFE_F00Du32; + let h3 = -0xCAFE_5EA7; + let h4 = -0xCAFE_F00Di32; } From d7a1fdedaccab8d0500fb10c0f0974387149aba7 Mon Sep 17 00:00:00 2001 From: Tapan Prakash Date: Tue, 2 Jun 2026 21:46:32 +0530 Subject: [PATCH 2/3] Added more test cases for _type hex values --- tests/source/hex_literal_lower.rs | 2 ++ tests/source/hex_literal_preserve.rs | 2 ++ tests/source/hex_literal_upper.rs | 2 ++ tests/target/hex_literal_lower.rs | 2 ++ tests/target/hex_literal_preserve.rs | 2 ++ tests/target/hex_literal_upper.rs | 2 ++ 6 files changed, 12 insertions(+) diff --git a/tests/source/hex_literal_lower.rs b/tests/source/hex_literal_lower.rs index 8023f0f19f7..de2c9f9d9dc 100644 --- a/tests/source/hex_literal_lower.rs +++ b/tests/source/hex_literal_lower.rs @@ -4,4 +4,6 @@ fn main() { let h2 = 0xCAFE_F00Du32; let h3 = -0xCAFE_5EA7; let h4 = -0xCAFE_F00Di32; + let h5 = 0xABcD07_i32; + let h6 = -0xABcD07_i32; } diff --git a/tests/source/hex_literal_preserve.rs b/tests/source/hex_literal_preserve.rs index 9c1937b7979..876592a4f64 100644 --- a/tests/source/hex_literal_preserve.rs +++ b/tests/source/hex_literal_preserve.rs @@ -4,4 +4,6 @@ fn main() { let h2 = 0xCaFe_F00du32; let h3 = -0xcAfE_5Ea7; let h4 = -0xCaFe_F00di32; + let h5 = 0xAbcd07_i32; + let h6 = -0xAbcd07_i32; } diff --git a/tests/source/hex_literal_upper.rs b/tests/source/hex_literal_upper.rs index 2972e615291..d3fbe367185 100644 --- a/tests/source/hex_literal_upper.rs +++ b/tests/source/hex_literal_upper.rs @@ -4,4 +4,6 @@ fn main() { let h2 = 0xCAFE_F00Du32; let h3 = -0xCaFE_5ea7; let h4 = -0xCAFE_F00Di32; + let h5 = 0xAbcd07_i32; + let h6 = -0xAbcd07_i32; } diff --git a/tests/target/hex_literal_lower.rs b/tests/target/hex_literal_lower.rs index f6654d7e3c2..d1d284c6df0 100644 --- a/tests/target/hex_literal_lower.rs +++ b/tests/target/hex_literal_lower.rs @@ -4,4 +4,6 @@ fn main() { let h2 = 0xcafe_f00du32; let h3 = -0xcafe_5ea7; let h4 = -0xcafe_f00di32; + let h5 = 0xabcd07_i32; + let h6 = -0xabcd07_i32; } diff --git a/tests/target/hex_literal_preserve.rs b/tests/target/hex_literal_preserve.rs index 9c1937b7979..876592a4f64 100644 --- a/tests/target/hex_literal_preserve.rs +++ b/tests/target/hex_literal_preserve.rs @@ -4,4 +4,6 @@ fn main() { let h2 = 0xCaFe_F00du32; let h3 = -0xcAfE_5Ea7; let h4 = -0xCaFe_F00di32; + let h5 = 0xAbcd07_i32; + let h6 = -0xAbcd07_i32; } diff --git a/tests/target/hex_literal_upper.rs b/tests/target/hex_literal_upper.rs index a9e03c211fe..4336453abae 100644 --- a/tests/target/hex_literal_upper.rs +++ b/tests/target/hex_literal_upper.rs @@ -4,4 +4,6 @@ fn main() { let h2 = 0xCAFE_F00Du32; let h3 = -0xCAFE_5EA7; let h4 = -0xCAFE_F00Di32; + let h5 = 0xABCD07_i32; + let h6 = -0xABCD07_i32; } From 7bbfcf2d5219f8a1c91e73d000f4c834ae2edb6c Mon Sep 17 00:00:00 2001 From: Tapan Prakash Date: Tue, 2 Jun 2026 21:58:18 +0530 Subject: [PATCH 3/3] Moved hex_literal_case tests to config folder --- tests/source/{ => configs/hex_literal_case}/hex_literal_lower.rs | 0 .../source/{ => configs/hex_literal_case}/hex_literal_preserve.rs | 0 tests/source/{ => configs/hex_literal_case}/hex_literal_upper.rs | 0 tests/target/{ => configs/hex_literal_case}/hex_literal_lower.rs | 0 .../target/{ => configs/hex_literal_case}/hex_literal_preserve.rs | 0 tests/target/{ => configs/hex_literal_case}/hex_literal_upper.rs | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename tests/source/{ => configs/hex_literal_case}/hex_literal_lower.rs (100%) rename tests/source/{ => configs/hex_literal_case}/hex_literal_preserve.rs (100%) rename tests/source/{ => configs/hex_literal_case}/hex_literal_upper.rs (100%) rename tests/target/{ => configs/hex_literal_case}/hex_literal_lower.rs (100%) rename tests/target/{ => configs/hex_literal_case}/hex_literal_preserve.rs (100%) rename tests/target/{ => configs/hex_literal_case}/hex_literal_upper.rs (100%) diff --git a/tests/source/hex_literal_lower.rs b/tests/source/configs/hex_literal_case/hex_literal_lower.rs similarity index 100% rename from tests/source/hex_literal_lower.rs rename to tests/source/configs/hex_literal_case/hex_literal_lower.rs diff --git a/tests/source/hex_literal_preserve.rs b/tests/source/configs/hex_literal_case/hex_literal_preserve.rs similarity index 100% rename from tests/source/hex_literal_preserve.rs rename to tests/source/configs/hex_literal_case/hex_literal_preserve.rs diff --git a/tests/source/hex_literal_upper.rs b/tests/source/configs/hex_literal_case/hex_literal_upper.rs similarity index 100% rename from tests/source/hex_literal_upper.rs rename to tests/source/configs/hex_literal_case/hex_literal_upper.rs diff --git a/tests/target/hex_literal_lower.rs b/tests/target/configs/hex_literal_case/hex_literal_lower.rs similarity index 100% rename from tests/target/hex_literal_lower.rs rename to tests/target/configs/hex_literal_case/hex_literal_lower.rs diff --git a/tests/target/hex_literal_preserve.rs b/tests/target/configs/hex_literal_case/hex_literal_preserve.rs similarity index 100% rename from tests/target/hex_literal_preserve.rs rename to tests/target/configs/hex_literal_case/hex_literal_preserve.rs diff --git a/tests/target/hex_literal_upper.rs b/tests/target/configs/hex_literal_case/hex_literal_upper.rs similarity index 100% rename from tests/target/hex_literal_upper.rs rename to tests/target/configs/hex_literal_case/hex_literal_upper.rs