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
This commit is contained in:
bors 2022-12-03 12:45:27 +00:00
commit d7be2fa1a6

View file

@ -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![[]],
);
}
}