@@ -200,7 +200,18 @@ fn recursive_merge(
200200 return None ;
201201 }
202202 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+ } ) {
204215 Ok ( idx) => {
205216 let lhs_t = & mut use_trees[ idx] ;
206217 let lhs_path = lhs_t. path ( ) ?;
@@ -327,11 +338,11 @@ fn path_cmp_for_sort(a: Option<ast::Path>, b: Option<ast::Path>) -> Ordering {
327338
328339/// Path comparison func for binary searching for merging.
329340fn 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 ( ) ) ) {
331342 ( None , None ) => Ordering :: Equal ,
332343 ( None , Some ( _) ) => Ordering :: Less ,
333344 ( 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) ,
335346 }
336347}
337348
@@ -801,6 +812,24 @@ use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
801812 )
802813 }
803814
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+
804833 #[ test]
805834 fn merge_groups_skip_pub ( ) {
806835 check_full (
0 commit comments