From fa0afb957671b75bcbcc8fd8ebfdbcaf088ee2bf Mon Sep 17 00:00:00 2001 From: Jeroen Vannevel Date: Wed, 5 Jan 2022 01:36:04 +0000 Subject: [PATCH] additional test for a reference local (on top of mutable reference local) --- .../src/handlers/extract_variable.rs | 70 ++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/crates/ide_assists/src/handlers/extract_variable.rs b/crates/ide_assists/src/handlers/extract_variable.rs index 9e11e38d3d6..b498d86fb46 100644 --- a/crates/ide_assists/src/handlers/extract_variable.rs +++ b/crates/ide_assists/src/handlers/extract_variable.rs @@ -1139,7 +1139,7 @@ fn foo(s: S) { } #[test] - fn test_extract_var_reference_local() { + fn test_extract_var_mutable_reference_local() { check_assist( extract_variable, r#" @@ -1198,7 +1198,73 @@ fn do_thing(&self) { fn foo() { let local = &mut S::new(); - let $0x = local.sub; + let $0x = &mut local.sub; + x.do_thing(); +}"#, + ); + } + + #[test] + fn test_extract_var_reference_local() { + check_assist( + extract_variable, + r#" +struct X; + +struct S { + sub: X +} + +impl S { + fn new() -> S { + S { + sub: X::new() + } + } +} + +impl X { + fn new() -> X { + X { } + } + fn do_thing(&self) { + + } +} + + +fn foo() { + let local = &S::new(); + $0local.sub$0.do_thing(); +}"#, + r#" +struct X; + +struct S { + sub: X +} + +impl S { + fn new() -> S { + S { + sub: X::new() + } + } +} + +impl X { + fn new() -> X { + X { } + } + fn do_thing(&self) { + + } +} + + +fn foo() { + let local = &S::new(); + let $0x = &local.sub; x.do_thing(); }"#, );