Skip to content

Commit 5afaf68

Browse files
committed
Auto merge of rust-lang#15864 - Young-Flash:find_self, r=lnicola
fix: find `Self` reference took a lot of time to debug to find the problem, here should compare the actual `Adt` type close rust-lang/rust-analyzer#12693
2 parents 7663319 + e0276dc commit 5afaf68

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

crates/ide-db/src/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ impl<'a> FindUsages<'a> {
584584
) -> bool {
585585
match NameRefClass::classify(self.sema, name_ref) {
586586
Some(NameRefClass::Definition(Definition::SelfType(impl_)))
587-
if impl_.self_ty(self.sema.db) == *self_ty =>
587+
if impl_.self_ty(self.sema.db).as_adt() == self_ty.as_adt() =>
588588
{
589589
let FileRange { file_id, range } = self.sema.original_range(name_ref.syntax());
590590
let reference = FileReference {

crates/ide/src/references.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,32 @@ enum Foo {
683683
);
684684
}
685685

686+
#[test]
687+
fn test_self() {
688+
check(
689+
r#"
690+
struct S$0<T> {
691+
t: PhantomData<T>,
692+
}
693+
694+
impl<T> S<T> {
695+
fn new() -> Self {
696+
Self {
697+
t: Default::default(),
698+
}
699+
}
700+
}
701+
"#,
702+
expect![[r#"
703+
S Struct FileId(0) 0..38 7..8
704+
705+
FileId(0) 48..49
706+
FileId(0) 71..75
707+
FileId(0) 86..90
708+
"#]],
709+
)
710+
}
711+
686712
#[test]
687713
fn test_find_all_refs_two_modules() {
688714
check(

0 commit comments

Comments
 (0)