Skip to content

fix: Fix extract variable on arg with comma#21936

Open
A4-Tacks wants to merge 1 commit intorust-lang:masterfrom
A4-Tacks:extract-arg-with-comma
Open

fix: Fix extract variable on arg with comma#21936
A4-Tacks wants to merge 1 commit intorust-lang:masterfrom
A4-Tacks:extract-arg-with-comma

Conversation

@A4-Tacks
Copy link
Copy Markdown
Member

@A4-Tacks A4-Tacks commented Apr 3, 2026

Example

fn main() {
    let x = 2;
    foo(
        x + x,
        $0x - x,$0
    )
}

Before this PR

fn main() {
    let x = 2;
    let $0var_name = x + x;
    foo(
        var_name,
        x - x,
    )
}

After this PR

fn main() {
    let x = 2;
    let $0var_name = x - x;
    foo(
        x + x,
        var_name,
    )
}

Example
---
```rust
fn main() {
    let x = 2;
    foo(
        x + x,
        $0x - x,$0
    )
}
```

**Before this PR**

```rust
fn main() {
    let x = 2;
    let $0var_name = x + x;
    foo(
        var_name,
        x - x,
    )
}
```

**After this PR**

```rust
fn main() {
    let x = 2;
    let $0var_name = x - x;
    foo(
        x + x,
        var_name,
    )
}
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 3, 2026
SyntaxKind::BLOCK_EXPR => {
ast::BlockExpr::cast(node).filter(|it| it.is_standalone()).map(ast::Expr::from)
}
SyntaxKind::ARG_LIST => ast::ArgList::cast(node)?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also pass when multiple args are selected. Also ARG_LIST isn't the only place for things like that (e.g. ARRAY_EXPR is too). IMO we should disable the assist when the comma is selected, but I also agree to enable it if it's confined to where only a single item is selected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants