diff options
| author | bors <bors@rust-lang.org> | 2024-08-07 06:34:46 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-08-07 06:34:46 +0000 |
| commit | 0713a4704508c86ff223910a415829e08031ae64 (patch) | |
| tree | 32d4e21612b5fe2972d6a826d9cb0652fa463ca4 | |
| parent | 937ef11c55cb7f2d972d80a74c474c10fa97f610 (diff) | |
| parent | ac7c46651533765c4809f1bad6f5177f865624ef (diff) | |
| download | rust-0713a4704508c86ff223910a415829e08031ae64.tar.gz rust-0713a4704508c86ff223910a415829e08031ae64.zip | |
Auto merge of #17813 - roife:fix-issue-17803, r=Veykril
fix: tyck for non-ADT types when searching refs for `Self` kw
See https://github.com/rust-lang/rust-analyzer/pull/15864/files/e0276dc5ddc38c65240edb408522bb869f15afb4#r1389848845
For ADTs, to handle `{error}` in generic args, we should to convert them to ADT for comparisons; for others, we can directly compare the types.
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide-db/src/search.rs | 9 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/references.rs | 25 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/search.rs b/src/tools/rust-analyzer/crates/ide-db/src/search.rs index b6d17ce67ed..9e01a6d4408 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/search.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/search.rs @@ -663,9 +663,16 @@ impl<'a> FindUsages<'a> { name_ref: &ast::NameRef, sink: &mut dyn FnMut(EditionedFileId, FileReference) -> bool, ) -> bool { + // See https://github.com/rust-lang/rust-analyzer/pull/15864/files/e0276dc5ddc38c65240edb408522bb869f15afb4#r1389848845 + let ty_eq = |ty: hir::Type| match (ty.as_adt(), self_ty.as_adt()) { + (Some(ty), Some(self_ty)) => ty == self_ty, + (None, None) => ty == *self_ty, + _ => false, + }; + match NameRefClass::classify(self.sema, name_ref) { Some(NameRefClass::Definition(Definition::SelfType(impl_))) - if impl_.self_ty(self.sema.db).as_adt() == self_ty.as_adt() => + if ty_eq(impl_.self_ty(self.sema.db)) => { let FileRange { file_id, range } = self.sema.original_range(name_ref.syntax()); let reference = FileReference { diff --git a/src/tools/rust-analyzer/crates/ide/src/references.rs b/src/tools/rust-analyzer/crates/ide/src/references.rs index 46c2d47ee82..64b82b31c74 100644 --- a/src/tools/rust-analyzer/crates/ide/src/references.rs +++ b/src/tools/rust-analyzer/crates/ide/src/references.rs @@ -60,7 +60,6 @@ pub(crate) fn find_all_refs( move |def: Definition| { let mut usages = def.usages(sema).set_scope(search_scope.as_ref()).include_self_refs().all(); - if literal_search { retain_adt_literal_usages(&mut usages, def, sema); } @@ -818,6 +817,30 @@ impl<T> S<T> { } #[test] + fn test_self_inside_not_adt_impl() { + check( + r#" +pub trait TestTrait { + type Assoc; + fn stuff() -> Self; +} +impl TestTrait for () { + type Assoc$0 = u8; + fn stuff() -> Self { + let me: Self = (); + me + } +} +"#, + expect![[r#" + Assoc TypeAlias FileId(0) 92..108 97..102 + + FileId(0) 31..36 + "#]], + ) + } + + #[test] fn test_find_all_refs_two_modules() { check( r#" |
