about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-07-08 15:01:38 +0000
committerbors <bors@rust-lang.org>2023-07-08 15:01:38 +0000
commitfdb8aa2ea6aa4335f4b7251f0ac02c946833b095 (patch)
tree039d9a70e9c875ff255c4e6288334ef222fcc787 /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
parentd9c43b1cc7297fe29735155ee2f47f5fa8498610 (diff)
parent9200d27a263c243a3073d7b30ae7f677048e2117 (diff)
downloadrust-fdb8aa2ea6aa4335f4b7251f0ac02c946833b095.tar.gz
rust-fdb8aa2ea6aa4335f4b7251f0ac02c946833b095.zip
Auto merge of #15235 - omertuc:matchsemi, r=lowr
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