Skip to content

Commit 57384b1

Browse files
committed
Fix duplicate record functional update
Example --- ```rust fn main() { let thing = 1; let foo = Foo { foo1: 0, foo2: 0 }; let foo2 = Foo { thing, $0 ..Default::default() } } ``` **Before this PR** ```text fd ..Default::default() fd foo1 u32 fd foo2 u32 ``` **After this PR** ```text fd foo1 u32 fd foo2 u32 ```
1 parent bbd40f8 commit 57384b1

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

crates/ide-completion/src/completions/record.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ pub(crate) fn complete_record_expr_fields(
7070
}
7171
_ => {
7272
let missing_fields = ctx.sema.record_literal_missing_fields(record_expr);
73+
let update_exists = record_expr
74+
.record_expr_field_list()
75+
.is_some_and(|list| list.dotdot_token().is_some());
7376

74-
if !missing_fields.is_empty() {
77+
if !missing_fields.is_empty() && !update_exists {
7578
cov_mark::hit!(functional_update_field);
7679
add_default_update(acc, ctx, ty);
7780
}

crates/ide-completion/src/tests/record.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,29 @@ fn main() {
263263
);
264264
}
265265

266+
#[test]
267+
fn functional_update_exist_update() {
268+
check(
269+
r#"
270+
//- minicore:default
271+
struct Foo { foo1: u32, foo2: u32 }
272+
impl Default for Foo {
273+
fn default() -> Self { loop {} }
274+
}
275+
276+
fn main() {
277+
let thing = 1;
278+
let foo = Foo { foo1: 0, foo2: 0 };
279+
let foo2 = Foo { thing, $0 ..Default::default() }
280+
}
281+
"#,
282+
expect![[r#"
283+
fd foo1 u32
284+
fd foo2 u32
285+
"#]],
286+
);
287+
}
288+
266289
#[test]
267290
fn empty_union_literal() {
268291
check(

0 commit comments

Comments
 (0)