Sitelet https://github.com/starkware-libs/cairo/commit/792625f00d940975bcbf9d21ae8f16c2a2071071
Skip to content

Commit 792625f

Browse files
authored
bugfix(formatter): Made formatter merge in use more consistent. (#10150)
1 parent a0fc8f8 commit 792625f

3 files changed

Lines changed: 8 additions & 9 deletions

File tree

‎crates/cairo-lang-formatter/src/formatter_impl.rs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,13 +1284,8 @@ fn compare_use_paths<'a>(a: &UsePath<'a>, b: &UsePath<'a>, db: &dyn Database) ->
12841284
match (a, b) {
12851285
// Case for multi vs multi.
12861286
(UsePath::Multi(a_multi), UsePath::Multi(b_multi)) => {
1287-
let empty_string = "".into();
12881287
let get_min_child = |multi: &ast::UsePathMulti<'a>| {
1289-
multi.use_paths(db).elements(db).min_by_key(|child| match child {
1290-
UsePath::Leaf(leaf) => leaf.extract_ident(db),
1291-
UsePath::Single(single) => single.extract_ident(db),
1292-
_ => &empty_string,
1293-
})
1288+
multi.use_paths(db).elements(db).min_by(|a, b| compare_use_paths(a, b, db))
12941289
};
12951290
match (get_min_child(a_multi), get_min_child(b_multi)) {
12961291
(Some(a_min), Some(b_min)) => compare_use_paths(&a_min, &b_min, db),

‎crates/cairo-lang-formatter/test_data/cairo_files/sort_inner_use.cairo‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ use a::{{d}, e, ab, c};
1818

1919
use a::{a, a::{c, {a}}, a::{b}, a::{{a},b}};
2020
use a::{c, d::{a, *}, r, t::{*, c::a}};
21+
22+
use x::{{self, m}, {a, m}};

‎crates/cairo-lang-formatter/test_data/expected_results/sort_inner_use.cairo‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ use a::{a, b, c, d};
44

55
use a::{a, b as aee, b as bee, c as cee, d};
66

7-
use a::{a, a::{b}, a::{c, {a}}, a::{b, {a}}};
7+
use a::{a, a::{b}, a::{b, {a}}, a::{c, {a}}};
88
use a::{a as ab, a as bc};
9+
10+
use a::{ab, c, e, {d}};
911
use a::{b, d};
1012
use a::{b, d};
1113

1214
use a::{c, d};
1315
use a::{c, d::{*, a}, r, t::{*, c::a}};
14-
15-
use a::{ab, c, e, {d}};
1616
use aba;
1717
use b::{a, b, c, d};
1818
use c::{*, a, b, c, d};
1919
use std::collections::HashMap;
20+
21+
use x::{{self, m}, {a, m}};
2022
use crate::utils::{a, b, c, d};

0 commit comments

Comments
 (0)