about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRyo Yoshida <low.ryoshida@gmail.com>2023-03-15 17:14:49 +0900
committerRyo Yoshida <low.ryoshida@gmail.com>2023-03-15 17:18:09 +0900
commit01bf0725b146b0cf71c21ec8452067f9bd3de1d8 (patch)
treec58422c04a09c473450dc674f20dc5d78c36286d
parentb4d7ea0692f2a72276704109ee13ffb3284f4863 (diff)
downloadrust-01bf0725b146b0cf71c21ec8452067f9bd3de1d8.tar.gz
rust-01bf0725b146b0cf71c21ec8452067f9bd3de1d8.zip
fix: don't replace `SyntaxToken` with `SyntaxNode`
-rw-r--r--crates/ide-assists/src/handlers/inline_call.rs40
1 files changed, 38 insertions, 2 deletions
diff --git a/crates/ide-assists/src/handlers/inline_call.rs b/crates/ide-assists/src/handlers/inline_call.rs
index 5ac18727c19..28d815e81b4 100644
--- a/crates/ide-assists/src/handlers/inline_call.rs
+++ b/crates/ide-assists/src/handlers/inline_call.rs
@@ -363,10 +363,10 @@ fn inline(
         .collect();
 
     if function.self_param(sema.db).is_some() {
-        let this = || make::name_ref("this").syntax().clone_for_update();
+        let this = || make::name_ref("this").syntax().clone_for_update().first_token().unwrap();
         if let Some(self_local) = params[0].2.as_local(sema.db) {
             usages_for_locals(self_local)
-                .flat_map(|FileReference { name, range, .. }| match name {
+                .filter_map(|FileReference { name, range, .. }| match name {
                     ast::NameLike::NameRef(_) => Some(body.syntax().covering_element(range)),
                     _ => None,
                 })
@@ -691,6 +691,42 @@ fn main() {
     }
 
     #[test]
+    fn generic_method_by_ref() {
+        check_assist(
+            inline_call,
+            r#"
+struct Foo(u32);
+
+impl Foo {
+    fn add<T>(&self, a: u32) -> Self {
+        Foo(self.0 + a)
+    }
+}
+
+fn main() {
+    let x = Foo(3).add$0::<usize>(2);
+}
+"#,
+            r#"
+struct Foo(u32);
+
+impl Foo {
+    fn add<T>(&self, a: u32) -> Self {
+        Foo(self.0 + a)
+    }
+}
+
+fn main() {
+    let x = {
+        let ref this = Foo(3);
+        Foo(this.0 + 2)
+    };
+}
+"#,
+        );
+    }
+
+    #[test]
     fn method_by_ref_mut() {
         check_assist(
             inline_call,