-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Go to definition on 5.to_string() should go to the implemention #4558
Comments
This is currently blocked on chalk -- at the moment, it by design doesn't expose the specific trait impl that matches. |
When you say "by design", do you mean that Chalk has announced the intention to never implement such a feature, or merely that such a feature would be desired but is currently not on the roadmap? If the latter, is there a corresponding issue on the Chalk repo? |
It's an open design problem; as I understood it, @nikomatsakis agreed we need some way to do this, but alluded to having some particular ideas how it should be done (or how it should not be done). You'd have to ask him for details. I don't think there's an issue in the Chalk repo yet, but I may be wrong. |
From what I recall, the idea is to keep the core chalk's interface pure, so that you can only ask "does this type implements this traits", and then leave the "trail of evidence" (which you need to actually codegen) to some extra API. |
Hmm, my plan was to treat this as roughly a kind of associated type normalization. In particular, every method in an impl has a unique type, so the idea was that you would effectively be "normalizing" |
Ah yeah, that's kind of what I imagined since you mentioned normalization. We wouldn't really need one associated item per method though, would we? Except maybe to handle default methods, but that could also be done in a simpler way... |
@flodiebold right, one per method -- basically each thing in the impl, whether it be a |
Is anyone working on this? And if not, anyone willing to provide me a bit of guidance in making something happen here? I'm practically useless without go to definition in my text editor :( |
I see this ticket received the label Unactionable. I understand it is blocked by Chalk and it is waiting for the Chalk to complete some work. Can we have a reference to a ticket for Chalk here? as @bstrie requested initially. |
Actually, I think this is actionable without any extensions to Chalk (using Niko's plan), but I would like to get the current transition of hir_ty to Chalk's IR done first. |
@nikomatsakis One thing though. How would we handle "go to impl" for associated types? I.e. if we have |
@flodiebold that's a good point, my plan can't really model that scenario. I suppose we could add something into the logic just for this, basically a kind of projection where you are not finding the value but the impl -- i.e., instead of |
@flodiebold quick question: can we just hack around this on IDE side? Seems like we can try finding direct impl, and, if that fails, try finding the single blanket impl? |
Hmm I don't think it's always that easy, consider something like this: impl<T> Trait for Foo<T> where T: Debug {}
impl<T> Trait for Foo<Baz<T>> {} And we can already implement it using Chalk, except for associated types. |
Yeah, I mean we need chalk support to cover 100% of cases, but it seems that 80% solution is hackable? Most of the impls are just impl Trait for SpecificType. |
I concur, when I was reading RA code earlier, I was looking at some stuff like TryToNav and it would have been a nice time save to have this. If you folks want, I can have a crack at implementing the 80% solution this weekend or next. |
@lf- go for it! |
I don't really see the point of doing the 80% solution when we can do the 100% solution for methods. |
Ah, sorry, I misunderstood you. If we already can implement this with chalk, then, judging by the amount of upvotes on this issue, we probably should :) |
Hmm so |
I'd like to work with someone to make this work, as an excuse to learn more about rust-analyzer |
Also to prove out the impl strategy I have in mind |
I could help, but maybe @lf- is interested as well. |
@lf- what do you think? We could setup a time to sketch out how it might work. Ideal for me would be to collaborate with someone who can do most of the coding, just because my time is limited. |
Just to throw in some mentoring instructions for all interested parties:
|
Inside Regarding the Chalk integration, the starting point would be the |
That sounds fine with me, do you have any thoughts on times? I'm in PST and more or less can accommodate any time in the day or evening except next Monday. We can connect on Zulip to further discuss, I'm @/jade. I'm not an expert in the insides of the IDE, although I've touched most of the mentioned files before. I want to learn about chalk :) |
I've had a start at this.
This is something like a pair of So if I understand it correctly, we are generating the data (hopefully) correctly, but it's being discarded in here: I guess this is when I have to figure out what I want/need to get out of chalk 🙂
Got it. |
I think what @matklad means is to store a
Not sure what you mean by that, but currently we don't know the correct impl at all. Implementing that logic is what we need to use Chalk for. What we're discarding there is the self type, but going from the self type to the correct impl isn't completely trivial. |
You might not have the item on the impl:
I am not sure what exactly do we want to store, but the API should make it clear that we have two things here. It seems that we need something like |
Also in the case of built-in impls, like the impl of |
As you might see, there have some cross references to this issue. I've been working on the Chalk side since July and it's now more or less review ready. I am going to stick it onto rust-analyzer over the coming weeks. This feature is a lot of work 🥲 |
This also leads to the "inline |
11772: Support constants in const eval r=HKalbasi a=HKalbasi This PR enables evaluating things like this: ```rust const X: usize = 2; const Y: usize = 3 + X; // = 5 ``` My target was nalgebra's `U5`, `U22`, ... which are defined as `type U5 = Const<{ SomeType5::SOME_ASSOC_CONST }>` but I didn't find out how to find the `ConstId` of the implementation of the trait, not the trait itself (possibly related to #4558 ? We can find associated type alias, so maybe this is doable already) So it doesn't help for nalgebra currently, but it is useful anyway. Co-authored-by: hkalbasi <hamidrezakalbasi@protonmail.com>
I realized that this didn't get updated on the current state of things. Unfortunately, working on this issue burned me out really badly last summer and I won't have any resources to make it happen. Based on rust-lang/chalk#716, @compiler-errors was interested in working on the chalk side, but I'm not sure what the status is on that today. |
I hope you recovered from being burned out on this and it didn't spoil your fun on other rust things! Thanks for working on rust-analyzer. |
feat: Go to implementation of trait methods try goto where the trait method implies, #4558
feat: Go to implementation of trait methods try goto where the trait method implies, #4558
Implemented in #12549, I would say. 🎉 |
In rust-analyzer using "go to definition" on the
to_string()
part of5.to_string()
takes you to:In IntelliJ it takes you to the more useful:
The text was updated successfully, but these errors were encountered: