@@ -57,7 +57,8 @@ pub(crate) fn incoming_calls(
5757 . flat_map ( |func| func. usages ( sema) . all ( ) ) ;
5858
5959 for ( _, references) in references {
60- let references = references. into_iter ( ) . map ( |FileReference { name, .. } | name) ;
60+ let references =
61+ references. iter ( ) . filter_map ( |FileReference { name, .. } | name. as_name_ref ( ) ) ;
6162 for name in references {
6263 // This target is the containing function
6364 let nav = sema. ancestors_with_macros ( name. syntax ( ) . clone ( ) ) . find_map ( |node| {
@@ -457,4 +458,148 @@ fn caller$0() {
457458 expect ! [ [ ] ] ,
458459 ) ;
459460 }
461+
462+ #[ test]
463+ fn test_trait_method_call_hierarchy_on_def ( ) {
464+ check_hierarchy (
465+ r#"
466+ trait T1 {
467+ fn call$0ee();
468+ }
469+
470+ struct S1;
471+
472+ impl T1 for S1 {
473+ fn callee() {}
474+ }
475+
476+ fn caller() {
477+ S1::callee();
478+ }
479+ "# ,
480+ expect ! [ [ "callee Function FileId(0) 15..27 18..24" ] ] ,
481+ expect ! [ [ "caller Function FileId(0) 82..115 85..91 : [104..110]" ] ] ,
482+ expect ! [ [ ] ] ,
483+ ) ;
484+ }
485+
486+ #[ test]
487+ fn test_trait_method_call_hierarchy_on_impl ( ) {
488+ check_hierarchy (
489+ r#"
490+ trait T1 {
491+ fn callee();
492+ }
493+
494+ struct S1;
495+
496+ impl T1 for S1 {
497+ fn call$0ee() {}
498+ }
499+
500+ fn caller() {
501+ S1::callee();
502+ }
503+ "# ,
504+ expect ! [ [ "callee Function FileId(0) 64..78 67..73" ] ] ,
505+ expect ! [ [ "caller Function FileId(0) 82..115 85..91 : [104..110]" ] ] ,
506+ expect ! [ [ ] ] ,
507+ ) ;
508+ }
509+
510+ #[ test]
511+ fn test_trait_method_call_hierarchy_on_ref ( ) {
512+ check_hierarchy (
513+ r#"
514+ trait T1 {
515+ fn callee();
516+ }
517+
518+ struct S1;
519+
520+ impl T1 for S1 {
521+ fn callee() {}
522+ }
523+
524+ fn caller() {
525+ S1::call$0ee();
526+ }
527+ "# ,
528+ expect ! [ [ "callee Function FileId(0) 64..78 67..73" ] ] ,
529+ expect ! [ [ "caller Function FileId(0) 82..115 85..91 : [104..110]" ] ] ,
530+ expect ! [ [ ] ] ,
531+ ) ;
532+ }
533+
534+ #[ test]
535+ fn test_trait_method_generic_call_hierarchy_on_def ( ) {
536+ check_hierarchy (
537+ r#"
538+ trait T1 {
539+ fn call$0ee();
540+ }
541+
542+ struct S1;
543+
544+ impl T1 for S1 {
545+ fn callee() {}
546+ }
547+
548+ fn caller<T: T1>() {
549+ T::callee();
550+ }
551+ "# ,
552+ expect ! [ [ "callee Function FileId(0) 15..27 18..24" ] ] ,
553+ expect ! [ [ "caller Function FileId(0) 82..121 85..91 : [110..116]" ] ] ,
554+ expect ! [ [ ] ] ,
555+ ) ;
556+ }
557+
558+ #[ test]
559+ fn test_trait_method_generic_call_hierarchy_on_impl ( ) {
560+ check_hierarchy (
561+ r#"
562+ trait T1 {
563+ fn callee();
564+ }
565+
566+ struct S1;
567+
568+ impl T1 for S1 {
569+ fn call$0ee() {}
570+ }
571+
572+ fn caller<T: T1>() {
573+ T::callee();
574+ }
575+ "# ,
576+ expect ! [ [ "callee Function FileId(0) 64..78 67..73" ] ] ,
577+ expect ! [ [ "caller Function FileId(0) 82..121 85..91 : [110..116]" ] ] ,
578+ expect ! [ [ ] ] ,
579+ ) ;
580+ }
581+
582+ #[ test]
583+ fn test_trait_method_generic_call_hierarchy_on_ref ( ) {
584+ check_hierarchy (
585+ r#"
586+ trait T1 {
587+ fn callee();
588+ }
589+
590+ struct S1;
591+
592+ impl T1 for S1 {
593+ fn callee() {}
594+ }
595+
596+ fn caller<T: T1>() {
597+ T::call$0ee();
598+ }
599+ "# ,
600+ expect ! [ [ "callee Function FileId(0) 15..27 18..24" ] ] ,
601+ expect ! [ [ "caller Function FileId(0) 82..121 85..91 : [110..116]" ] ] ,
602+ expect ! [ [ ] ] ,
603+ ) ;
604+ }
460605}
0 commit comments