Skip to content

Commit adb3729

Browse files
committed
Fix: expand glob import to empty braces if the glob is unused
1 parent 580a6c4 commit adb3729

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

crates/ide_assists/src/handlers/expand_glob_import.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext) -> Opti
7272

7373
match use_tree.star_token() {
7474
Some(star) => {
75-
let needs_braces = use_tree.path().is_some() && names_to_import.len() > 1;
75+
let needs_braces = use_tree.path().is_some() && names_to_import.len() != 1;
7676
if needs_braces {
7777
ted::replace(star, expanded.syntax())
7878
} else {
@@ -294,6 +294,40 @@ fn qux(bar: Bar, baz: Baz) {
294294
)
295295
}
296296

297+
#[test]
298+
fn expanding_glob_import_unused() {
299+
check_assist(
300+
expand_glob_import,
301+
r"
302+
mod foo {
303+
pub struct Bar;
304+
pub struct Baz;
305+
pub struct Qux;
306+
307+
pub fn f() {}
308+
}
309+
310+
use foo::*$0;
311+
312+
fn qux() {}
313+
",
314+
r"
315+
mod foo {
316+
pub struct Bar;
317+
pub struct Baz;
318+
pub struct Qux;
319+
320+
pub fn f() {}
321+
}
322+
323+
use foo::{};
324+
325+
fn qux() {}
326+
",
327+
)
328+
}
329+
330+
297331
#[test]
298332
fn expanding_glob_import_with_existing_explicit_names() {
299333
check_assist(

0 commit comments

Comments
 (0)