Skip to content

Completing a function with return type () inserts a semicolon even when in an expression #20987

@kpreid

Description

@kpreid

rust-analyzer version: rust-analyzer version: 0.4.2671-standalone (4bf516e 2025-11-06)

rustc version: rustc 1.91.1 (ed61e7d7e 2025-11-07)

editor or extension: VSCode, RA extension version 0.4.2671

code snippet to reproduce:

fn called_function() {}

fn higher_order_function(_: impl FnOnce()) {}

fn main() {
    higher_order_function(ca /* cursor */);
}

Place the cursor as indicated and ask for completion. RA will insert:

higher_order_function(called_function(););

This is a syntax error. It should not insert a semicolon inside an expression. Ideally, it would not insert the parentheses either, but that is covered by #19635 and #3148, which is noted as being hard; it should be possible purely syntactically to decide not to insert this guaranteed syntax error. (Perhaps the parentheses could also be suppressed too on these grounds because it's not useful to nest function calls returning ()? But that might be too much magic.)

@rustbot label +A-completion

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions