Skip to content

Commit afc1ae1

Browse files
committed
Auto merge of rust-lang#16016 - dfireBird:regression-fix-15879, r=lnicola
fix: Insert fn call parens only if the parens inserted around field name Fixes rust-lang#16014. Sorry I missed it in previous PR. I've added a test as level to prevent regressions again. Give any suggestions to improve the test if anything.
2 parents 986577f + 20c6f27 commit afc1ae1

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,31 @@ fn foo() {
427427
..Default::default()
428428
};
429429
}
430+
"#,
431+
);
432+
}
433+
434+
#[test]
435+
fn callable_field_struct_init() {
436+
check_edit(
437+
"field",
438+
r#"
439+
struct S {
440+
field: fn(),
441+
}
442+
443+
fn main() {
444+
S {fi$0
445+
}
446+
"#,
447+
r#"
448+
struct S {
449+
field: fn(),
450+
}
451+
452+
fn main() {
453+
S {field
454+
}
430455
"#,
431456
);
432457
}

crates/ide-completion/src/render.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ pub(crate) fn render_field(
169169
if let Some(receiver) = ctx.completion.sema.original_ast_node(receiver.clone()) {
170170
builder.insert(receiver.syntax().text_range().start(), "(".to_string());
171171
builder.insert(ctx.source_range().end(), ")".to_string());
172-
}
173-
}
174172

175-
let is_parens_needed =
176-
!matches!(dot_access.kind, DotAccessKind::Method { has_parens: true });
173+
let is_parens_needed =
174+
!matches!(dot_access.kind, DotAccessKind::Method { has_parens: true });
177175

178-
if is_parens_needed {
179-
builder.insert(ctx.source_range().end(), "()".to_string());
176+
if is_parens_needed {
177+
builder.insert(ctx.source_range().end(), "()".to_string());
178+
}
179+
}
180180
}
181181
}
182182

0 commit comments

Comments
 (0)