@@ -878,7 +878,7 @@ impl FunctionBody {
878
878
// We can move the value into the function call if it's not used after the call,
879
879
// if the var is not used but defined outside a loop we are extracting from we can't move it either
880
880
// as the function will reuse it in the next iteration.
881
- let move_local = !has_usages && defined_outside_parent_loop;
881
+ let move_local = ( !has_usages && defined_outside_parent_loop) || ty . is_reference ( ) ;
882
882
Param { var, ty, move_local, requires_mut, is_copy }
883
883
} )
884
884
. collect ( )
@@ -4332,6 +4332,43 @@ fn foo() {
4332
4332
fn $0fun_name(a: _) -> _ {
4333
4333
a
4334
4334
}
4335
+ "# ,
4336
+ ) ;
4337
+ }
4338
+
4339
+ #[ test]
4340
+ fn test_jeroen ( ) {
4341
+ check_assist (
4342
+ extract_function,
4343
+ r#"
4344
+ pub struct Foo {
4345
+ field: u32,
4346
+ }
4347
+
4348
+ pub fn testfn(arg: &mut Foo) {
4349
+ $0arg.field = 8; // write access
4350
+ println!("{}", arg.field); // read access$0
4351
+ // Simulating access after the extracted portion
4352
+ arg.field = 16; // write access
4353
+ println!("{}", arg.field); // read access
4354
+ }
4355
+ "# ,
4356
+ r#"
4357
+ pub struct Foo {
4358
+ field: u32,
4359
+ }
4360
+
4361
+ pub fn testfn(arg: &mut Foo) {
4362
+ fun_name(arg); // read access
4363
+ // Simulating access after the extracted portion
4364
+ arg.field = 16; // write access
4365
+ println!("{}", arg.field); // read access
4366
+ }
4367
+
4368
+ fn $0fun_name(arg: &mut Foo) {
4369
+ arg.field = 8;
4370
+ println!("{}", arg.field);
4371
+ }
4335
4372
"# ,
4336
4373
) ;
4337
4374
}
0 commit comments