Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
quaternic opened this issue Jun 14, 2022 · 2 comments · Fixed by #13454
Closed

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

quaternic opened this issue Jun 14, 2022 · 2 comments · Fixed by #13454
Labels
A-assists C-bug Category: bug

Comments

@quaternic
Copy link

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)

@flodiebold flodiebold added A-assists C-bug Category: bug labels Jun 14, 2022
@justinmmott
Copy link
Contributor

I'm going to try and work on this

justinmmott added a commit to justinmmott/rust-analyzer that referenced this issue Oct 21, 2022
@justinmmott
Copy link
Contributor

I think i got it!

@bors bors closed this as completed in df38770 Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants