fix: hide destructure_struct_binding assist if no public fields
This commit is contained in:
parent
9f14343f9e
commit
2a4ba4295b
@ -107,6 +107,10 @@ fn collect_data(ident_pat: ast::IdentPat, ctx: &AssistContext<'_>) -> Option<Str
|
|||||||
let visible_fields =
|
let visible_fields =
|
||||||
fields.into_iter().filter(|field| field.is_visible_from(ctx.db(), module)).collect_vec();
|
fields.into_iter().filter(|field| field.is_visible_from(ctx.db(), module)).collect_vec();
|
||||||
|
|
||||||
|
if visible_fields.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
let has_private_members =
|
let has_private_members =
|
||||||
(is_non_exhaustive && is_foreign_crate) || visible_fields.len() < n_fields;
|
(is_non_exhaustive && is_foreign_crate) || visible_fields.len() < n_fields;
|
||||||
|
|
||||||
@ -413,7 +417,7 @@ fn main() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_struct() {
|
fn unit_struct() {
|
||||||
check_assist(
|
check_assist_not_applicable(
|
||||||
destructure_struct_binding,
|
destructure_struct_binding,
|
||||||
r#"
|
r#"
|
||||||
struct Foo;
|
struct Foo;
|
||||||
@ -422,13 +426,6 @@ fn main() {
|
|||||||
let $0foo = Foo;
|
let $0foo = Foo;
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
r#"
|
|
||||||
struct Foo;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let Foo = Foo;
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -739,4 +736,18 @@ fn main(foo: Foo) {
|
|||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn record_struct_no_public_members() {
|
||||||
|
check_assist_not_applicable(
|
||||||
|
destructure_struct_binding,
|
||||||
|
r#"
|
||||||
|
//- /lib.rs crate:dep
|
||||||
|
pub struct Foo { bar: i32, baz: i32 };
|
||||||
|
|
||||||
|
//- /main.rs crate:main deps:dep
|
||||||
|
fn main($0foo: dep::Foo) {}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -724,7 +724,10 @@ pub fn record_pat_field_list(
|
|||||||
) -> ast::RecordPatFieldList {
|
) -> ast::RecordPatFieldList {
|
||||||
let mut fields = fields.into_iter().join(", ");
|
let mut fields = fields.into_iter().join(", ");
|
||||||
if let Some(rest_pat) = rest_pat {
|
if let Some(rest_pat) = rest_pat {
|
||||||
format_to!(fields, ", {rest_pat}");
|
if !fields.is_empty() {
|
||||||
|
fields.push_str(", ");
|
||||||
|
}
|
||||||
|
format_to!(fields, "{rest_pat}");
|
||||||
}
|
}
|
||||||
ast_from_text(&format!("fn f(S {{ {fields} }}: ()))"))
|
ast_from_text(&format!("fn f(S {{ {fields} }}: ()))"))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user