Skip to content

Commit 5051717

Browse files
bors[bot]yue4u
andauthored
Merge #10589
10589: Fix: expand into {} if the glob import is unused r=lnicola a=rainy-me close #10524 I think the second `expand into {}` behavior is genuinely better. (maybe this should been labeled with good first issue xd) Co-authored-by: rainy-me <[email protected]>
2 parents 580a6c4 + 1ea2c72 commit 5051717

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

crates/ide_assists/src/handlers/expand_glob_import.rs

Lines changed: 34 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,39 @@ 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+
297330
#[test]
298331
fn expanding_glob_import_with_existing_explicit_names() {
299332
check_assist(

0 commit comments

Comments
 (0)