diff options
| author | bors <bors@rust-lang.org> | 2023-12-05 14:53:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-12-05 14:53:29 +0000 |
| commit | afc1ae1aa30f55395180ad770cc99c8fb1052338 (patch) | |
| tree | c7f82ef685db65a04a67f6b1b79c3077e46c522a | |
| parent | 986577faaa5d0ce773e83b7bf575d2bfdbcf24ad (diff) | |
| parent | 20c6f270240bdb3b34d4f1399ccc29823343deed (diff) | |
| download | rust-afc1ae1aa30f55395180ad770cc99c8fb1052338.tar.gz rust-afc1ae1aa30f55395180ad770cc99c8fb1052338.zip | |
Auto merge of #16016 - dfireBird:regression-fix-15879, r=lnicola
fix: Insert fn call parens only if the parens inserted around field name Fixes #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.
| -rw-r--r-- | crates/ide-completion/src/completions/record.rs | 25 | ||||
| -rw-r--r-- | crates/ide-completion/src/render.rs | 12 |
2 files changed, 31 insertions, 6 deletions
diff --git a/crates/ide-completion/src/completions/record.rs b/crates/ide-completion/src/completions/record.rs index 945c3945bfa..46213deb0af 100644 --- a/crates/ide-completion/src/completions/record.rs +++ b/crates/ide-completion/src/completions/record.rs @@ -430,4 +430,29 @@ fn foo() { "#, ); } + + #[test] + fn callable_field_struct_init() { + check_edit( + "field", + r#" +struct S { + field: fn(), +} + +fn main() { + S {fi$0 +} +"#, + r#" +struct S { + field: fn(), +} + +fn main() { + S {field +} +"#, + ); + } } diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs index 048730c078d..830d7cabab5 100644 --- a/crates/ide-completion/src/render.rs +++ b/crates/ide-completion/src/render.rs @@ -169,14 +169,14 @@ pub(crate) fn render_field( if let Some(receiver) = ctx.completion.sema.original_ast_node(receiver.clone()) { builder.insert(receiver.syntax().text_range().start(), "(".to_string()); builder.insert(ctx.source_range().end(), ")".to_string()); - } - } - let is_parens_needed = - !matches!(dot_access.kind, DotAccessKind::Method { has_parens: true }); + let is_parens_needed = + !matches!(dot_access.kind, DotAccessKind::Method { has_parens: true }); - if is_parens_needed { - builder.insert(ctx.source_range().end(), "()".to_string()); + if is_parens_needed { + builder.insert(ctx.source_range().end(), "()".to_string()); + } + } } } |
