fix: Don't drop glob with nested self

This commit is contained in:
DropDemBits 2022-02-14 19:41:49 -05:00
parent df2eb3c7cb
commit 86c1251afb
No known key found for this signature in database
GPG Key ID: 894910BF83E70347
2 changed files with 15 additions and 0 deletions

View File

@ -321,6 +321,18 @@ use foo::{bar::{self}};
)
}
#[test]
fn test_merge_nested_list_self_and_glob() {
check_assist(
merge_imports,
r"
use std$0::{fmt::*};
use std::{fmt::{self, Display}};
",
r"use std::{fmt::{self, *, Display}};",
)
}
#[test]
fn test_merge_single_wildcard_diff_prefixes() {
check_assist(

View File

@ -115,6 +115,9 @@ fn recursive_merge(lhs: &ast::UseTree, rhs: &ast::UseTree, merge: MergeBehavior)
let tree_contains_self = |tree: &ast::UseTree| {
tree.use_tree_list()
.map(|tree_list| tree_list.use_trees().any(|it| tree_is_self(&it)))
// Glob imports aren't part of the use-tree lists,
// so they need to be handled explicitly
.or_else(|| tree.star_token().is_some().then(|| false))
};
match (tree_contains_self(lhs_t), tree_contains_self(&rhs_t)) {
(Some(true), None) => continue,