make assist not applicable if there is no missing field

This commit is contained in:
dfireBird 2024-02-26 21:21:56 +05:30
parent 6f4354f6ad
commit 2ea70662f0
No known key found for this signature in database
GPG key ID: 26D522CA5FC2B93D

View file

@ -36,6 +36,11 @@ pub(crate) fn fill_record_pattern_fields(acc: &mut Assists, ctx: &AssistContext<
let missing_fields = ctx.sema.record_pattern_missing_fields(&record_pat);
if missing_fields.is_empty() {
cov_mark::hit!(no_missing_fields);
return None;
}
let old_field_list = record_pat.record_pat_field_list()?;
let new_field_list = make::record_pat_field_list(old_field_list.fields()).clone_for_update();
for (f, _) in missing_fields.iter() {
@ -230,6 +235,41 @@ fn bar(foo: Foo) {
Foo::$0B{..} => true,
};
}
"#,
);
}
#[test]
fn not_applicable_when_no_missing_fields() {
// This is still possible even though it's meaningless
cov_mark::check!(no_missing_fields);
check_assist_not_applicable(
fill_record_pattern_fields,
r#"
enum Foo {
A(X),
B{y: Y, z: Z}
}
fn bar(foo: Foo) {
match foo {
Foo::A(_) => false,
Foo::B{y, z, ..$0} => true,
};
}
"#,
);
check_assist_not_applicable(
fill_record_pattern_fields,
r#"
struct Bar {
y: Y,
z: Z,
}
fn foo(bar: Bar) {
let Bar { y, z, ..$0 } = bar;
}
"#,
);
}