rust-refactor icon indicating copy to clipboard operation
rust-refactor copied to clipboard

rename local variables

Open nrc opened this issue 10 years ago • 4 comments

nrc avatar Jun 19 '15 01:06 nrc

Identifies conflicts with other variables, function-local and non-function local types, but only non-function local functions. Function-local functions can cause sub-block conflicts.

fn main() {
    let a = 2;
    fn foo() {}
    foo();
    let _ = 3 + a; // type conflict
}

Doesn't conflict with variables declared in a nested scope.

GSam avatar Jul 16 '15 14:07 GSam

Also functions for tuple let bindings, but haven't tested other destructuring assignments. (Obvious case where this doesn't work is the iterator variable for a (macro) for loop.)

GSam avatar Jul 16 '15 14:07 GSam

Conflicts with struct destructures are fine when given a name, but not when they are inferred. FINE:

let Point{x:x, y:y} = Point{x:1, y:2}

NOT FINE:

let Point{x, y} = Point{x:1, y:2}
to 
let Point{foo, y} = Point{x:1, y:2}

I believe this check requires going to type checking, which makes it an interesting corner case.

GSam avatar Aug 02 '15 10:08 GSam

Oh, that is a lovely edge case! Small note that there is no inference here - we just match the name of the field with the name of the introduced local variable. This will also affect field renaming - if you rename the *field x to foo, then you'll also need to either rename the local variable x to foo too (which could also clash with other local vars) or you'll need to change Point { x, ... to Point { x: foo, ....

Perhaps option 2 plus a warning is the best solution?

Anyway, make sure this goes into your report.

nrc avatar Aug 02 '15 18:08 nrc