]> git.lizzy.rs Git - rust.git/commitdiff
Record assoc item resolution
authorFlorian Diebold <flodiebold@gmail.com>
Thu, 31 Oct 2019 14:13:52 +0000 (15:13 +0100)
committerFlorian Diebold <flodiebold@gmail.com>
Fri, 1 Nov 2019 18:57:08 +0000 (19:57 +0100)
crates/ra_hir/src/ty/infer/path.rs
crates/ra_ide_api/src/goto_definition.rs

index 0cde77265e64e66ad7fb3840e0ffef7c2c438ecc..c58564b22fe020dba39837694c27e7c4fc4e99df 100644 (file)
@@ -230,7 +230,7 @@ fn find_trait_assoc_candidate(
         &mut self,
         ty: Ty,
         name: &Name,
-        _id: ExprOrPatId,
+        id: ExprOrPatId,
     ) -> Option<(ValueNs, Option<Substs>)> {
         let krate = self.resolver.krate()?;
 
@@ -276,6 +276,8 @@ fn find_trait_assoc_candidate(
                             trait_: t,
                             substs: trait_substs,
                         }));
+
+                        self.write_assoc_resolution(id, *item);
                         return Some((ValueNs::Function(f), Some(substs)));
                     }
                 }
index 323faab33587442b4f276b0d433dfd424c9837ef..c1ce54bea394986b5570d5032f22425f4053e67c 100644 (file)
@@ -390,6 +390,61 @@ fn bar() -> Foo {
             "spam RECORD_FIELD_DEF FileId(1) [17; 26) [17; 21)",
         );
     }
+
+    #[test]
+    fn goto_definition_works_for_ufcs_inherent_methods() {
+        check_goto(
+            "
+            //- /lib.rs
+            struct Foo;
+            impl Foo {
+                fn frobnicate() {  }
+            }
+
+            fn bar(foo: &Foo) {
+                Foo::frobnicate<|>();
+            }
+            ",
+            "frobnicate FN_DEF FileId(1) [27; 47) [30; 40)",
+        );
+    }
+
+    #[test]
+    fn goto_definition_works_for_ufcs_trait_methods_through_traits() {
+        check_goto(
+            "
+            //- /lib.rs
+            trait Foo {
+                fn frobnicate();
+            }
+
+            fn bar() {
+                Foo::frobnicate<|>();
+            }
+            ",
+            "frobnicate FN_DEF FileId(1) [16; 32) [19; 29)",
+        );
+    }
+
+    #[test]
+    fn goto_definition_works_for_ufcs_trait_methods_through_self() {
+        check_goto(
+            "
+            //- /lib.rs
+            struct Foo;
+            trait Trait {
+                fn frobnicate();
+            }
+            impl Trait for Foo {}
+
+            fn bar() {
+                Foo::frobnicate<|>();
+            }
+            ",
+            "frobnicate FN_DEF FileId(1) [30; 46) [33; 43)",
+        );
+    }
+
     #[test]
     fn goto_definition_on_self() {
         check_goto(