From 7985d0476f16a55352367d20a2f367af4ff7b185 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Mon, 13 Jan 2025 16:31:15 -0300 Subject: [PATCH 1/2] fix(nargo_fmt): don't consider identifiers the same if they are equal case insensitive --- tooling/nargo_fmt/src/formatter/use_tree_merge.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tooling/nargo_fmt/src/formatter/use_tree_merge.rs b/tooling/nargo_fmt/src/formatter/use_tree_merge.rs index 76fdcd0d0f8..5e2c8f9a456 100644 --- a/tooling/nargo_fmt/src/formatter/use_tree_merge.rs +++ b/tooling/nargo_fmt/src/formatter/use_tree_merge.rs @@ -179,7 +179,12 @@ impl Ord for Segment { if let (Segment::Plain(self_string), Segment::Plain(other_string)) = (self, other) { // Case-insensitive comparison for plain segments - self_string.to_lowercase().cmp(&other_string.to_lowercase()) + let ordering = self_string.to_lowercase().cmp(&other_string.to_lowercase()); + if ordering == Ordering::Equal { + self_string.cmp(&other_string) + } else { + ordering + } } else { order_number_ordering } @@ -620,4 +625,10 @@ use std::merkle::compute_merkle_root; let expected = "use std::{as_witness, merkle::compute_merkle_root};\n"; assert_format(src, expected); } + + #[test] + fn does_not_merge_same_identifiers_if_equal_case_insensitive() { + let src = "use bigint::{BigNum, bignum::BigNumTrait};\n"; + assert_format(src, src); + } } From 8f385f066ffe6c064cdbf5b98fa3d3872e0f3e8e Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Mon, 13 Jan 2025 16:47:34 -0300 Subject: [PATCH 2/2] Update tooling/nargo_fmt/src/formatter/use_tree_merge.rs --- tooling/nargo_fmt/src/formatter/use_tree_merge.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/nargo_fmt/src/formatter/use_tree_merge.rs b/tooling/nargo_fmt/src/formatter/use_tree_merge.rs index 5e2c8f9a456..a679e026435 100644 --- a/tooling/nargo_fmt/src/formatter/use_tree_merge.rs +++ b/tooling/nargo_fmt/src/formatter/use_tree_merge.rs @@ -181,7 +181,7 @@ impl Ord for Segment { // Case-insensitive comparison for plain segments let ordering = self_string.to_lowercase().cmp(&other_string.to_lowercase()); if ordering == Ordering::Equal { - self_string.cmp(&other_string) + self_string.cmp(other_string) } else { ordering }