Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: find Self reference #15864

Merged
merged 1 commit into from Nov 10, 2023
Merged

fix: find Self reference #15864

merged 1 commit into from Nov 10, 2023

Conversation

Young-Flash
Copy link
Member

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

close #12693

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 10, 2023
@lnicola
Copy link
Member

lnicola commented Nov 10, 2023

@bors r+

@bors
Copy link
Collaborator

bors commented Nov 10, 2023

📌 Commit e0276dc has been approved by lnicola

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Nov 10, 2023

⌛ Testing commit e0276dc with merge 5afaf68...

@bors
Copy link
Collaborator

bors commented Nov 10, 2023

☀️ Test successful - checks-actions
Approved by: lnicola
Pushing 5afaf68 to master...

@bors bors merged commit 5afaf68 into rust-lang:master Nov 10, 2023
10 checks passed
@@ -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() =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this doesn't seem right to me, now we discard any other type that could appear as the self type in an impl. I'm curious as to why this equality fails in the given example in the first place. Sounds like we are losing some type info along the way somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious too. debug to that point and found the unequality. Is there anyother type for Self in an impl beside Adt?

Actually I don't quite understand the whole implementation of find refenence, it‘s complicated for me :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trait T {}
impl T for fn() {}

is an example. Don't think you can trigger references highlighting on that, but other code might require the Self resolution in search to work for that. I can take a look at that next week and see what's going on here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yes, the reference search is pretty messy looking and undocumented so I don't blame you for not being able to fully grasp the implementation there :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah the problem is that the self_ty here contains an {error} for the generic param where as the impl.self_ty() returns the struct with a var for the generic parameter, so the equality check fails. Hm

@Young-Flash Young-Flash deleted the find_self branch November 15, 2023 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't find reference when Self is used to construct a type that takes parameters
5 participants