From ec946570772a286e9c3cbd57c34bb40d36131275 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 30 Nov 2020 15:35:55 +0100 Subject: Fix use merging not using the first path segment --- crates/ide_db/src/helpers/insert_use.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/helpers/insert_use.rs b/crates/ide_db/src/helpers/insert_use.rs index 67e800fad..08d246c16 100644 --- a/crates/ide_db/src/helpers/insert_use.rs +++ b/crates/ide_db/src/helpers/insert_use.rs @@ -384,7 +384,7 @@ fn path_cmp_for_sort(a: Option, b: Option) -> Ordering { /// Path comparison func for binary searching for merging. fn path_cmp_bin_search(lhs: Option, rhs: Option) -> Ordering { - match (lhs.and_then(|path| path.segment()), rhs.and_then(|path| path.segment())) { + match (lhs.as_ref().and_then(first_segment), rhs.as_ref().and_then(first_segment)) { (None, None) => Ordering::Equal, (None, Some(_)) => Ordering::Less, (Some(_), None) => Ordering::Greater, @@ -1081,6 +1081,15 @@ use std::io;", ) } + #[test] + fn merge_nested_considers_first_segments() { + check_full( + "hir_ty::display::write_bounds_like_dyn_trait", + r"use hir_ty::{autoderef, display::{HirDisplayError, HirFormatter}, method_resolution};", + r"use hir_ty::{autoderef, display::{HirDisplayError, HirFormatter, write_bounds_like_dyn_trait}, method_resolution};", + ); + } + #[test] fn skip_merge_last_too_long() { check_last( -- cgit v1.2.3