Skip to content

Commit b3ac58d

Browse files
committed
Add some more cov_marks
1 parent 8c9359b commit b3ac58d

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ pub(crate) fn complete_expr_path(
231231
cov_mark::hit!(functional_update);
232232
let missing_fields =
233233
ctx.sema.record_literal_missing_fields(record_expr);
234-
add_default_update(acc, ctx, ty, &missing_fields);
234+
if !missing_fields.is_empty() {
235+
add_default_update(acc, ctx, ty);
236+
}
235237
}
236238
};
237239
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ pub(crate) fn complete_record_expr_fields(
5959
}
6060
_ => {
6161
let missing_fields = ctx.sema.record_literal_missing_fields(record_expr);
62-
add_default_update(acc, ctx, ty, &missing_fields);
62+
63+
if !missing_fields.is_empty() {
64+
cov_mark::hit!(functional_update_field);
65+
add_default_update(acc, ctx, ty);
66+
}
6367
if dot_prefix {
6468
cov_mark::hit!(functional_update_one_dot);
6569
let mut item =
@@ -78,14 +82,14 @@ pub(crate) fn add_default_update(
7882
acc: &mut Completions,
7983
ctx: &CompletionContext<'_>,
8084
ty: Option<hir::TypeInfo>,
81-
missing_fields: &[(hir::Field, hir::Type)],
8285
) {
8386
let default_trait = ctx.famous_defs().core_default_Default();
84-
let impl_default_trait = default_trait
87+
let impls_default_trait = default_trait
8588
.zip(ty.as_ref())
8689
.map_or(false, |(default_trait, ty)| ty.original.impls_trait(ctx.db, default_trait, &[]));
87-
if impl_default_trait && !missing_fields.is_empty() {
90+
if impls_default_trait {
8891
// FIXME: This should make use of scope_def like completions so we get all the other goodies
92+
// that is we should handle this like actually completing the default function
8993
let completion_text = "..Default::default()";
9094
let mut item = CompletionItem::new(SymbolKind::Field, ctx.source_range(), completion_text);
9195
let completion_text =

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ fn main() {
156156

157157
#[test]
158158
fn functional_update_no_dot() {
159+
cov_mark::check!(functional_update_field);
159160
// FIXME: This should filter out all completions that do not have the type `Foo`
160161
check(
161162
r#"

0 commit comments

Comments
 (0)