Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2ea7066

Browse files
committed
make assist not applicable if there is no missing field
1 parent 6f4354f commit 2ea7066

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

crates/ide-assists/src/handlers/fill_record_pattern_fields.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ pub(crate) fn fill_record_pattern_fields(acc: &mut Assists, ctx: &AssistContext<
3636

3737
let missing_fields = ctx.sema.record_pattern_missing_fields(&record_pat);
3838

39+
if missing_fields.is_empty() {
40+
cov_mark::hit!(no_missing_fields);
41+
return None;
42+
}
43+
3944
let old_field_list = record_pat.record_pat_field_list()?;
4045
let new_field_list = make::record_pat_field_list(old_field_list.fields()).clone_for_update();
4146
for (f, _) in missing_fields.iter() {
@@ -230,6 +235,41 @@ fn bar(foo: Foo) {
230235
Foo::$0B{..} => true,
231236
};
232237
}
238+
"#,
239+
);
240+
}
241+
242+
#[test]
243+
fn not_applicable_when_no_missing_fields() {
244+
// This is still possible even though it's meaningless
245+
cov_mark::check!(no_missing_fields);
246+
check_assist_not_applicable(
247+
fill_record_pattern_fields,
248+
r#"
249+
enum Foo {
250+
A(X),
251+
B{y: Y, z: Z}
252+
}
253+
254+
fn bar(foo: Foo) {
255+
match foo {
256+
Foo::A(_) => false,
257+
Foo::B{y, z, ..$0} => true,
258+
};
259+
}
260+
"#,
261+
);
262+
check_assist_not_applicable(
263+
fill_record_pattern_fields,
264+
r#"
265+
struct Bar {
266+
y: Y,
267+
z: Z,
268+
}
269+
270+
fn foo(bar: Bar) {
271+
let Bar { y, z, ..$0 } = bar;
272+
}
233273
"#,
234274
);
235275
}

0 commit comments

Comments
 (0)