mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Auto merge of #17813 - roife:fix-issue-17803, r=Veykril
fix: tyck for non-ADT types when searching refs for `Self` kw
See e0276dc5dd (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.
This commit is contained in:
commit
ee10731c31
2 changed files with 32 additions and 2 deletions
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
@ -817,6 +816,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(
|
||||
|
|
Loading…
Reference in a new issue