Skip to content

Inline function assist gets confused with a local shadowing the caller's argument #12536

Closed
@quaternic

Description

@quaternic
fn test(foo: u32) -> u32 {
    let a = 10;
    foo * 6
}

fn main() {
    let a = 7;
    let res = test(a);
    assert!(res == 42);
}

Inlining results in:

let a = 7;
let res = {
    let a = 10;
    a * 6  // <-- incorrectly refers to the local
};
assert!(res == 42);

which fails the assert. A correct inlining would be:

let a = 7;
let res = {
    let foo = a;
    let a = 10;
    foo * 6
};
assert!(res == 42);

rust-analyzer version: 0.0.0 (366bd72 2022-06-12)

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