-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Support built-in derives #1427
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
Comments
It would be nice if "go to definition" (or "implementation"; "definition" is what I'm used to from VS) on a method of a derived trait would work and point to the attribute.
Yes, see rust-lang/rust#41481 and rust-lang/rust#26925. |
Currently "go to definition" will go to the definition of the method in the trait. I don't know if we should go to the impl if possible, or if we should have a separate command that does that... In many cases it's not possible anyway 🤔 Edit: Ah right, there's a 'go to implementation' in the LSP. So that should probably go to the impl. We'd first have to get Chalk to tell us which impl applied though... |
I think the more future proof version (supporing custom derives) would be to generate actual source code when we do macro expansion. |
@matklad hey, where the implementation of |
A hacky and maybe easy way to get this (and also custom derives) would be to assert that types with |
Yes, as a midterm solution, we could basically provide synthetic impls for derives. Nowadays, I think we have all of the necessary infrastructure for that. It'd involve adding a variant to the This won't work for custom derives though, since they can do basically anything, not just implementing a trait, and even for the ones that do, I don't think we have a good way of knowing what the trait being implemented is. Still, I think this could be worth it for the built-in derives, since proper support for custom derives may still take quite some time. |
This is actually fixed 🙂 |
We should support the built-in derives, e.g. with
we should know that the type implements those traits and pass corresponding impls to Chalk when doing trait solving. The most noticeable case where this currently matters is
Clone
since that gets called directly all the time; the other ones are more likely to be used in bounds, so we're probably missing some trait implementations because of this.Here are some general notes about this (I haven't thought about / investigated this in detail yet):
ra_hir::ImplBlock
s for this, or we could collect the derives in some separate data structure and just generate fake impls for Chalk (i.e. inimpls_for_trait
). I'm not sure which would be the better/nicer approach.#[derive(Clone)] struct S<T>
would result inimpl<T: Clone> Clone for S<T>
), but I haven't checked this.The text was updated successfully, but these errors were encountered: