Skip to content

Variables in an expression of an macro call is not converted as param on Extract Function assist #21031

@dfireBird

Description

@dfireBird

rust-analyzer version: rust-analyzer version: 0.0.0 (2efc800 2025-11-11) [/home/user/Projects/rust-analyzer/target/debug/rust-analyzer]

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

editor or extension: VSCode (but generally it doesn't matter)

relevant settings: no settings change except for imports and server path change

repository link (if public, optional): N/A

code snippet to reproduce:

fn foo() {
    let s = 123;
    $0print!("{}", s == 123);$0
}

When extracting function of an macro call (especially the format, print one) that has an variable used inside as expression, the extracted function does not have the used variable as an parameter of the function. When assist is invoked on above code, it will create function like this:

fn fun_name() {
    print!("{}", s == 123);
}

instead of

fn fun_name(s: i32) {
    print!("{}", s == 123);
}

I can also reproduced this on println and format and I assume similar macros have this issue as well.

@rustbot label +A-assists +A-macro

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