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

Properly pass variables into extracted function #2188

Closed
Tracked by #2183
Undin opened this issue Jan 10, 2018 · 1 comment
Closed
Tracked by #2183

Properly pass variables into extracted function #2188

Undin opened this issue Jan 10, 2018 · 1 comment
Labels
E-medium Issue required decent knowledge about platform and project codebase help wanted improvement subsystem::code insight General label for issues related to code understanding: highlighting, completion, annotation, etc. subsystem::refactoring Issues related to refactorings

Comments

@Undin
Copy link
Member

Undin commented Jan 10, 2018

We always pass variables by value and it can lead to incorrect code.
We should correctly determine how to pass variable: by value or by reference.

fn foo() {
    let vec = vec![1, 2, 3];
    <selection>println!("{}", vec.len());</selection>
    println!("{}", vec[0]);
}

Expected:

fn foo() {
    let vec = vec![1, 2, 3];
    bar(&vec);
    println!("{}", vec[0]);
}

fn bar(vec: &Vec<i32>) {
    println!("{}", vec.len());
}

Actual:

fn foo() {
    let vec = vec![1, 2, 3];
    bar(vec);
    println!("{}", vec[0]); // error[E0382]: use of moved value: `vec`
}

fn bar(vec: Vec<i32>) {
    println!("{}", vec.len()); 
}
@Undin Undin added help wanted E-medium Issue required decent knowledge about platform and project codebase subsystem::code insight General label for issues related to code understanding: highlighting, completion, annotation, etc. improvement labels Jan 10, 2018
@Undin Undin mentioned this issue Jan 10, 2018
20 tasks
@t-kameyama
Copy link
Contributor

I will work on this

bors bot added a commit that referenced this issue Apr 8, 2018
2318: TYPE: Properly pass variables into extracted function r=Undin a=t-kameyama

Fixes #2188

Co-authored-by: Toshiaki Kameyama <kmymtsak@gmail.com>
@bors bors bot closed this as completed in #2318 Apr 8, 2018
@artemmukhin artemmukhin added the subsystem::refactoring Issues related to refactorings label Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-medium Issue required decent knowledge about platform and project codebase help wanted improvement subsystem::code insight General label for issues related to code understanding: highlighting, completion, annotation, etc. subsystem::refactoring Issues related to refactorings
Projects
None yet
Development

No branches or pull requests

3 participants