@@ -264,19 +264,21 @@ pub fn common_prefix(lhs: &ast::Path, rhs: &ast::Path) -> Option<(ast::Path, ast
264
264
265
265
/// Use tree comparison func for binary searching for merging.
266
266
fn use_tree_cmp_bin_search ( lhs : & ast:: UseTree , rhs : & ast:: UseTree ) -> Ordering {
267
+ let lhs_is_simple_path = lhs. is_simple_path ( ) && lhs. rename ( ) . is_none ( ) ;
268
+ let rhs_is_simple_path = rhs. is_simple_path ( ) && rhs. rename ( ) . is_none ( ) ;
267
269
match (
268
270
lhs. path ( ) . as_ref ( ) . and_then ( ast:: Path :: first_segment) ,
269
271
rhs. path ( ) . as_ref ( ) . and_then ( ast:: Path :: first_segment) ,
270
272
) {
271
- ( None , None ) => match ( lhs . is_simple_path ( ) , lhs . is_simple_path ( ) ) {
273
+ ( None , None ) => match ( lhs_is_simple_path , rhs_is_simple_path ) {
272
274
( true , true ) => Ordering :: Equal ,
273
275
( true , false ) => Ordering :: Less ,
274
276
( false , true ) => Ordering :: Greater ,
275
277
( false , false ) => use_tree_cmp_by_tree_list_glob_or_alias ( lhs, rhs, false ) ,
276
278
} ,
277
- ( Some ( _) , None ) if !rhs . is_simple_path ( ) => Ordering :: Less ,
279
+ ( Some ( _) , None ) if !rhs_is_simple_path => Ordering :: Less ,
278
280
( Some ( _) , None ) => Ordering :: Greater ,
279
- ( None , Some ( _) ) if !lhs . is_simple_path ( ) => Ordering :: Greater ,
281
+ ( None , Some ( _) ) if !lhs_is_simple_path => Ordering :: Greater ,
280
282
( None , Some ( _) ) => Ordering :: Less ,
281
283
( Some ( ref a) , Some ( ref b) ) => path_segment_cmp ( a, b) ,
282
284
}
@@ -289,16 +291,18 @@ fn use_tree_cmp_bin_search(lhs: &ast::UseTree, rhs: &ast::UseTree) -> Ordering {
289
291
/// Example foo::{self, foo, baz, Baz, Qux, FOO_BAZ, *, {Bar}}
290
292
/// Ref: <https://github.com/rust-lang/rustfmt/blob/6356fca675bd756d71f5c123cd053d17b16c573e/src/imports.rs#L83-L86>.
291
293
pub ( super ) fn use_tree_cmp ( a : & ast:: UseTree , b : & ast:: UseTree ) -> Ordering {
294
+ let a_is_simple_path = a. is_simple_path ( ) && a. rename ( ) . is_none ( ) ;
295
+ let b_is_simple_path = b. is_simple_path ( ) && b. rename ( ) . is_none ( ) ;
292
296
match ( a. path ( ) , b. path ( ) ) {
293
- ( None , None ) => match ( a . is_simple_path ( ) , b . is_simple_path ( ) ) {
297
+ ( None , None ) => match ( a_is_simple_path , b_is_simple_path ) {
294
298
( true , true ) => Ordering :: Equal ,
295
299
( true , false ) => Ordering :: Less ,
296
300
( false , true ) => Ordering :: Greater ,
297
301
( false , false ) => use_tree_cmp_by_tree_list_glob_or_alias ( a, b, true ) ,
298
302
} ,
299
- ( Some ( _) , None ) if !b . is_simple_path ( ) => Ordering :: Less ,
303
+ ( Some ( _) , None ) if !b_is_simple_path => Ordering :: Less ,
300
304
( Some ( _) , None ) => Ordering :: Greater ,
301
- ( None , Some ( _) ) if !a . is_simple_path ( ) => Ordering :: Greater ,
305
+ ( None , Some ( _) ) if !a_is_simple_path => Ordering :: Greater ,
302
306
( None , Some ( _) ) => Ordering :: Less ,
303
307
( Some ( ref a_path) , Some ( ref b_path) ) => {
304
308
// cmp_by would be useful for us here but that is currently unstable
@@ -313,9 +317,9 @@ pub(super) fn use_tree_cmp(a: &ast::UseTree, b: &ast::UseTree) -> Ordering {
313
317
ord => Some ( ord) ,
314
318
}
315
319
}
316
- EitherOrBoth :: Left ( _) if b . is_simple_path ( ) => Some ( Ordering :: Greater ) ,
320
+ EitherOrBoth :: Left ( _) if b_is_simple_path => Some ( Ordering :: Greater ) ,
317
321
EitherOrBoth :: Left ( _) => Some ( Ordering :: Less ) ,
318
- EitherOrBoth :: Right ( _) if a . is_simple_path ( ) => Some ( Ordering :: Less ) ,
322
+ EitherOrBoth :: Right ( _) if a_is_simple_path => Some ( Ordering :: Less ) ,
319
323
EitherOrBoth :: Right ( _) => Some ( Ordering :: Greater ) ,
320
324
} )
321
325
. unwrap_or_else ( || use_tree_cmp_by_tree_list_glob_or_alias ( a, b, true ) )
0 commit comments