about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-12-03 12:45:27 +0000
committerbors <bors@rust-lang.org>2022-12-03 12:45:27 +0000
commitd7be2fa1a6d8375465c026efd079f7c7f0678775 (patch)
tree26d367705f10081d5e6b05fb1792867ba0cebc08
parent398a71affb05aeeea1991044ec9ca1229e68f0f3 (diff)
parent30736b54c9fa4ae7dce93f71a7d363205dfd2842 (diff)
downloadrust-d7be2fa1a6d8375465c026efd079f7c7f0678775.tar.gz
rust-d7be2fa1a6d8375465c026efd079f7c7f0678775.zip
Auto merge of #13713 - allanbrondum:bug/trait-method-callers, r=Veykril
check reference is a NameRef (and not Name)

Fixes that implementing methods are shown in call hierarchy https://github.com/rust-lang/rust-analyzer/issues/13712
-rw-r--r--crates/ide/src/call_hierarchy.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/crates/ide/src/call_hierarchy.rs b/crates/ide/src/call_hierarchy.rs
index 5a8cda8fb3d..48bcd37b62c 100644
--- a/crates/ide/src/call_hierarchy.rs
+++ b/crates/ide/src/call_hierarchy.rs
@@ -57,7 +57,8 @@ pub(crate) fn incoming_calls(
         .flat_map(|func| func.usages(sema).all());
 
     for (_, references) in references {
-        let references = references.into_iter().map(|FileReference { name, .. }| name);
+        let references =
+            references.iter().filter_map(|FileReference { name, .. }| name.as_name_ref());
         for name in references {
             // This target is the containing function
             let nav = sema.ancestors_with_macros(name.syntax().clone()).find_map(|node| {
@@ -457,4 +458,28 @@ fn caller$0() {
             expect![[]],
         );
     }
+
+    #[test]
+    fn test_trait_method_call_hierarchy() {
+        check_hierarchy(
+            r#"
+trait T1 {
+    fn call$0ee();
+}
+
+struct S1;
+
+impl T1 for S1 {
+    fn callee() {}
+}
+
+fn caller() {
+    S1::callee();
+}
+"#,
+            expect![["callee Function FileId(0) 15..27 18..24"]],
+            expect![["caller Function FileId(0) 82..115 85..91 : [104..110]"]],
+            expect![[]],
+        );
+    }
 }