From 920e99aacb917ad0608b0520661baae785aa0ae6 Mon Sep 17 00:00:00 2001 From: roife Date: Wed, 17 Jan 2024 13:50:50 +0800 Subject: [PATCH] test: add tests for variant kinds of SelfParam in inline_call --- .../ide-assists/src/handlers/inline_call.rs | 86 +++++++++++++++++-- 1 file changed, 81 insertions(+), 5 deletions(-) diff --git a/crates/ide-assists/src/handlers/inline_call.rs b/crates/ide-assists/src/handlers/inline_call.rs index 206802e93c..bb87b9b6c9 100644 --- a/crates/ide-assists/src/handlers/inline_call.rs +++ b/crates/ide-assists/src/handlers/inline_call.rs @@ -759,7 +759,7 @@ impl Foo { fn main() { let x = { - let ref this = Foo(3); + let this = &Foo(3); Foo(this.0 + 2) }; } @@ -795,7 +795,7 @@ impl Foo { fn main() { let x = { - let ref this = Foo(3); + let this = &Foo(3); Foo(this.0 + 2) }; } @@ -833,7 +833,7 @@ impl Foo { fn main() { let mut foo = Foo(3); { - let ref mut this = foo; + let this = &mut foo; this.0 = 0; }; } @@ -920,7 +920,7 @@ impl Foo { } fn bar(&self) { { - let ref this = self; + let this = &self; this; this; }; @@ -1595,7 +1595,7 @@ impl Enum { fn a() -> bool { { - let ref this = Enum::A; + let this = &Enum::A; this == &Enum::A || this == &Enum::B } } @@ -1657,6 +1657,82 @@ fn main() { a as A }; } +"#, + ) + } + + #[test] + fn method_by_reborrow() { + check_assist( + inline_call, + r#" +pub struct Foo(usize); + +impl Foo { + fn add1(&mut self) { + self.0 += 1; + } +} + +pub fn main() { + let f = &mut Foo(0); + f.add1$0(); +} +"#, + r#" +pub struct Foo(usize); + +impl Foo { + fn add1(&mut self) { + self.0 += 1; + } +} + +pub fn main() { + let f = &mut Foo(0); + { + let this = &mut *f; + this.0 += 1; + }; +} +"#, + ) + } + + #[test] + fn method_by_mut() { + check_assist( + inline_call, + r#" +pub struct Foo(usize); + +impl Foo { + fn add1(mut self) { + self.0 += 1; + } +} + +pub fn main() { + let mut f = Foo(0); + f.add1$0(); +} +"#, + r#" +pub struct Foo(usize); + +impl Foo { + fn add1(mut self) { + self.0 += 1; + } +} + +pub fn main() { + let mut f = Foo(0); + { + let mut this = f; + this.0 += 1; + }; +} "#, ) }