File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
src/tools/rust-analyzer/crates Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -663,9 +663,16 @@ impl<'a> FindUsages<'a> {
663663 name_ref : & ast:: NameRef ,
664664 sink : & mut dyn FnMut ( EditionedFileId , FileReference ) -> bool ,
665665 ) -> bool {
666+ // See https://github.com/rust-lang/rust-analyzer/pull/15864/files/e0276dc5ddc38c65240edb408522bb869f15afb4#r1389848845
667+ let ty_eq = |ty : hir:: Type | match ( ty. as_adt ( ) , self_ty. as_adt ( ) ) {
668+ ( Some ( ty) , Some ( self_ty) ) => ty == self_ty,
669+ ( None , None ) => ty == * self_ty,
670+ _ => false ,
671+ } ;
672+
666673 match NameRefClass :: classify ( self . sema , name_ref) {
667674 Some ( NameRefClass :: Definition ( Definition :: SelfType ( impl_) ) )
668- if impl_. self_ty ( self . sema . db ) . as_adt ( ) == self_ty . as_adt ( ) =>
675+ if ty_eq ( impl_. self_ty ( self . sema . db ) ) =>
669676 {
670677 let FileRange { file_id, range } = self . sema . original_range ( name_ref. syntax ( ) ) ;
671678 let reference = FileReference {
Original file line number Diff line number Diff line change @@ -60,7 +60,6 @@ pub(crate) fn find_all_refs(
6060 move |def : Definition | {
6161 let mut usages =
6262 def. usages ( sema) . set_scope ( search_scope. as_ref ( ) ) . include_self_refs ( ) . all ( ) ;
63-
6463 if literal_search {
6564 retain_adt_literal_usages ( & mut usages, def, sema) ;
6665 }
@@ -817,6 +816,30 @@ impl<T> S<T> {
817816 )
818817 }
819818
819+ #[ test]
820+ fn test_self_inside_not_adt_impl ( ) {
821+ check (
822+ r#"
823+ pub trait TestTrait {
824+ type Assoc;
825+ fn stuff() -> Self;
826+ }
827+ impl TestTrait for () {
828+ type Assoc$0 = u8;
829+ fn stuff() -> Self {
830+ let me: Self = ();
831+ me
832+ }
833+ }
834+ "# ,
835+ expect ! [ [ r#"
836+ Assoc TypeAlias FileId(0) 92..108 97..102
837+
838+ FileId(0) 31..36
839+ "# ] ] ,
840+ )
841+ }
842+
820843 #[ test]
821844 fn test_find_all_refs_two_modules ( ) {
822845 check (
You can’t perform that action at this time.
0 commit comments