about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
diff options
context:
space:
mode:
authorOmer Tuchfeld <omer@tuchfeld.dev>2023-07-08 13:48:04 +0200
committerOmer Tuchfeld <omer@tuchfeld.dev>2023-07-08 15:41:24 +0200
commit9200d27a263c243a3073d7b30ae7f677048e2117 (patch)
treed6c58e7059ea4b4da89f31225dcd33e7ad9d1e0e /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
parentdb0add1ce92af58a92b2a80990044ae21713ae29 (diff)
downloadrust-9200d27a263c243a3073d7b30ae7f677048e2117.tar.gz
rust-9200d27a263c243a3073d7b30ae7f677048e2117.zip
Stop inserting semicolon when extracting match arm
# Overview

Extracting a match arm value that has type unit into a function, when a
comma already follows the match arm value, results in an invalid (syntax
error) semicolon added between the newly generated function's generated
call and the comma.

# Example

Running this extraction

```rust
fn main() {
    match () {
        _ => $0()$0,
    };
}
```

would lead to

```rust
fn main() {
    match () {
        _ => fun_name();,
    };
}

fn fun_name() {
}
```

# Issue / Fix details

This happens because when there is no comma, rust-analyzer would simply
add the comma and wouldn't even try to evaluate whether it needs to add
a semicolon. But when the comma is there, it proceeds to evaluate
whether it needs to add a semicolon and it looks like the evaluation
logic erroneously ignores the possibility that we're in a match arm.
IIUC it never makes sense to add a semicolon when we're extracting from
a match arm value, so I've adjusted the logic to always decide against
adding a semicolon when we're in a match arm
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions