mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2026-03-21 20:34:07 +00:00
Merge pull request #21354 from A4-Tacks/dedup-record-update
Fix duplicate record functional update
This commit is contained in:
@@ -70,8 +70,11 @@ pub(crate) fn complete_record_expr_fields(
|
||||
}
|
||||
_ => {
|
||||
let missing_fields = ctx.sema.record_literal_missing_fields(record_expr);
|
||||
let update_exists = record_expr
|
||||
.record_expr_field_list()
|
||||
.is_some_and(|list| list.dotdot_token().is_some());
|
||||
|
||||
if !missing_fields.is_empty() {
|
||||
if !missing_fields.is_empty() && !update_exists {
|
||||
cov_mark::hit!(functional_update_field);
|
||||
add_default_update(acc, ctx, ty);
|
||||
}
|
||||
|
||||
@@ -263,6 +263,29 @@ fn main() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn functional_update_exist_update() {
|
||||
check(
|
||||
r#"
|
||||
//- minicore:default
|
||||
struct Foo { foo1: u32, foo2: u32 }
|
||||
impl Default for Foo {
|
||||
fn default() -> Self { loop {} }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let thing = 1;
|
||||
let foo = Foo { foo1: 0, foo2: 0 };
|
||||
let foo2 = Foo { thing, $0 ..Default::default() }
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
fd foo1 u32
|
||||
fd foo2 u32
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_union_literal() {
|
||||
check(
|
||||
|
||||
Reference in New Issue
Block a user