Skip to content

Commit

Permalink
Auto merge of #15864 - Young-Flash:find_self, r=lnicola
Browse files Browse the repository at this point in the history
fix: find `Self` reference

took a lot of time to debug to find the problem, here should compare the actual `Adt` type

close #12693
  • Loading branch information
bors committed Nov 10, 2023
2 parents 7663319 + e0276dc commit 5afaf68
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/ide-db/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ impl<'a> FindUsages<'a> {
) -> bool {
match NameRefClass::classify(self.sema, name_ref) {
Some(NameRefClass::Definition(Definition::SelfType(impl_)))
if impl_.self_ty(self.sema.db) == *self_ty =>
if impl_.self_ty(self.sema.db).as_adt() == self_ty.as_adt() =>
{
let FileRange { file_id, range } = self.sema.original_range(name_ref.syntax());
let reference = FileReference {
Expand Down
26 changes: 26 additions & 0 deletions crates/ide/src/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,32 @@ enum Foo {
);
}

#[test]
fn test_self() {
check(
r#"
struct S$0<T> {
t: PhantomData<T>,
}
impl<T> S<T> {
fn new() -> Self {
Self {
t: Default::default(),
}
}
}
"#,
expect![[r#"
S Struct FileId(0) 0..38 7..8
FileId(0) 48..49
FileId(0) 71..75
FileId(0) 86..90
"#]],
)
}

#[test]
fn test_find_all_refs_two_modules() {
check(
Expand Down

0 comments on commit 5afaf68

Please sign in to comment.