File tree 2 files changed +32
-2
lines changed
src/tools/rust-analyzer/crates 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> {
663
663
name_ref : & ast:: NameRef ,
664
664
sink : & mut dyn FnMut ( EditionedFileId , FileReference ) -> bool ,
665
665
) -> 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
+
666
673
match NameRefClass :: classify ( self . sema , name_ref) {
667
674
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 ) ) =>
669
676
{
670
677
let FileRange { file_id, range } = self . sema . original_range ( name_ref. syntax ( ) ) ;
671
678
let reference = FileReference {
Original file line number Diff line number Diff line change @@ -60,7 +60,6 @@ pub(crate) fn find_all_refs(
60
60
move |def : Definition | {
61
61
let mut usages =
62
62
def. usages ( sema) . set_scope ( search_scope. as_ref ( ) ) . include_self_refs ( ) . all ( ) ;
63
-
64
63
if literal_search {
65
64
retain_adt_literal_usages ( & mut usages, def, sema) ;
66
65
}
@@ -817,6 +816,30 @@ impl<T> S<T> {
817
816
)
818
817
}
819
818
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
+
820
843
#[ test]
821
844
fn test_find_all_refs_two_modules ( ) {
822
845
check (
You can’t perform that action at this time.
0 commit comments