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 method resolution for inherent array impls #10017

Closed
wants to merge 2 commits into from
Closed

Fix method resolution for inherent array impls #10017

wants to merge 2 commits into from

Conversation

yotamofek
Copy link
Contributor

I've been trying to solve #9992 on my own, even though I really don't understand the internals of rust-analyzer enough, but I hacked up something that seems to solve the issue!

As far as I can tell, the problem with resolving methods from std's (pretty recently added) impls on array, was caused by two separate issues, which are fixed by the two separate commits in this PR:

  • the inherent impls on TyKind::Array were not registered for TyFingerprint::Array
  • the inherent impls, when registered by rust-analyzer, are registered for [T; {unknown}], while the receiver has a concrete len. I added the array Ty with an unknown const len as one of the targets for auto-derefing, which makes is_valid_candidate correctly return true in these cases.

So just to re-iterate, I have no idea if these changes actually make sense, but I thought opening a PR is worth a shot. :) And if not, I would love to get some pointers and keep working on this.

Thanks!

@yotamofek yotamofek closed this Aug 24, 2021
@yotamofek yotamofek deleted the fix-array-method-resolution branch August 24, 2021 19:29
@yotamofek yotamofek restored the fix-array-method-resolution branch August 24, 2021 19:29
@flodiebold
Copy link
Member

The first change is correct. Changing how arrays are derefed is not the right thing to do though. To get this working properly, we'll probably need to implement some more of const generics (in particular, lowering them during type lowering), which is a bigger refactoring. I would actually expect it to somewhat work though, since we treat unknown consts as 'equal' to other consts.

@yotamofek
Copy link
Contributor Author

@flodiebold thanks for taking a look.
It works, but seems to break the (I guess) somewhat fragile workaround for the #[rustc_skip_array_during_method_dispatch] attribute, which is why I closed this PR. 😅

bors bot added a commit that referenced this pull request Sep 8, 2021
10180: Fix resolution for inherent array methods r=flodiebold a=yotamofek

My second attempt at fixing #9992 , previous attempt was here: #10017 , but the logic was broken.

I know that this is not an ideal solution.... that would require, IIUC, a pretty big overhaul of the const generics handling in `rust-analyzer`. But, given that some of the array methods were/are being stabilized (e.g. rust-lang/rust#87174 ), I think it'll be very beneficial to `rust-analyzer` users to have some preliminary support for them. (I know it's something I've been running into quite a lot lately :) )

As far as my limited understanding of this project's architecture goes, I think this isn't the worst hack in the world, and shouldn't be too much of a hassle to undo if/when const generics become better supported. If the maintainers deem this approach viable, I'll want to add some comments, emphasizing the purpose of this code, and that it should be removed at some point in the future.

Co-authored-by: Yotam Ofek <yotam.ofek@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants