mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-16 09:48:10 +00:00
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 <github@yue.coffee>
This commit is contained in:
commit
5051717856
1 changed files with 34 additions and 1 deletions
|
@ -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 {
|
||||
|
@ -294,6 +294,39 @@ 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(
|
||||
|
|
Loading…
Reference in a new issue