diff options
| author | rainy-me <github@yue.coffee> | 2021-10-19 23:31:30 +0900 |
|---|---|---|
| committer | rainy-me <github@yue.coffee> | 2021-10-19 23:31:30 +0900 |
| commit | adb3729b915ed682cadedc40641fd645e1bb4a8f (patch) | |
| tree | 47cc2c17798e9a7ded2d092e51662e2ad504b43c | |
| parent | 580a6c41eb4a4034e85aa89a673819e66a4113fc (diff) | |
| download | rust-adb3729b915ed682cadedc40641fd645e1bb4a8f.tar.gz rust-adb3729b915ed682cadedc40641fd645e1bb4a8f.zip | |
Fix: expand glob import to empty braces if the glob is unused
| -rw-r--r-- | crates/ide_assists/src/handlers/expand_glob_import.rs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/crates/ide_assists/src/handlers/expand_glob_import.rs b/crates/ide_assists/src/handlers/expand_glob_import.rs index e2931df3776..14bc35fea8e 100644 --- a/crates/ide_assists/src/handlers/expand_glob_import.rs +++ b/crates/ide_assists/src/handlers/expand_glob_import.rs @@ -72,7 +72,7 @@ pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext) -> Opti match use_tree.star_token() { Some(star) => { - let needs_braces = use_tree.path().is_some() && names_to_import.len() > 1; + let needs_braces = use_tree.path().is_some() && names_to_import.len() != 1; if needs_braces { ted::replace(star, expanded.syntax()) } else { @@ -295,6 +295,40 @@ fn qux(bar: Bar, baz: Baz) { } #[test] + fn expanding_glob_import_unused() { + check_assist( + expand_glob_import, + r" +mod foo { + pub struct Bar; + pub struct Baz; + pub struct Qux; + + pub fn f() {} +} + +use foo::*$0; + +fn qux() {} +", + r" +mod foo { + pub struct Bar; + pub struct Baz; + pub struct Qux; + + pub fn f() {} +} + +use foo::{}; + +fn qux() {} +", + ) + } + + + #[test] fn expanding_glob_import_with_existing_explicit_names() { check_assist( expand_glob_import, |
