@@ -200,7 +200,18 @@ fn recursive_merge(
200
200
return None ;
201
201
}
202
202
let rhs_path = rhs_t. path ( ) ;
203
- match use_trees. binary_search_by ( |p| path_cmp_bin_search ( p. path ( ) , rhs_path. clone ( ) ) ) {
203
+ match use_trees. binary_search_by ( |lhs_t| {
204
+ let ( lhs_t, rhs_t) = match lhs_t
205
+ . path ( )
206
+ . zip ( rhs_path. clone ( ) )
207
+ . and_then ( |( lhs, rhs) | common_prefix ( & lhs, & rhs) )
208
+ {
209
+ Some ( ( lhs_p, rhs_p) ) => ( lhs_t. split_prefix ( & lhs_p) , rhs_t. split_prefix ( & rhs_p) ) ,
210
+ None => ( lhs_t. clone ( ) , rhs_t. clone ( ) ) ,
211
+ } ;
212
+
213
+ path_cmp_bin_search ( lhs_t. path ( ) , rhs_t. path ( ) )
214
+ } ) {
204
215
Ok ( idx) => {
205
216
let lhs_t = & mut use_trees[ idx] ;
206
217
let lhs_path = lhs_t. path ( ) ?;
@@ -327,11 +338,11 @@ fn path_cmp_for_sort(a: Option<ast::Path>, b: Option<ast::Path>) -> Ordering {
327
338
328
339
/// Path comparison func for binary searching for merging.
329
340
fn path_cmp_bin_search ( lhs : Option < ast:: Path > , rhs : Option < ast:: Path > ) -> Ordering {
330
- match ( lhs, rhs) {
341
+ match ( lhs. and_then ( |path| path . segment ( ) ) , rhs. and_then ( |path| path . segment ( ) ) ) {
331
342
( None , None ) => Ordering :: Equal ,
332
343
( None , Some ( _) ) => Ordering :: Less ,
333
344
( Some ( _) , None ) => Ordering :: Greater ,
334
- ( Some ( ref a) , Some ( ref b) ) => path_cmp_short ( a, b) ,
345
+ ( Some ( ref a) , Some ( ref b) ) => path_segment_cmp ( a, b) ,
335
346
}
336
347
}
337
348
@@ -801,6 +812,24 @@ use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
801
812
)
802
813
}
803
814
815
+ #[ test]
816
+ fn merge_groups_full_nested_long ( ) {
817
+ check_full (
818
+ "std::foo::bar::Baz" ,
819
+ r"use std::{foo::bar::Qux};" ,
820
+ r"use std::{foo::bar::{Baz, Qux}};" ,
821
+ ) ;
822
+ }
823
+
824
+ #[ test]
825
+ fn merge_groups_last_nested_long ( ) {
826
+ check_full (
827
+ "std::foo::bar::Baz" ,
828
+ r"use std::{foo::bar::Qux};" ,
829
+ r"use std::{foo::bar::{Baz, Qux}};" ,
830
+ ) ;
831
+ }
832
+
804
833
#[ test]
805
834
fn merge_groups_skip_pub ( ) {
806
835
check_full (
0 commit comments